Skip to content

Commit

Permalink
compilation test for conditional threadlocal storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Philipp Hafer committed Apr 25, 2023
1 parent 3cfdfac commit c4b5cde
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/std/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,26 @@ test "expectEqualDeep composite type" {
}
}

// TODO: test blocks can observe their own index fn argument.
// Do not leaks implementation details from the test runner into libstd.
// `test_fns_i` is index into builtin.test_functions set by test runner.
const TestFn_iT = if (!builtin.is_test) u32 else void;
threadlocal var test_fns_i: TestFn_iT = if (!builtin.is_test) 0 else void;

/// Send expected panic message to server from test runner, spawns itself as a
/// child process with the test number, tells the server pid and process group
/// of child and waits for the child process. The child process executes exactly
/// one test block up to panic or returns with error code 1.
/// If another expected panic message has been received by the server for the
/// same test block, then the test is marked as error.InvalidPanicMsg and the
/// child of the test runner thread is terminated via pid and process group,
///
/// In case no server is desired, the to be run test block is provided as cli
/// argument.
pub fn expectPanic(msg: []const u8) !void {
_ = msg;
}

fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
const line_begin_index = if (std.mem.lastIndexOfScalar(u8, source[0..indicator_index], '\n')) |line_begin|
line_begin + 1
Expand Down
2 changes: 1 addition & 1 deletion lib/std/zig/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub const Message = struct {
/// - 0 means not async
/// * expected_panic_msg: [tests_len]u32,
/// - null-terminated string_bytes index
/// - 0 means does not expect pani
/// - 0 means does not expect panic
/// * string_bytes: [string_bytes_len]u8,
pub const TestMetadata = extern struct {
string_bytes_len: u32,
Expand Down
1 change: 1 addition & 0 deletions lib/test_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ fn mainTerminal() void {

var leaks: usize = 0;
for (test_fn_list, 0..) |test_fn, i| {
std.testing.test_fns_i = i;
std.testing.allocator_instance = .{};
defer {
if (std.testing.allocator_instance.deinit() == .leak) {
Expand Down

0 comments on commit c4b5cde

Please sign in to comment.