diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-02-12 13:31:50 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-02-12 13:31:50 -0500 |
| commit | b4e44c4e80fd4f477a46251fdaf485a742ffe6f7 (patch) | |
| tree | b1d21e106f3165140961f4998a0e4147c331e078 /std | |
| parent | ec0846a00fd3d0ae0b7b94961f855b8ab6c938db (diff) | |
| download | zig-b4e44c4e80fd4f477a46251fdaf485a742ffe6f7.tar.gz zig-b4e44c4e80fd4f477a46251fdaf485a742ffe6f7.zip | |
self hosted parser tests every combination of memory allocation failure
Diffstat (limited to 'std')
| -rw-r--r-- | std/zig/parser.zig | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/std/zig/parser.zig b/std/zig/parser.zig index 70ffa24c73..4dbca8501e 100644 --- a/std/zig/parser.zig +++ b/std/zig/parser.zig @@ -1050,13 +1050,13 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) ![]u8 { defer tree.deinit(); var buffer = try std.Buffer.initSize(allocator, 0); + errdefer buffer.deinit(); + var buffer_out_stream = io.BufferOutStream.init(&buffer); try parser.renderSource(&buffer_out_stream.stream, tree.root_node); return buffer.toOwnedSlice(); } -// TODO test for memory leaks -// TODO test for valid frees fn testCanonical(source: []const u8) !void { const needed_alloc_count = x: { // Try it once with unlimited memory, make sure it works @@ -1083,14 +1083,13 @@ fn testCanonical(source: []const u8) !void { return error.NondeterministicMemoryUsage; } else |err| switch (err) { error.OutOfMemory => { - // TODO make this pass - //if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { - // warn("\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n", - // fail_index, needed_alloc_count, - // failing_allocator.allocated_bytes, failing_allocator.freed_bytes, - // failing_allocator.index, failing_allocator.deallocations); - // return error.MemoryLeakDetected; - //} + if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { + warn("\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n", + fail_index, needed_alloc_count, + failing_allocator.allocated_bytes, failing_allocator.freed_bytes, + failing_allocator.index, failing_allocator.deallocations); + return error.MemoryLeakDetected; + } }, error.ParseError => @panic("test failed"), } |
