forked from pbiggar/darklang-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-coverage
More file actions
executable file
·122 lines (106 loc) · 2.85 KB
/
run-coverage
File metadata and controls
executable file
·122 lines (106 loc) · 2.85 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# run-coverage - Run tests with code coverage and generate reports
#
# Usage: ./run-coverage [OPTIONS]
#
# Options:
# --no-report Skip HTML report generation
# -h, --help Show this help message
#
# Prerequisites:
# dotnet tool install -g coverlet.console
# dotnet tool install -g dotnet-reportgenerator-globaltool
set -e
# Parse arguments
NO_REPORT=false
HELP=false
while [[ $# -gt 0 ]]; do
case $1 in
--no-report)
NO_REPORT=true
shift
;;
-h|--help)
HELP=true
shift
;;
*)
shift
;;
esac
done
# Show help
if [ "$HELP" = true ]; then
echo "Usage: ./run-coverage [OPTIONS]"
echo ""
echo "Run tests with code coverage and generate HTML reports."
echo ""
echo "Options:"
echo " --no-report Skip HTML report generation"
echo " -h, --help Show this help message"
echo ""
echo "Prerequisites:"
echo " dotnet tool install -g coverlet.console"
echo " dotnet tool install -g dotnet-reportgenerator-globaltool"
echo ""
echo "Output:"
echo " coverage.xml Cobertura format coverage data"
echo " coverage-report/ HTML report directory"
exit 0
fi
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
# Check for required tools
if ! command -v coverlet &> /dev/null; then
echo "Error: coverlet not found."
echo "Install with: dotnet tool install -g coverlet.console"
exit 1
fi
if [ "$NO_REPORT" = false ] && ! command -v reportgenerator &> /dev/null; then
echo "Error: reportgenerator not found."
echo "Install with: dotnet tool install -g dotnet-reportgenerator-globaltool"
exit 1
fi
# Build
echo "Building..."
if ! timeout 120 dotnet build --verbosity quiet 2>&1; then
echo "Build failed!"
exit 1
fi
echo "Build complete."
echo ""
# Paths
TEST_DLL="$SCRIPT_DIR/bin/Tests/Debug/net10.0/Tests.dll"
TEST_EXE="$SCRIPT_DIR/bin/Tests/Debug/net10.0/Tests"
COVERAGE_OUTPUT="$SCRIPT_DIR/coverage.xml"
REPORT_DIR="$SCRIPT_DIR/coverage-report"
if [ ! -f "$TEST_DLL" ]; then
echo "Error: Test DLL not found at $TEST_DLL"
echo "Try running the build first."
exit 1
fi
# Clean previous coverage
rm -f "$COVERAGE_OUTPUT"
rm -rf "$REPORT_DIR"
# Run tests with coverage
echo "Running tests with coverage..."
echo ""
coverlet "$TEST_DLL" \
--target "$TEST_EXE" \
--format cobertura \
--output "$COVERAGE_OUTPUT" \
--exclude "[Tests]*"
echo ""
echo "Coverage data written to: $COVERAGE_OUTPUT"
# Generate HTML report
if [ "$NO_REPORT" = false ]; then
echo ""
echo "Generating HTML report..."
reportgenerator \
-reports:"$COVERAGE_OUTPUT" \
-targetdir:"$REPORT_DIR" \
-reporttypes:Html
echo ""
echo "Coverage report: $REPORT_DIR/index.html"
fi