Skip to content

Commit 8ef209f

Browse files
committed
test: add end-to-end test for coverage hooks
Runs bashunit on fixture file with coverage enabled to verify the complete flow works correctly, including hook coverage attribution.
1 parent 3d8b8ec commit 8ef209f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/acceptance/coverage_hooks_test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
function set_up_before_script() {
55
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
66
LCOV_FILE="$(bashunit::temp_file "lcov-output")"
7+
LCOV_FILE_EXTERNAL="$(bashunit::temp_file "lcov-external")"
78
}
89

910
function test_coverage_includes_src_hits_from_setup_hook() {
@@ -27,3 +28,21 @@ function test_coverage_includes_src_hits_from_setup_hook() {
2728
assert_contains "SF:$(pwd)/src/" "$lcov"
2829
assert_contains "DA:" "$lcov"
2930
}
31+
32+
function test_coverage_hooks_via_external_bashunit() {
33+
# Run bashunit on fixture with coverage enabled and verify hook code is tracked
34+
local output
35+
output=$(BASHUNIT_COVERAGE=true \
36+
BASHUNIT_COVERAGE_PATHS="src/" \
37+
BASHUNIT_COVERAGE_REPORT="$LCOV_FILE_EXTERNAL" \
38+
./bashunit tests/acceptance/fixtures/test_coverage_hooks.sh --simple 2>&1)
39+
40+
assert_successful_code
41+
42+
# Verify LCOV file was created with coverage data
43+
assert_file_exists "$LCOV_FILE_EXTERNAL"
44+
local lcov
45+
lcov="$(cat "$LCOV_FILE_EXTERNAL" 2>/dev/null)"
46+
assert_contains "SF:" "$lcov"
47+
assert_contains "DA:" "$lcov"
48+
}

0 commit comments

Comments
 (0)