File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111
1212jobs :
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
Original file line number Diff line number Diff line change 11.zig-cache /
22zig-out /
3+ kcov-output /
4+ coverage /
Original file line number Diff line number Diff 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" );
You can’t perform that action at this time.
0 commit comments