Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM alpine:3.24.1@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b AS builder


ARG VERSION=0.16.0
ARG VERSION=0.17.0
ARG RELEASE=zig-x86_64-linux-${VERSION}

# We can't reliably pin the package versions on Alpine, so we ignore the linter warning.
Expand Down
11 changes: 7 additions & 4 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ for test_dir in "${tmp_dir}"/*; do
bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}"

for file in "$results_file_path" "$expected_results_file_path"; do
# We remove nondeterministic memory locations of instructions and
# compiler-generated anonymous function suffixes (e.g.
# `expectError__anon_17425`), both of which vary between builds.
# We remove nondeterministic memory locations of instructions and of
# leaked allocations (printed without a `0x` prefix, e.g.
# `leaked [addr: 7820fd4cc140,`) and compiler-generated function
# instantiation suffixes (e.g. `expectError__anon_17425` or
# `expectError__func_957`), all of which vary between builds.
# See: https://github.com/exercism/zig-test-runner/issues/26
sed -E \
-e 's/0x[a-f0-9]+/<MEMHASH>/g' \
-e 's/__anon_[0-9]+/__anon_<ANON>/g' \
-e 's/addr: [a-f0-9]+/addr: <MEMHASH>/g' \
-e 's/__(anon|func)_[0-9]+/__\1_<ANON>/g' \
"${file}" > "${file}.tmp"
done

Expand Down
18 changes: 9 additions & 9 deletions tests/example-all-fail/expected_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,55 @@
"name": "year not divisible by 4 in common year",
"test_code": "try testing.expect(!leap.leap(2015));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:7:5: <MEMHASH> in test.year not divisible by 4 in common year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(2015));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:7:5: <MEMHASH> in test.year not divisible by 4 in common year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(2015));\n ^"
},
{
"name": "year divisible by 2, not divisible by 4 in common year",
"test_code": "try testing.expect(!leap.leap(1970));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:11:5: <MEMHASH> in test.year divisible by 2, not divisible by 4 in common year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(1970));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:11:5: <MEMHASH> in test.year divisible by 2, not divisible by 4 in common year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(1970));\n ^"
},
{
"name": "year divisible by 4, not divisible by 100 in leap year",
"test_code": "try testing.expect(leap.leap(1996));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:15:5: <MEMHASH> in test.year divisible by 4, not divisible by 100 in leap year (test_example_all_fail.zig)\n try testing.expect(leap.leap(1996));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:15:5: <MEMHASH> in test.year divisible by 4, not divisible by 100 in leap year (test_example_all_fail.zig)\n try testing.expect(leap.leap(1996));\n ^"
},
{
"name": "year divisible by 4 and 5 is still a leap year",
"test_code": "try testing.expect(leap.leap(1960));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:19:5: <MEMHASH> in test.year divisible by 4 and 5 is still a leap year (test_example_all_fail.zig)\n try testing.expect(leap.leap(1960));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:19:5: <MEMHASH> in test.year divisible by 4 and 5 is still a leap year (test_example_all_fail.zig)\n try testing.expect(leap.leap(1960));\n ^"
},
{
"name": "year divisible by 100, not divisible by 400 in common year",
"test_code": "try testing.expect(!leap.leap(2100));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:23:5: <MEMHASH> in test.year divisible by 100, not divisible by 400 in common year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(2100));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:23:5: <MEMHASH> in test.year divisible by 100, not divisible by 400 in common year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(2100));\n ^"
},
{
"name": "year divisible by 100 but not by 3 is still not a leap year",
"test_code": "try testing.expect(!leap.leap(1900));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:27:5: <MEMHASH> in test.year divisible by 100 but not by 3 is still not a leap year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(1900));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:27:5: <MEMHASH> in test.year divisible by 100 but not by 3 is still not a leap year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(1900));\n ^"
},
{
"name": "year divisible by 400 is leap year",
"test_code": "try testing.expect(leap.leap(2000));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:31:5: <MEMHASH> in test.year divisible by 400 is leap year (test_example_all_fail.zig)\n try testing.expect(leap.leap(2000));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:31:5: <MEMHASH> in test.year divisible by 400 is leap year (test_example_all_fail.zig)\n try testing.expect(leap.leap(2000));\n ^"
},
{
"name": "year divisible by 400 but not by 125 is still a leap year",
"test_code": "try testing.expect(leap.leap(2400));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:35:5: <MEMHASH> in test.year divisible by 400 but not by 125 is still a leap year (test_example_all_fail.zig)\n try testing.expect(leap.leap(2400));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:35:5: <MEMHASH> in test.year divisible by 400 but not by 125 is still a leap year (test_example_all_fail.zig)\n try testing.expect(leap.leap(2400));\n ^"
},
{
"name": "year divisible by 200, not divisible by 400 in common year",
"test_code": "try testing.expect(!leap.leap(1800));",
"status": "fail",
"message": "/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:39:5: <MEMHASH> in test.year divisible by 200, not divisible by 400 in common year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(1800));\n ^"
"message": "/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_all_fail.zig:39:5: <MEMHASH> in test.year divisible by 200, not divisible by 400 in common year (test_example_all_fail.zig)\n try testing.expect(!leap.leap(1800));\n ^"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const mem = std.mem;
/// Returns the case-insensitive counts of English letters in `s`.
/// Caller guarantees that `s` contains at most 15 of a single letter.
fn count(s: []const u8) [26]u4 {
var result = [_]u4{0} ** 26;
var result: [26]u4 = @splat(0);
for (s) |c| {
switch (c) {
'A'...'Z' => result[c - 'A'] += 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/example-debug-error-output/expected_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"name": "failing test alongside error-like debug output",
"test_code": "try testing.expect(mod.greet().len == 99);",
"status": "fail",
"message": "FAIL (TestUnexpectedResult)\n/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_debug_error_output.zig:15:5: <MEMHASH> in test.failing test alongside error-like debug output (test_example_debug_error_output.zig)\n try testing.expect(mod.greet().len == 99);\n ^",
"message": "FAIL (TestUnexpectedResult)\n/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_debug_error_output.zig:15:5: <MEMHASH> in test.failing test alongside error-like debug output (test_example_debug_error_output.zig)\n try testing.expect(mod.greet().len == 99);\n ^",
"output": "error: greet was called with no arguments"
},
{
"name": "failing line carries an error-like comment",
"test_code": "try testing.expect(mod.greet().len == 99); // error: expected a longer greeting",
"status": "fail",
"message": "FAIL (TestUnexpectedResult)\n/opt/zig/lib/std/testing.zig:615:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_debug_error_output.zig:19:5: <MEMHASH> in test.failing line carries an error-like comment (test_example_debug_error_output.zig)\n try testing.expect(mod.greet().len == 99); // error: expected a longer greeting\n ^",
"message": "FAIL (TestUnexpectedResult)\n/opt/zig/lib/std/testing.zig:584:14: <MEMHASH> in expect (std.zig)\n if (!ok) return error.TestUnexpectedResult;\n ^\ntest_example_debug_error_output.zig:19:5: <MEMHASH> in test.failing line carries an error-like comment (test_example_debug_error_output.zig)\n try testing.expect(mod.greet().len == 99); // error: expected a longer greeting\n ^",
"output": "error: greet was called with no arguments"
}
]
Expand Down
2 changes: 1 addition & 1 deletion tests/example-error-exercise/expected_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"name": "zero is an error",
"test_code": "const expected = ComputationError.IllegalArgument;\nconst actual = collatz.steps(0);\ntry testing.expectError(expected, actual);",
"status": "fail",
"message": "FAIL (TestExpectedError)\n/opt/zig/lib/std/testing.zig:65:9: <MEMHASH> in expectError__anon_<ANON> (std.zig)\n return error.TestExpectedError;\n ^\ntest_example_error_exercise.zig:34:5: <MEMHASH> in test.zero is an error (test_example_error_exercise.zig)\n try testing.expectError(expected, actual);\n ^"
"message": "FAIL (TestExpectedError)\n/opt/zig/lib/std/testing.zig:634:9: <MEMHASH> in expectError__func_<ANON> (std.zig)\n return error.TestExpectedError;\n ^\ntest_example_error_exercise.zig:34:5: <MEMHASH> in test.zero is an error (test_example_error_exercise.zig)\n try testing.expectError(expected, actual);\n ^"
}
]
}
2 changes: 1 addition & 1 deletion tests/example-memory-leak/expected_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "makePair cleans up on allocation failure",
"test_code": "try std.testing.checkAllAllocationFailures(\n std.testing.allocator,\n pairTest,\n .{},\n);",
"status": "fail",
"message": "FAIL (MemoryLeakDetected)\n/opt/zig/lib/std/mem/Allocator.zig:300:82: <MEMHASH> in allocBytesWithAlignment__anon_<ANON> (std.zig)\n const byte_ptr = self.rawAlloc(byte_count, alignment, return_address) orelse return error.OutOfMemory;\n ^\n/opt/zig/lib/std/mem/Allocator.zig:286:5: <MEMHASH> in allocWithSizeAndAlignment__anon_<ANON> (std.zig)\n return self.allocBytesWithAlignment(alignment, byte_count, return_address);\n ^\n/opt/zig/lib/std/mem/Allocator.zig:274:55: <MEMHASH> in allocAdvancedWithRetAddr (std.zig)\n const ptr: [*]align(a.toByteUnits()) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address));\n ^\n/opt/zig/lib/std/mem/Allocator.zig:198:5: <MEMHASH> in alloc__anon_<ANON> (std.zig)\n return self.allocAdvancedWithRetAddr(T, null, n, @returnAddress());\n ^\nexample_memory_leak.zig:9:20: <MEMHASH> in makePair (test_example_memory_leak.zig)\n const second = try allocator.alloc(u8, 16);\n ^\ntest_example_memory_leak.zig:7:15: <MEMHASH> in pairTest (test_example_memory_leak.zig)\n const p = try mod.makePair(allocator);\n ^\n/opt/zig/lib/std/testing.zig:1156:21: <MEMHASH> in checkAllAllocationFailures__anon_<ANON> (std.zig)\n return error.MemoryLeakDetected;\n ^\ntest_example_memory_leak.zig:13:5: <MEMHASH> in test.makePair cleans up on allocation failure (test_example_memory_leak.zig)\n try std.testing.checkAllAllocationFailures(\n ^\n[DebugAllocator] (err): memory address <MEMHASH> leaked: \nexample_memory_leak.zig:8:38: <MEMHASH> in makePair (test_example_memory_leak.zig)\n const first = try allocator.alloc(u8, 16);\n ^\ntest_example_memory_leak.zig:7:31: <MEMHASH> in pairTest (test_example_memory_leak.zig)\n const p = try mod.makePair(allocator);\n ^\n/opt/zig/lib/std/testing.zig:1133:69: <MEMHASH> in checkAllAllocationFailures__anon_<ANON> (std.zig)\n if (@call(.auto, test_fn, .{failing_allocator_inst.allocator()} ++ extra_args)) |_| {\n ^\ntest_example_memory_leak.zig:13:47: <MEMHASH> in test.makePair cleans up on allocation failure (test_example_memory_leak.zig)\n try std.testing.checkAllAllocationFailures(\n ^\n/opt/zig/lib/compiler/test_runner.zig:291:25: <MEMHASH> in mainTerminal (test_runner.zig)\n if (test_fn.func()) |_| {\n ^\n/opt/zig/lib/compiler/test_runner.zig:73:28: <MEMHASH> in main (test_runner.zig)\n return mainTerminal(init);\n ^\n/opt/zig/lib/std/start.zig:699:88: <MEMHASH> in callMain (std.zig)\n if (fn_info.params[0].type.? == std.process.Init.Minimal) return wrapMain(root.main(.{\n ^\n/opt/zig/lib/std/start.zig:190:5: <MEMHASH> in _start (std.zig)\n asm volatile (switch (native_arch) {\n ^",
"message": "FAIL (MemoryLeakDetected)\n/opt/zig/lib/std/mem/Allocator.zig:325:82: <MEMHASH> in allocBytesAligned__func_<ANON> (std.zig)\n const byte_ptr = self.rawAlloc(byte_count, alignment, return_address) orelse return error.OutOfMemory;\n ^\n/opt/zig/lib/std/mem/Allocator.zig:311:5: <MEMHASH> in allocWithSizeAndAlignment__func_<ANON> (std.zig)\n return self.allocBytesAligned(alignment, byte_count, return_address);\n ^\n/opt/zig/lib/std/mem/Allocator.zig:299:55: <MEMHASH> in allocAdvancedWithRetAddr (std.zig)\n const ptr: [*]align(a.toByteUnits()) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address));\n ^\n/opt/zig/lib/std/mem/Allocator.zig:223:5: <MEMHASH> in alloc__func_<ANON> (std.zig)\n return self.allocAdvancedWithRetAddr(T, null, n, @returnAddress());\n ^\nexample_memory_leak.zig:9:20: <MEMHASH> in makePair (test_example_memory_leak.zig)\n const second = try allocator.alloc(u8, 16);\n ^\ntest_example_memory_leak.zig:7:15: <MEMHASH> in pairTest (test_example_memory_leak.zig)\n const p = try mod.makePair(allocator);\n ^\n/opt/zig/lib/std/testing.zig:1186:21: <MEMHASH> in checkAllAllocationFailures__func_<ANON> (std.zig)\n return error.MemoryLeakDetected;\n ^\ntest_example_memory_leak.zig:13:5: <MEMHASH> in test.makePair cleans up on allocation failure (test_example_memory_leak.zig)\n try std.testing.checkAllAllocationFailures(\n ^\n[SafeAllocator] (err): leaked [addr: <MEMHASH>, len: 16 (<MEMHASH>) align: 1] allocated at: \nexample_memory_leak.zig:8:38: <MEMHASH> in makePair (test_example_memory_leak.zig)\n const first = try allocator.alloc(u8, 16);\n ^\ntest_example_memory_leak.zig:7:31: <MEMHASH> in pairTest (test_example_memory_leak.zig)\n const p = try mod.makePair(allocator);\n ^\n/opt/zig/lib/std/testing.zig:1163:69: <MEMHASH> in checkAllAllocationFailures__func_<ANON> (std.zig)\n if (@call(.auto, test_fn, .{failing_allocator_inst.allocator()} ++ extra_args)) |_| {\n ^\ntest_example_memory_leak.zig:13:47: <MEMHASH> in test.makePair cleans up on allocation failure (test_example_memory_leak.zig)\n try std.testing.checkAllAllocationFailures(\n ^\n/opt/zig/lib/compiler/test_runner.zig:295:25: <MEMHASH> in mainTerminal (test_runner.zig)\n if (test_fn.func()) |_| {\n ^\n/opt/zig/lib/compiler/test_runner.zig:74:28: <MEMHASH> in main (test_runner.zig)\n return mainTerminal(init);\n ^\n/opt/zig/lib/std/start.zig:789:88: <MEMHASH> in callMain (std.zig)\n if (fn_info.param_types[0].? == std.process.Init.Minimal) return wrapMain(root.main(.{\n ^\n(additional stack frames may have been skipped...)",
"output": "fail_index: 1/2\nallocated bytes: 16\nfreed bytes: 0\nallocations: 1\ndeallocations: 0\nallocation that was made to fail: \nexample_memory_leak.zig:9:39: <MEMHASH> in makePair (test_example_memory_leak.zig)\n const second = try allocator.alloc(u8, 16);\n ^\ntest_example_memory_leak.zig:7:31: <MEMHASH> in pairTest (test_example_memory_leak.zig)\n const p = try mod.makePair(allocator);\n ^\n/opt/zig/lib/std/testing.zig: [output truncated]"
},
{
Expand Down
Loading