zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c614d8d0081782116e94f3c8bfbf4ea515e7a3f3 (tree)
parent e46ddeeb296aeb259d1bb9f96cb977f4868309e7
Author: Pat Tullmann <pat.github@tullmann.org>
Date:   Wed,  6 Aug 2025 21:50:56 -0700

standalone posix tests: add skeleton

Add build.zig, README and empty test files.

Diffstat:
Mtest/standalone/build.zig.zon | 3+++
Atest/standalone/posix/README.md | 8++++++++
Atest/standalone/posix/build.zig | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest/standalone/posix/cwd.zig | 1+
Atest/standalone/posix/getenv.zig | 1+
Atest/standalone/posix/relpaths.zig | 1+
Atest/standalone/posix/sigaction.zig | 1+
7 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon @@ -211,6 +211,9 @@ .tsan = .{ .path = "tsan", }, + .posix = .{ + .path = "posix", + }, }, .paths = .{ "build.zig", diff --git a/test/standalone/posix/README.md b/test/standalone/posix/README.md @@ -0,0 +1,8 @@ +## Zig standalone POSIX tests + +This directory is just for std.posix-related test cases that depend on +process-wide state like the current-working directory, signal handlers, +fork, the main thread, environment variables, etc. Most tests (e.g, +around file descriptors, etc) are with the unit tests in +`lib/std/posix/test.zig`. New tests should be with the unit tests, unless +there is a specific reason they cannot. diff --git a/test/standalone/posix/build.zig b/test/standalone/posix/build.zig @@ -0,0 +1,72 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +const Case = struct { + src_path: []const u8, +}; + +const cases = [_]Case{ + .{ + .src_path = "cwd.zig", + }, + .{ + .src_path = "getenv.zig", + }, + .{ + .src_path = "sigaction.zig", + }, + .{ + .src_path = "relpaths.zig", + }, +}; + +pub fn build(b: *std.Build) void { + const test_step = b.step("test", "Run POSIX standalone test cases"); + b.default_step = test_step; + + const optimize = b.standardOptimizeOption(.{}); + + const default_target = b.resolveTargetQuery(.{}); + + // Run each test case built against libc-less, glibc, and musl. + for (cases) |case| { + const run_def = run_exe(b, optimize, &case, default_target, false); + test_step.dependOn(&run_def.step); + + if (default_target.result.os.tag == .linux) { + const gnu_target = b.resolveTargetQuery(.{ .abi = .gnu }); + const musl_target = b.resolveTargetQuery(.{ .abi = .musl }); + + const run_gnu = run_exe(b, optimize, &case, gnu_target, true); + const run_musl = run_exe(b, optimize, &case, musl_target, true); + + test_step.dependOn(&run_gnu.step); + test_step.dependOn(&run_musl.step); + } else { + const run_libc = run_exe(b, optimize, &case, default_target, true); + test_step.dependOn(&run_libc.step); + } + } +} + +fn run_exe(b: *std.Build, optimize: std.builtin.OptimizeMode, case: *const Case, target: std.Build.ResolvedTarget, link_libc: bool) *std.Build.Step.Run { + const exe_name = b.fmt("test-posix-{s}{s}{s}", .{ + std.fs.path.stem(case.src_path), + if (link_libc) "-libc" else "", + if (link_libc and target.result.isGnuLibC()) "-gnu" else if (link_libc and target.result.isMuslLibC()) "-musl" else "", + }); + + const exe = b.addExecutable(.{ + .name = exe_name, + .root_module = b.createModule(.{ + .root_source_file = b.path(case.src_path), + .link_libc = link_libc, + .optimize = optimize, + .target = target, + }), + }); + + const run_cmd = b.addRunArtifact(exe); + + return run_cmd; +} diff --git a/test/standalone/posix/cwd.zig b/test/standalone/posix/cwd.zig @@ -0,0 +1 @@ +pub fn main() !void {} diff --git a/test/standalone/posix/getenv.zig b/test/standalone/posix/getenv.zig @@ -0,0 +1 @@ +pub fn main() !void {} diff --git a/test/standalone/posix/relpaths.zig b/test/standalone/posix/relpaths.zig @@ -0,0 +1 @@ +pub fn main() !void {} diff --git a/test/standalone/posix/sigaction.zig b/test/standalone/posix/sigaction.zig @@ -0,0 +1 @@ +pub fn main() !void {}