From 4058f3b8173f076dd2cdc429a724913e6cd463ba Mon Sep 17 00:00:00 2001 From: -k Date: Tue, 18 Jun 2024 10:38:31 -0700 Subject: [PATCH] test: move `main` --- build.zig | 15 +++++++++++---- tests/cli.zig | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tests/cli.zig diff --git a/build.zig b/build.zig index 4ab8c20..479240e 100644 --- a/build.zig +++ b/build.zig @@ -41,8 +41,15 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Run all tests"); test_step.dependOn(&run_unit_tests.step); - const test_ok = b.addRunArtifact(exe); - test_ok.addArgs(&.{"-t=short"}); - test_ok.expectExitCode(0); - test_step.dependOn(&test_ok.step); + const test_options = b.addOptions(); + test_options.addOptionPath("exe_path", exe.getEmittedBin()); + + const integration_tests = b.addTest(.{ + .root_source_file = .{ .path = "./tests/cli.zig" }, + }); + + integration_tests.root_module.addOptions("build_options", test_options); + + const run_integration_tests = b.addRunArtifact(integration_tests); + test_step.dependOn(&run_integration_tests.step); } diff --git a/tests/cli.zig b/tests/cli.zig new file mode 100644 index 0000000..e7f6b14 --- /dev/null +++ b/tests/cli.zig @@ -0,0 +1,20 @@ +const std = @import("std"); +const build_options = @import("build_options"); + +test "main" { + const exe_path = build_options.exe_path; + const argv = [_][]const u8{ exe_path, "--time=short" }; + const proc = try std.ChildProcess.run(.{ + .allocator = std.testing.allocator, + .argv = &argv, + }); + + defer std.testing.allocator.free(proc.stdout); + defer std.testing.allocator.free(proc.stderr); + + const term = proc.term; + + try std.testing.expectEqual(term, std.ChildProcess.Term{ .Exited = 0 }); + try std.testing.expectEqual(proc.stderr.len, 0); + // ... +}