Skip to content

Commit 475a16f

Browse files
add codecoverage
. . . . . . . .
1 parent 1fea064 commit 475a16f

3 files changed

Lines changed: 43 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,28 @@ on:
1111

1212
jobs:
1313
test:
14-
runs-on: ubuntu-latest
15-
name: Build and Test
14+
name: Build, Test and Check coverage
15+
runs-on: ubuntu-22.04
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: |
24+
sudo apt-get update
25+
sudo apt-get install -y kcov
26+
27+
- name: Install zig
28+
uses: mlugg/setup-zig@v2
29+
30+
- name: Zig build test
31+
run: zig build test -Dtest-coverage --summary all
32+
33+
- name: Upload results to Codecov
34+
uses: codecov/codecov-action@v5
35+
with:
36+
token: ${{ secrets.CODECOV_TOKEN }}
37+
directory: ./coverage/
38+
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: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,26 @@ 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+
"./coverage",
56+
null, // to get zig to use the --test-cmd-bin flag
57+
});
58+
}
59+
4660
const run_parcom_tests = b.addRunArtifact(parcom_tests);
4761

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

0 commit comments

Comments
 (0)