| ... | @@ -1050,13 +1050,13 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) ![]u8 { | ... | @@ -1050,13 +1050,13 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) ![]u8 { |
| 1050 | defer tree.deinit(); | 1050 | defer tree.deinit(); |
| 1051 | | 1051 | |
| 1052 | var buffer = try std.Buffer.initSize(allocator, 0); | 1052 | var buffer = try std.Buffer.initSize(allocator, 0); |
| | 1053 | errdefer buffer.deinit(); |
| | 1054 | |
| 1053 | var buffer_out_stream = io.BufferOutStream.init(&buffer); | 1055 | var buffer_out_stream = io.BufferOutStream.init(&buffer); |
| 1054 | try parser.renderSource(&buffer_out_stream.stream, tree.root_node); | 1056 | try parser.renderSource(&buffer_out_stream.stream, tree.root_node); |
| 1055 | return buffer.toOwnedSlice(); | 1057 | return buffer.toOwnedSlice(); |
| 1056 | } | 1058 | } |
| 1057 | | 1059 | |
| 1058 | // TODO test for memory leaks | | |
| 1059 | // TODO test for valid frees | | |
| 1060 | fn testCanonical(source: []const u8) !void { | 1060 | fn testCanonical(source: []const u8) !void { |
| 1061 | const needed_alloc_count = x: { | 1061 | const needed_alloc_count = x: { |
| 1062 | // Try it once with unlimited memory, make sure it works | 1062 | // Try it once with unlimited memory, make sure it works |
| ... | @@ -1083,14 +1083,13 @@ fn testCanonical(source: []const u8) !void { | ... | @@ -1083,14 +1083,13 @@ fn testCanonical(source: []const u8) !void { |
| 1083 | return error.NondeterministicMemoryUsage; | 1083 | return error.NondeterministicMemoryUsage; |
| 1084 | } else |err| switch (err) { | 1084 | } else |err| switch (err) { |
| 1085 | error.OutOfMemory => { | 1085 | error.OutOfMemory => { |
| 1086 | // TODO make this pass | 1086 | if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { |
| 1087 | //if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { | 1087 | warn("\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n", |
| 1088 | // warn("\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n", | 1088 | fail_index, needed_alloc_count, |
| 1089 | // fail_index, needed_alloc_count, | 1089 | failing_allocator.allocated_bytes, failing_allocator.freed_bytes, |
| 1090 | // failing_allocator.allocated_bytes, failing_allocator.freed_bytes, | 1090 | failing_allocator.index, failing_allocator.deallocations); |
| 1091 | // failing_allocator.index, failing_allocator.deallocations); | 1091 | return error.MemoryLeakDetected; |
| 1092 | // return error.MemoryLeakDetected; | 1092 | } |
| 1093 | //} | | |
| 1094 | }, | 1093 | }, |
| 1095 | error.ParseError => @panic("test failed"), | 1094 | error.ParseError => @panic("test failed"), |
| 1096 | } | 1095 | } |