Skip to content

Commit 74be2b0

Browse files
add codecoverage
. . . . . .
1 parent 1fea064 commit 74be2b0

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,35 @@ on:
1111

1212
jobs:
1313
test:
14+
name: Build, Test and Check coverage
1415
runs-on: ubuntu-latest
15-
name: Build and Test
1616
steps:
17-
- uses: actions/checkout@v3
18-
- uses: mlugg/setup-zig@v1
19-
- run: zig build test --summary all
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Install zig
23+
uses: mlugg/setup-zig@v2
24+
25+
- name: Zig build test
26+
run: |
27+
zig build test --summary all
28+
ls zig-out/bin
29+
30+
- name: get kcov version
31+
uses: sudo-bot/action-kcov@latest
32+
with:
33+
cli-args: "--version"
34+
35+
- name: Run test with kcov coverage
36+
uses: sudo-bot/action-kcov@latest
37+
with:
38+
cli-args: "--dump-summary ./coverage ./zig-out/bin/test"
39+
40+
- name: Upload results to Codecov
41+
uses: codecov/codecov-action@v5
42+
with:
43+
token: ${{ secrets.CODECOV_TOKEN }}
44+
directory: ./coverage/
45+
fail_ci_if_error: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.zig-cache/
22
zig-out/
3+
kcov-output/
4+
coverage/

build.zig

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,32 @@ pub fn build(b: *std.Build) void {
3737
) orelse &[0][]const u8{};
3838

3939
const parcom_tests = b.addTest(.{
40-
.root_source_file = b.path("src/parcom.zig"),
41-
.target = target,
42-
.optimize = optimize,
40+
.root_module = parcom,
4341
.filters = test_filters,
4442
});
4543

44+
// -Dtest-coverage
45+
const coverage = b.option(
46+
bool,
47+
"test-coverage",
48+
"Generate test coverage",
49+
) orelse false;
50+
51+
if (coverage) {
52+
parcom_tests.setExecCmd(&[_]?[]const u8{
53+
"kcov",
54+
"--include-path=src/parcom.zig",
55+
"--dump-summary",
56+
"./coverage",
57+
null, // to get zig to use the --test-cmd-bin flag
58+
});
59+
}
60+
4661
const run_parcom_tests = b.addRunArtifact(parcom_tests);
62+
const install_tests_bin = b.addInstallArtifact(parcom_tests, .{});
4763

4864
const test_step = b.step("test", "Run unit tests");
65+
test_step.dependOn(&install_tests_bin.step);
4966
test_step.dependOn(&run_parcom_tests.step);
5067

5168
// ----- Examples -----

0 commit comments

Comments
 (0)