Skip to content

Commit

Permalink
test: move main
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesrocket committed Jun 18, 2024
1 parent 470191f commit 4058f3b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
15 changes: 11 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
20 changes: 20 additions & 0 deletions tests/cli.zig
Original file line number Diff line number Diff line change
@@ -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);
// ...
}

0 comments on commit 4058f3b

Please sign in to comment.