exercises(all-your-base): test: add test for global array#322
Merged
Conversation
A recent commit [1] added missing frees in the test cases that returned
a single 0. This causes a previously-passing solution that returned a
slice referencing a global array to panic:
$ zig test test_all_your_base.zig
Test [9/17] test.empty list... thread 27369 panic: Invalid free
/usr/lib/zig/std/heap/general_purpose_allocator.zig:609:21: 0x22cb5e in freeLarge (test)
@Panic("Invalid free");
^
/usr/lib/zig/std/heap/general_purpose_allocator.zig:824:31: 0x22c0db in free (test)
self.freeLarge(old_mem, log2_old_align, ret_addr);
^
/usr/lib/zig/std/mem/Allocator.zig:98:28: 0x22800f in free__anon_3776 (test)
return self.vtable.free(self.ptr, buf, log2_buf_align, ret_addr);
^
/home/foo/exercism-zig/exercises/practice/all-your-base/test_all_your_base.zig:94:33: 0x22881a in test.empty list (test)
defer testing.allocator.free(actual);
^
Add a targeted test case to help a user that writes such a solution.
Their solution will still produce a panic, but it will point to a more
obvious test case. And it will now produce a test failure first:
$ zig test test_all_your_base.zig
Test [9/18] test.empty list - second call returns different memory... slices differ. first difference occurs at index 0 (0x0)
============ expected this output: ============= len: 1 (0x1)
[0]: 0
============= instead found this: ============== len: 1 (0x1)
[0]: 1
================================================
thread 27306 panic: Invalid free
/usr/lib/zig/std/heap/general_purpose_allocator.zig:609:21: 0x22ceee in freeLarge (test)
@Panic("Invalid free");
^
/usr/lib/zig/std/heap/general_purpose_allocator.zig:824:31: 0x22c46b in free (test)
self.freeLarge(old_mem, log2_old_align, ret_addr);
^
/usr/lib/zig/std/mem/Allocator.zig:98:28: 0x2280df in free__anon_3777 (test)
return self.vtable.free(self.ptr, buf, log2_buf_align, ret_addr);
^
/home/foo/exercism-zig/exercises/practice/all-your-base/test_all_your_base.zig:101:33: 0x228a3e in test.empty list - second call returns different memory (test)
defer testing.allocator.free(again);
^
The ordering of the test cases looks strange: the test that calls
`convert` twice with empty `digits` is before the test that does so
once. But otherwise the user will see the panic in the non-targeted test
case.
[1] b65162f, 2023-09-12, "exercises(all-your-base): add missing frees"
ErikSchierboom
approved these changes
Sep 15, 2023
FedericoStra
approved these changes
Sep 16, 2023
This test's name starts with "empty list", and appears before tests named (also somewhat badly) "empty list" and "single zero".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up from #317 (comment).
Commit b65162f added missing frees in the test cases that returned a single 0. This causes a previously-passing solution that incorrectly returned a reference to a global array to panic:
Add a targeted test case to help a user that writes such a solution. Their solution will still produce a panic, but it will point to a more obvious test case. And it will now produce a test failure first:
The ordering of the test cases looks strange: the test that calls
converttwice with emptydigitsis before the test that does so once. But otherwise the user will see the panic in the non-targeted test case.