Skip to content

Commit d4c7d75

Browse files
committed
chore: add code coverage
1 parent 06c92f7 commit d4c7d75

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

.github/workflows/ci.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,24 @@ jobs:
2323
run: |
2424
cat regression.out
2525
cat regression.diffs
26+
27+
coverage:
28+
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
submodules: true
35+
- uses: cachix/install-nix-action@v18
36+
with:
37+
nix_path: nixpkgs=channel:nixos-unstable
38+
39+
- name: Run coverage
40+
run: nix-shell --run "nxpg-16 nxpg-tmp nxpg-coverage"
41+
42+
- name: Send coverage to Coveralls
43+
uses: coverallsapp/[email protected]
44+
with:
45+
github-token: ${{ secrets.GITHUB_TOKEN }}
46+
files: ./coverage.info

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ SRC = $(wildcard src/*.c)
1212
OBJS = $(patsubst src/%.c, src/%.o, $(SRC))
1313
SHLIB_LINK = -lmustach
1414
PG_CFLAGS = -std=c99 -Wno-declaration-after-statement -Wall -Werror -Wshadow
15+
ifeq ($(COVERAGE), 1)
16+
PG_CFLAGS += --coverage
17+
endif
1518

1619
TESTS = $(wildcard test/sql/*.sql)
1720
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))

nix/nxpg.nix

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ writeShellScriptBin, findutils, entr, callPackage, postgresql_17, postgresql_16, postgresql_15, postgresql_14, postgresql_13, postgresql_12 } :
1+
{ writeShellScriptBin, findutils, entr, callPackage, lcov, postgresql_17, postgresql_16, postgresql_15, postgresql_14, postgresql_13, postgresql_12 } :
22
let
33
prefix = "nxpg";
44
supportedPgs = [
@@ -24,7 +24,26 @@ let
2424
make
2525
make installcheck
2626
'';
27+
cov =
28+
writeShellScriptBin "${prefix}-coverage" ''
29+
set -euo pipefail
30+
31+
info_file="coverage.info"
32+
out_dir="coverage_html"
33+
34+
make clean
35+
make COVERAGE=1
36+
make installcheck
37+
${lcov}/bin/lcov --capture --directory . --output-file "$info_file"
38+
39+
# remove postgres headers on the nix store, otherwise they show on the output
40+
${lcov}/bin/lcov --remove "$info_file" '/nix/*' --output-file "$info_file" || true
2741
42+
${lcov}/bin/lcov --list coverage.info
43+
${lcov}/bin/genhtml "$info_file" --output-directory "$out_dir"
44+
45+
echo "${prefix}-coverage: To see the results, visit file://$(pwd)/$out_dir/index.html on your browser"
46+
'';
2847
watch =
2948
writeShellScriptBin "${prefix}-watch" ''
3049
set -euo pipefail
@@ -80,6 +99,7 @@ in
8099
[
81100
build
82101
test
102+
cov
83103
watch
84104
tmpDb
85105
allPgPaths

0 commit comments

Comments
 (0)