test_runner: enable testing panics in mainTerminal
The user can use std.testing.spawnExpectPanic() in a test to spawn a child process, which must panic or the test fails. Internally,
-
- is_panic_parentproc is set from the cli arguments for simple reproduction of both test spawn and panic behavior,
-
- panic_msg is set as threadlocal, if comptime-detectable capabilities exist, to enable multithreaded processing and user-customized messages,
-
- error.SpawnZigTest is returned to the test_runner.zig
-
- the test_runner spawns a child_process on correct usage
-
- the child_process expected to panic executes only one test block
This means, that only one @panic is possible within a test block and that no follow-up code after the @panic in the test block can be run.
This commit does not add the panic test capability to the server yet, since there are open design questions how many processes should be spawned at the same time and how to manage time quotas to prevent unnecessary slowdowns.
Supersedes #14351. Work on #1356.
Question: Is the approach lit? Should I include it like this in Server with test code or are there any concerns?
// testfile.zig
const std = @import("std");
const testing = std.testing;
test "panic" {
try testing.spawnExpectPanic("test1");
try testing.expectEqual(@as(u8, 1), @as(u32, 1));
@panic("test1");
}
test "wrong_panic" {
try testing.spawnExpectPanic("test1");
@panic("test2");
}
// Test [2/3] test.wrong_panic... Signal: 6
// Test [2/3] test.wrong_panic... FAIL expected_panic_msg: 'test1', got: 'test2
test "no panic but one was expected" {
try testing.spawnExpectPanic("test3");
}
// Test [2/3] test.no panic but one was expected... error.SpawnZigTest
// Test [2/3] test.no panic but one was expected... spawning '/home/misterspoon/dev/git/zi/zig/enable_testing_pan
ics/zig-cache/o/4b2b4b4abad5f54a10c57ea01651fa0d/test --test_panic_index 2'
// Test [2/3] test.no panic but one was expected... FAIL term exited, status: 0)
// stdout: ()
// stderr: ()
// unhandled case:
// test "testme" {
// @panic("123123");
// }
./deb/bin/zig test testfile.zig
Test [1/3] test.panic... SPAWN '/home/jan/dev/zdev/zig/enable_testing_panics/zig-cache/o/b0b2decbe7ec71ffe70cf209
7d241485/test --test_panic_index 0'
Test [1/3] test.panic... Signal: 6
Test [2/3] test.wrong_panic... SPAWN '/home/jan/dev/zdev/zig/enable_testing_panics/zig-cache/o/b0b2decbe7ec71ffe7
0cf2097d241485/test --test_panic_index 1'
Test [2/3] test.wrong_panic... Signal: 6
Test [2/3] test.wrong_panic... FAIL expected_panic_msg: 'test1', got: 'test2', Signal: 6
Test [3/3] test.no panic but one was expected... SPAWN '/home/jan/dev/zdev/zig/enable_testing_panics/zig-cache/o/
b0b2decbe7ec71ffe70cf2097d241485/test --test_panic_index 2'
Test [3/3] test.no panic but one was expected... FAIL term exited, status: 0)
stdout: ()
stderr: ()
1 passed; 0 skipped; 2 failed.
error: the following test command failed with exit code 1:
/home/jan/dev/zdev/zig/enable_testing_panics/zig-cache/o/b0b2decbe7ec71ffe70cf2097d241485/test
later after design issues resolved or approach clarified:
- [x] move into function
- [ ] server integration
- [ ] clarify how the server logic should work
- must store remaining time left for process,
- must store gid+pid to kill it, if taking too long
- must regularly check, if already finished
- double check where list of unfinished tests and status is stored
This ~~is~~ ~~was~~ is hitting x86_64 backend missing feature[s]:
test transitive failure
+- test-behavior transitive failure
| +- run test behavior-x86_64-windows-gnu-Debug-selfhosted-no-lld transitive failure
| +- zig test Debug x86_64-windows-gnu 1 errors
+- test-universal-libc transitive failure
+- run test universal-libc-x86_64-windows-gnu-Debug-selfhosted-no-lld transitive failure
+- zig test Debug x86_64-windows-gnu 1 errors
D:\a\zig\zig\lib\std\unicode.zig:200:5: error: TODO implement airReduce for x86_64
D:\a\zig\zig\lib\std\unicode.zig:200:5: error: TODO implement airReduce for x86_64
~~I'll try to rebase to fix it.~~ rebased. The issue persists.
Closing abandoned pull request (last update 3 months ago, not passing CI checks)