authorgravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-01-30 00:14:17-06:00
committergravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-01-30 00:27:44-06:00
log184128fd9e5bfcf9b9a1c1021cf1d8db03147c28
tree44f6f584c0887273eb87ee42065ee5e03986039b
parent5c8e85f3884c581b17c8df1f19852189fe7c9412

Fix testing.allocator wiring


2 files changed, 6 insertions(+), 7 deletions(-)

lib/std/special/test_runner.zig+4-6
...@@ -14,12 +14,6 @@ pub fn main() anyerror!void {...@@ -14,12 +14,6 @@ pub fn main() anyerror!void {
1414
15 for (test_fn_list) |test_fn, i| {15 for (test_fn_list) |test_fn, i| {
16 std.testing.base_allocator_instance.reset();16 std.testing.base_allocator_instance.reset();
17 defer {
18 std.testing.allocator_instance.validate() catch |err| switch (err) {
19 error.Leak => std.debug.panic("", .{}),
20 else => std.debug.panic("error.{}", .{@errorName(err)}),
21 };
22 }
2317
24 var test_node = root_node.start(test_fn.name, null);18 var test_node = root_node.start(test_fn.name, null);
25 test_node.activate();19 test_node.activate();
...@@ -30,6 +24,10 @@ pub fn main() anyerror!void {...@@ -30,6 +24,10 @@ pub fn main() anyerror!void {
30 if (test_fn.func()) |_| {24 if (test_fn.func()) |_| {
31 ok_count += 1;25 ok_count += 1;
32 test_node.end();26 test_node.end();
27 std.testing.allocator_instance.validate() catch |err| switch (err) {
28 error.Leak => std.debug.panic("", .{}),
29 else => std.debug.panic("error.{}", .{@errorName(err)}),
30 };
33 if (progress.terminal == null) std.debug.warn("OK\n", .{});31 if (progress.terminal == null) std.debug.warn("OK\n", .{});
34 } else |err| switch (err) {32 } else |err| switch (err) {
35 error.SkipZigTest => {33 error.SkipZigTest => {
lib/std/testing/leak_count_allocator.zig+2-1
...@@ -23,10 +23,11 @@ pub const LeakCountAllocator = struct {...@@ -23,10 +23,11 @@ pub const LeakCountAllocator = struct {
2323
24 fn realloc(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 {24 fn realloc(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 {
25 const self = @fieldParentPtr(LeakCountAllocator, "allocator", allocator);25 const self = @fieldParentPtr(LeakCountAllocator, "allocator", allocator);
26 var data = try self.internal_allocator.reallocFn(self.internal_allocator, old_mem, old_align, new_size, new_align);
26 if (old_mem.len == 0) {27 if (old_mem.len == 0) {
27 self.count += 1;28 self.count += 1;
28 }29 }
29 return self.internal_allocator.reallocFn(self.internal_allocator, old_mem, old_align, new_size, new_align);30 return data;
30 }31 }
3132
32 fn shrink(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {33 fn shrink(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {