Repository navigation
Expand file tree
/
Copy pathcoverage.sh
More file actions
executable file
·57 lines (42 loc) · 1.91 KB
/
Copy pathcoverage.sh
File metadata and controls
executable file
·57 lines (42 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Script to run tests with coverage and generate reports
set -e
COV_DIR="coverage"
# Find the correct gcov (matching gfortran version)
GCOV=$(dirname $(which gfortran))/gcov
echo "Using gcov: $GCOV"
echo ""
echo "================================================"
echo "Running tests with coverage..."
echo "================================================"
# Build and run tests with coverage flags
fpm test --flag "--coverage"
fpm run --example --flag "--coverage"
echo ""
echo "================================================"
echo "Generating coverage report with lcov..."
echo "================================================"
# Create coverage directory and move build artifacts
mkdir -p "$COV_DIR"
cp -r build/gfortran_*/*/* "$COV_DIR/" 2>/dev/null || true
# we want to skip the files that start with 'build_dependencies' because they are not part of the source code
find "$COV_DIR" -name "build_dependencies*" -exec rm -rf {} +
find "$COV_DIR" -name "test_*" -exec rm -rf {} +
# Capture initial coverage (baseline)
lcov --ignore-errors inconsistent --gcov-tool "$GCOV" --capture --initial --base-directory . --directory "$COV_DIR" --output-file "$COV_DIR/coverage.base" --quiet
# Capture test execution coverage
lcov --ignore-errors inconsistent --gcov-tool "$GCOV" --capture --base-directory . --directory "$COV_DIR" --output-file "$COV_DIR/coverage.capture" --quiet
# Combine baseline and test coverage
lcov --add-tracefile "$COV_DIR/coverage.base" --add-tracefile "$COV_DIR/coverage.capture" --output-file "$COV_DIR/coverage.info" --quiet
echo ""
echo "================================================"
echo "Coverage Summary"
echo "================================================"
# Display summary
lcov --summary "$COV_DIR/coverage.info"
echo ""
echo "Coverage data saved to: $COV_DIR/coverage.info"
echo ""
echo "generate HTML report:"
genhtml $COV_DIR/coverage.info --output-directory $COV_DIR/html
echo ""