From d4546d58bed6dbf887f37225a4255150817333f2 Mon Sep 17 00:00:00 2001 From: Brett Broadhurst Date: Wed, 18 Mar 2026 03:57:02 -0600 Subject: [PATCH] chore: configure kcov for test coverage --- build.zig | 18 ++++++++++++++++++ src/{ => Story}/runtime_tests.zig | 2 +- src/{ => Story}/testdata/hello-world/input.txt | 0 src/{ => Story}/testdata/hello-world/story.ink | 0 .../testdata/hello-world/transcript.txt | 0 .../testdata/monsieur-fogg/input.txt | 0 .../testdata/monsieur-fogg/story.ink | 0 .../testdata/monsieur-fogg/transcript.txt | 0 src/root.zig | 2 +- 9 files changed, 20 insertions(+), 2 deletions(-) rename src/{ => Story}/runtime_tests.zig (98%) rename src/{ => Story}/testdata/hello-world/input.txt (100%) rename src/{ => Story}/testdata/hello-world/story.ink (100%) rename src/{ => Story}/testdata/hello-world/transcript.txt (100%) rename src/{ => Story}/testdata/monsieur-fogg/input.txt (100%) rename src/{ => Story}/testdata/monsieur-fogg/story.ink (100%) rename src/{ => Story}/testdata/monsieur-fogg/transcript.txt (100%) diff --git a/build.zig b/build.zig index 6d6eb72..73ab78f 100644 --- a/build.zig +++ b/build.zig @@ -1,6 +1,8 @@ const std = @import("std"); pub fn build(b: *std.Build) void { + const use_llvm = true; + const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const mod = b.addModule("ink", .{ @@ -32,13 +34,29 @@ pub fn build(b: *std.Build) void { const mod_tests = b.addTest(.{ .root_module = mod, + .use_llvm = use_llvm, + .use_lld = use_llvm, }); const run_mod_tests = b.addRunArtifact(mod_tests); + const exe_tests = b.addTest(.{ .root_module = exe.root_module, + .use_llvm = use_llvm, + .use_lld = use_llvm, }); const run_exe_tests = b.addRunArtifact(exe_tests); + const test_step = b.step("test", "Run tests"); test_step.dependOn(&run_mod_tests.step); test_step.dependOn(&run_exe_tests.step); + + const run_cover = b.addSystemCommand(&.{ + "kcov", + "--clean", + "--include-pattern=src/", + b.pathJoin(&.{ b.install_path, "cover" }), + }); + run_cover.addArtifactArg(mod_tests); + const cover_step = b.step("cover", "Generate test coverage report"); + cover_step.dependOn(&run_cover.step); } diff --git a/src/runtime_tests.zig b/src/Story/runtime_tests.zig similarity index 98% rename from src/runtime_tests.zig rename to src/Story/runtime_tests.zig index 07c28ba..1ed4691 100644 --- a/src/runtime_tests.zig +++ b/src/Story/runtime_tests.zig @@ -1,6 +1,6 @@ const std = @import("std"); const fatal = std.process.fatal; -const ink = @import("root.zig"); +const ink = @import("../root.zig"); const Options = struct { input_reader: *std.Io.Reader, diff --git a/src/testdata/hello-world/input.txt b/src/Story/testdata/hello-world/input.txt similarity index 100% rename from src/testdata/hello-world/input.txt rename to src/Story/testdata/hello-world/input.txt diff --git a/src/testdata/hello-world/story.ink b/src/Story/testdata/hello-world/story.ink similarity index 100% rename from src/testdata/hello-world/story.ink rename to src/Story/testdata/hello-world/story.ink diff --git a/src/testdata/hello-world/transcript.txt b/src/Story/testdata/hello-world/transcript.txt similarity index 100% rename from src/testdata/hello-world/transcript.txt rename to src/Story/testdata/hello-world/transcript.txt diff --git a/src/testdata/monsieur-fogg/input.txt b/src/Story/testdata/monsieur-fogg/input.txt similarity index 100% rename from src/testdata/monsieur-fogg/input.txt rename to src/Story/testdata/monsieur-fogg/input.txt diff --git a/src/testdata/monsieur-fogg/story.ink b/src/Story/testdata/monsieur-fogg/story.ink similarity index 100% rename from src/testdata/monsieur-fogg/story.ink rename to src/Story/testdata/monsieur-fogg/story.ink diff --git a/src/testdata/monsieur-fogg/transcript.txt b/src/Story/testdata/monsieur-fogg/transcript.txt similarity index 100% rename from src/testdata/monsieur-fogg/transcript.txt rename to src/Story/testdata/monsieur-fogg/transcript.txt diff --git a/src/root.zig b/src/root.zig index 6864bc1..eaf4636 100644 --- a/src/root.zig +++ b/src/root.zig @@ -6,5 +6,5 @@ test { _ = tokenizer; _ = Ast; _ = Story; - _ = @import("runtime_tests.zig"); + _ = @import("Story/runtime_tests.zig"); }