A library for parsing Tiled maps.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add test coverage

Stolen from zigtools/zls

+26 -4
+26 -4
build.zig
··· 5 5 // runner. 6 6 pub fn build(b: *std.Build) void { 7 7 const target = b.standardTargetOptions(.{}); 8 - 9 8 const optimize = b.standardOptimizeOption(.{}); 10 9 11 - _ = b.addModule("tmz", .{ .root_source_file = b.path("src/tmz.zig") }); 10 + const coverage = b.option(bool, "coverage", "Generate a coverage report with kcov") orelse false; 12 11 13 12 const lib_mod = b.createModule(.{ 14 13 .root_source_file = b.path("src/tmz.zig"), ··· 28 27 .root_module = lib_mod, 29 28 }); 30 29 31 - const run_unit_tests = b.addRunArtifact(unit_tests); 30 + const run_tests = b.addRunArtifact(unit_tests); 32 31 33 32 const test_step = b.step("test", "Run unit tests"); 34 - test_step.dependOn(&run_unit_tests.step); 33 + test_step.dependOn(&run_tests.step); 34 + 35 + if (coverage) { 36 + const kcov_bin = b.findProgram(&.{"kcov"}, &.{}) catch "kcov"; 37 + const merge_step = std.Build.Step.Run.create(b, "merge coverage"); 38 + merge_step.addArgs(&.{ kcov_bin, "--merge" }); 39 + merge_step.rename_step_with_output_arg = false; 40 + const merged_coverage_output = merge_step.addOutputFileArg("."); 41 + 42 + run_tests.setName(b.fmt("{s} (collect coverage)", .{run_tests.step.name})); 43 + // prepend the kcov exec args 44 + const argv = run_tests.argv.toOwnedSlice(b.allocator) catch @panic("OOM"); 45 + run_tests.addArgs(&.{ kcov_bin, "--collect-only" }); 46 + run_tests.addPrefixedDirectoryArg("--include-pattern=", b.path("src")); 47 + merge_step.addDirectoryArg(run_tests.addOutputFileArg(run_tests.producer.?.name)); 48 + run_tests.argv.appendSlice(b.allocator, argv) catch @panic("OOM"); 49 + 50 + const install_coverage = b.addInstallDirectory(.{ 51 + .source_dir = merged_coverage_output, 52 + .install_dir = .{ .custom = "coverage" }, 53 + .install_subdir = "", 54 + }); 55 + test_step.dependOn(&install_coverage.step); 56 + } 35 57 }