aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorLion Kortlepel <[email protected]>2026-01-22 23:19:18 +0100
committerLion Kortlepel <[email protected]>2026-01-22 23:19:18 +0100
commitbd8123cb766a763b7699ae83c3d1b17e5746f842 (patch)
treed50b19ace2655e9ba7c116142e6ef8182e3796ef /scripts
parent2d2be7e2b38031f7cd826f78543b18a287423ad7 (diff)
downloadargs-bd8123cb766a763b7699ae83c3d1b17e5746f842.tar.zst
args-bd8123cb766a763b7699ae83c3d1b17e5746f842.zip
ci: add coverage scripts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile-cov25
-rwxr-xr-xscripts/test_coverage.sh38
2 files changed, 63 insertions, 0 deletions
diff --git a/scripts/Makefile-cov b/scripts/Makefile-cov
new file mode 100644
index 0000000..023d020
--- /dev/null
+++ b/scripts/Makefile-cov
@@ -0,0 +1,25 @@
+# Coverage makefile, DO NOT USE
+# This file is mostly AI generated.
+
+CFLAGS=-fprofile-arcs -ftest-coverage -DNDEBUG -I.
+
+all: tests_cov_tmp
+
+tests_cov_tmp: ls_args.o tests/tests.c tests/ls_test.h
+ $(CC) -o $@ ls_args.o tests/tests.c -Itests -ggdb $(CFLAGS)
+
+ls_args.o: ls_args.h
+ echo -e "#include <stddef.h>\nvoid* test_realloc(void*, size_t);" >.test.h
+ cat .test.h ls_args.h >.ls_args_test.c
+ $(CC) -c -x c -o $@ .ls_args_test.c -Wall -Wextra -Wpedantic -Werror -std=c89 -ggdb \
+ -Wno-error=pragma-once-outside-header \
+ -DLS_ARGS_IMPLEMENTATION \
+ -DLS_REALLOC=test_realloc \
+ -Wno-pragma-once-outside-header \
+ $(CFLAGS)
+
+.PHONY: clean
+
+clean:
+ rm -f tests_cov_tmp
+ rm -f ls_args.o
diff --git a/scripts/test_coverage.sh b/scripts/test_coverage.sh
new file mode 100755
index 0000000..adca730
--- /dev/null
+++ b/scripts/test_coverage.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# This file is mostly AI generated.
+set -euo pipefail
+set -x
+
+# Absolute paths
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+ROOT_DIR="$SCRIPT_DIR/.."
+COVERAGE_DIR="$ROOT_DIR/coverage"
+
+# Clean and prepare coverage dir
+rm -rf "$COVERAGE_DIR"
+mkdir -p "$COVERAGE_DIR"
+
+# Copy all relevant files to coverage directory
+cp "$ROOT_DIR/ls_args.h" "$COVERAGE_DIR/"
+mkdir -p "$COVERAGE_DIR/tests"
+cp "$ROOT_DIR/tests/tests.c" "$COVERAGE_DIR/tests/"
+cp "$ROOT_DIR/tests/ls_test.h" "$COVERAGE_DIR/tests/"
+cp "$SCRIPT_DIR/Makefile-cov" "$COVERAGE_DIR/Makefile"
+
+cd "$COVERAGE_DIR"
+
+export CFLAGS="-fprofile-arcs -ftest-coverage -DNDEBUG"
+# Build test binary with coverage instrumentation
+# Also disable asserts because they do not count for us
+make -B
+
+# Run test binary (generates .gcda files here)
+./tests_cov_tmp
+
+# Generate coverage reports (all output local to coverage/)
+gcovr --root . --object-directory . --exclude-directories tests --output coverage.txt
+gcovr --root . --object-directory . --exclude-directories tests --html --html-details -o coverage.html
+
+echo "Coverage summary: $COVERAGE_DIR/coverage.txt"
+echo "HTML report: $COVERAGE_DIR/coverage.html"