Fix testing.allocator wiring

This commit is contained in:
Benjamin Feng 2020-01-30 00:14:17 -06:00
parent 5c8e85f388
commit 184128fd9e
2 changed files with 6 additions and 7 deletions

View File

@ -14,12 +14,6 @@ pub fn main() anyerror!void {
for (test_fn_list) |test_fn, i| {
std.testing.base_allocator_instance.reset();
defer {
std.testing.allocator_instance.validate() catch |err| switch (err) {
error.Leak => std.debug.panic("", .{}),
else => std.debug.panic("error.{}", .{@errorName(err)}),
};
}
var test_node = root_node.start(test_fn.name, null);
test_node.activate();
@ -30,6 +24,10 @@ pub fn main() anyerror!void {
if (test_fn.func()) |_| {
ok_count += 1;
test_node.end();
std.testing.allocator_instance.validate() catch |err| switch (err) {
error.Leak => std.debug.panic("", .{}),
else => std.debug.panic("error.{}", .{@errorName(err)}),
};
if (progress.terminal == null) std.debug.warn("OK\n", .{});
} else |err| switch (err) {
error.SkipZigTest => {

View File

@ -23,10 +23,11 @@ pub const LeakCountAllocator = struct {
fn realloc(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 {
const self = @fieldParentPtr(LeakCountAllocator, "allocator", allocator);
var data = try self.internal_allocator.reallocFn(self.internal_allocator, old_mem, old_align, new_size, new_align);
if (old_mem.len == 0) {
self.count += 1;
}
return self.internal_allocator.reallocFn(self.internal_allocator, old_mem, old_align, new_size, new_align);
return data;
}
fn shrink(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {