Skip to content

Commit 2ce9b82

Browse files
add codecoverage
.
1 parent 1fea064 commit 2ce9b82

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,26 @@ 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 kcov
23+
run: sudo apt-get install -y kcov
24+
25+
- name: Install zig
26+
uses: mlugg/setup-zig@v1
27+
28+
- name: Zig build test
29+
run: zig build test -Dtest-coverage --summary all
30+
31+
- name: Upload results to Codecov
32+
uses: codecov/codecov-action@v5
33+
with:
34+
token: ${{ secrets.CODECOV_TOKEN }}
35+
directory: ./coverage/
36+
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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,28 @@ pub fn build(b: *std.Build) void {
3636
"Skip tests that do not match any filter",
3737
) orelse &[0][]const u8{};
3838

39+
// -Dtest-coverage
40+
const coverage = b.option(
41+
bool,
42+
"test-coverage",
43+
"Generate test coverage",
44+
) orelse false;
45+
3946
const parcom_tests = b.addTest(.{
40-
.root_source_file = b.path("src/parcom.zig"),
41-
.target = target,
42-
.optimize = optimize,
47+
.root_module = parcom,
4348
.filters = test_filters,
4449
});
4550

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);
4762

4863
const test_step = b.step("test", "Run unit tests");

0 commit comments

Comments
 (0)