Skip to content

Commit

Permalink
chore: add code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Feb 10, 2025
1 parent 06c92f7 commit d4c7d75
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@ jobs:
run: |
cat regression.out
cat regression.diffs
coverage:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Run coverage
run: nix-shell --run "nxpg-16 nxpg-tmp nxpg-coverage"

- name: Send coverage to Coveralls
uses: coverallsapp/github-action@v2.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
files: ./coverage.info
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ SRC = $(wildcard src/*.c)
OBJS = $(patsubst src/%.c, src/%.o, $(SRC))
SHLIB_LINK = -lmustach
PG_CFLAGS = -std=c99 -Wno-declaration-after-statement -Wall -Werror -Wshadow
ifeq ($(COVERAGE), 1)
PG_CFLAGS += --coverage
endif

TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
Expand Down
22 changes: 21 additions & 1 deletion nix/nxpg.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ writeShellScriptBin, findutils, entr, callPackage, postgresql_17, postgresql_16, postgresql_15, postgresql_14, postgresql_13, postgresql_12 } :
{ writeShellScriptBin, findutils, entr, callPackage, lcov, postgresql_17, postgresql_16, postgresql_15, postgresql_14, postgresql_13, postgresql_12 } :
let
prefix = "nxpg";
supportedPgs = [
Expand All @@ -24,7 +24,26 @@ let
make
make installcheck
'';
cov =
writeShellScriptBin "${prefix}-coverage" ''
set -euo pipefail
info_file="coverage.info"
out_dir="coverage_html"
make clean
make COVERAGE=1
make installcheck
${lcov}/bin/lcov --capture --directory . --output-file "$info_file"
# remove postgres headers on the nix store, otherwise they show on the output
${lcov}/bin/lcov --remove "$info_file" '/nix/*' --output-file "$info_file" || true
${lcov}/bin/lcov --list coverage.info
${lcov}/bin/genhtml "$info_file" --output-directory "$out_dir"
echo "${prefix}-coverage: To see the results, visit file://$(pwd)/$out_dir/index.html on your browser"
'';
watch =
writeShellScriptBin "${prefix}-watch" ''
set -euo pipefail
Expand Down Expand Up @@ -80,6 +99,7 @@ in
[
build
test
cov
watch
tmpDb
allPgPaths
Expand Down

0 comments on commit d4c7d75

Please sign in to comment.