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+ 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
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 @@ -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" );
You can’t perform that action at this time.
0 commit comments