pkg: add test targets

This commit is contained in:
Mitchell Hashimoto
2023-10-01 18:43:25 -07:00
parent f0d4e9c7c3
commit 0021b290cf
5 changed files with 77 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
_ = b.addModule("macos", .{ .source_file = .{ .path = "main.zig" } });
const module = b.addModule("macos", .{ .source_file = .{ .path = "main.zig" } });
const lib = b.addStaticLibrary(.{
.name = "macos",
@@ -31,4 +31,20 @@ pub fn build(b: *std.Build) !void {
try apple_sdk.addPaths(b, lib);
b.installArtifact(lib);
{
const test_exe = b.addTest(.{
.name = "test",
.root_source_file = .{ .path = "main.zig" },
.target = target,
.optimize = optimize,
});
test_exe.linkLibrary(lib);
var it = module.dependencies.iterator();
while (it.next()) |entry| test_exe.addModule(entry.key_ptr.*, entry.value_ptr.*);
const tests_run = b.addRunArtifact(test_exe);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&tests_run.step);
}
}