authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-12 13:31:50-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-12 13:31:50-05:00
logb4e44c4e80fd4f477a46251fdaf485a742ffe6f7
treeb1d21e106f3165140961f4998a0e4147c331e078
parentec0846a00fd3d0ae0b7b94961f855b8ab6c938db

self hosted parser tests every combination of memory allocation failure


1 files changed, 9 insertions(+), 10 deletions(-)

std/zig/parser.zig+9-10
......@@ -1050,13 +1050,13 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) ![]u8 {
10501050 defer tree.deinit();
10511051
10521052 var buffer = try std.Buffer.initSize(allocator, 0);
1053 errdefer buffer.deinit();
1054
10531055 var buffer_out_stream = io.BufferOutStream.init(&buffer);
10541056 try parser.renderSource(&buffer_out_stream.stream, tree.root_node);
10551057 return buffer.toOwnedSlice();
10561058}
10571059
1058// TODO test for memory leaks
1059// TODO test for valid frees
10601060fn testCanonical(source: []const u8) !void {
10611061 const needed_alloc_count = x: {
10621062 // Try it once with unlimited memory, make sure it works
......@@ -1083,14 +1083,13 @@ fn testCanonical(source: []const u8) !void {
10831083 return error.NondeterministicMemoryUsage;
10841084 } else |err| switch (err) {
10851085 error.OutOfMemory => {
1086 // TODO make this pass
1087 //if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
1088 // warn("\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",
1089 // fail_index, needed_alloc_count,
1090 // failing_allocator.allocated_bytes, failing_allocator.freed_bytes,
1091 // failing_allocator.index, failing_allocator.deallocations);
1092 // return error.MemoryLeakDetected;
1093 //}
1086 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
1087 warn("\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",
1088 fail_index, needed_alloc_count,
1089 failing_allocator.allocated_bytes, failing_allocator.freed_bytes,
1090 failing_allocator.index, failing_allocator.deallocations);
1091 return error.MemoryLeakDetected;
1092 }
10941093 },
10951094 error.ParseError => @panic("test failed"),
10961095 }