Skip to content

Commit c4b5cde

Browse files
author
Jan Philipp Hafer
committed
compilation test for conditional threadlocal storage
1 parent 3cfdfac commit c4b5cde

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/std/testing.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,26 @@ test "expectEqualDeep composite type" {
916916
}
917917
}
918918

919+
// TODO: test blocks can observe their own index fn argument.
920+
// Do not leaks implementation details from the test runner into libstd.
921+
// `test_fns_i` is index into builtin.test_functions set by test runner.
922+
const TestFn_iT = if (!builtin.is_test) u32 else void;
923+
threadlocal var test_fns_i: TestFn_iT = if (!builtin.is_test) 0 else void;
924+
925+
/// Send expected panic message to server from test runner, spawns itself as a
926+
/// child process with the test number, tells the server pid and process group
927+
/// of child and waits for the child process. The child process executes exactly
928+
/// one test block up to panic or returns with error code 1.
929+
/// If another expected panic message has been received by the server for the
930+
/// same test block, then the test is marked as error.InvalidPanicMsg and the
931+
/// child of the test runner thread is terminated via pid and process group,
932+
///
933+
/// In case no server is desired, the to be run test block is provided as cli
934+
/// argument.
935+
pub fn expectPanic(msg: []const u8) !void {
936+
_ = msg;
937+
}
938+
919939
fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
920940
const line_begin_index = if (std.mem.lastIndexOfScalar(u8, source[0..indicator_index], '\n')) |line_begin|
921941
line_begin + 1

lib/std/zig/Server.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub const Message = struct {
4242
/// - 0 means not async
4343
/// * expected_panic_msg: [tests_len]u32,
4444
/// - null-terminated string_bytes index
45-
/// - 0 means does not expect pani
45+
/// - 0 means does not expect panic
4646
/// * string_bytes: [string_bytes_len]u8,
4747
pub const TestMetadata = extern struct {
4848
string_bytes_len: u32,

lib/test_runner.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fn mainTerminal() void {
146146

147147
var leaks: usize = 0;
148148
for (test_fn_list, 0..) |test_fn, i| {
149+
std.testing.test_fns_i = i;
149150
std.testing.allocator_instance = .{};
150151
defer {
151152
if (std.testing.allocator_instance.deinit() == .leak) {

0 commit comments

Comments
 (0)