-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-coverage.sh
More file actions
executable file
·187 lines (167 loc) · 6.92 KB
/
generate-coverage.sh
File metadata and controls
executable file
·187 lines (167 loc) · 6.92 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# NebulaStore Test Coverage Generator (Bash version)
# This script runs tests with coverage and generates an HTML report
# Parse command line arguments
OPEN_REPORT=true
while [[ $# -gt 0 ]]; do
case $1 in
--no-open|--no-browser)
OPEN_REPORT=false
shift
;;
-h|--help)
echo "Usage: $0 [--no-open|--no-browser]"
echo " --no-open, --no-browser Don't open the report in browser"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use -h or --help for usage information"
exit 1
;;
esac
done
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}🧪 NebulaStore Test Coverage Generator${NC}"
echo -e "${BLUE}=====================================${NC}"
# Clean up old coverage reports and test results
echo -e "\n${YELLOW}🧹 Cleaning up old coverage reports and test results...${NC}"
# Remove coverage report directory
if [ -d "coverage-report" ]; then
rm -rf "coverage-report"
echo -e " ${GREEN}✓ Removed old coverage-report directory${NC}"
fi
# Find and remove all TestResults directories recursively
find . -type d -name "TestResults" -exec rm -rf {} + 2>/dev/null
echo -e " ${GREEN}✓ Cleaned up old TestResults directories${NC}"
# Remove any standalone coverage files
find . -name "*.cobertura.xml" -type f -delete 2>/dev/null
echo -e " ${GREEN}✓ Removed old coverage files${NC}"
# Clean build outputs to ensure fresh compilation
echo -e " ${YELLOW}Cleaning build outputs for fresh compilation...${NC}"
dotnet clean --verbosity quiet >/dev/null 2>&1
echo -e " ${GREEN}✓ Build outputs cleaned${NC}"
# Build solution to ensure latest code
echo -e "\n${YELLOW}🔨 Building solution to ensure latest code...${NC}"
dotnet build --verbosity quiet >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Build failed! Cannot proceed with testing.${NC}"
exit 1
fi
echo -e " ${GREEN}✓ Build completed successfully${NC}"
# Run tests with coverage
echo -e "\n${YELLOW}🔬 Running tests with coverage collection...${NC}"
dotnet test --collect:"XPlat Code Coverage" --verbosity minimal --no-build
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Tests failed! Coverage report generation aborted.${NC}"
exit 1
fi
echo -e " ${GREEN}✓ Tests completed successfully${NC}"
# Find coverage file
echo -e "\n${YELLOW}📊 Locating coverage files...${NC}"
COVERAGE_FILE=$(find . -name "coverage.cobertura.xml" | head -1)
if [ -z "$COVERAGE_FILE" ]; then
echo -e "${RED}❌ No coverage files found!${NC}"
echo -e "${YELLOW}Searching for TestResults directories...${NC}"
find . -name "TestResults" -type d | while read dir; do
echo -e " Found TestResults: $dir"
find "$dir" -name "*.xml" | while read file; do
echo -e " Found file: $file"
done
done
echo -e "${RED}Please ensure tests ran successfully and coverage was collected.${NC}"
exit 1
fi
echo -e " ${GREEN}✓ Found coverage file: $(basename "$COVERAGE_FILE")${NC}"
echo -e " ${BLUE}Full path: $COVERAGE_FILE${NC}"
# Check if reportgenerator is installed
echo -e "\n${YELLOW}🔧 Checking reportgenerator tool...${NC}"
if ! command -v reportgenerator &> /dev/null; then
echo -e " ${YELLOW}⚠️ reportgenerator not found, installing...${NC}"
dotnet tool install -g dotnet-reportgenerator-globaltool
if [ $? -eq 0 ]; then
echo -e " ${GREEN}✓ reportgenerator installed successfully${NC}"
# Refresh PATH to ensure tool is available
export PATH="$PATH:$HOME/.dotnet/tools"
else
echo -e "${RED}❌ Failed to install reportgenerator${NC}"
echo -e "${YELLOW}Trying alternative installation method...${NC}"
# Try with explicit path
export PATH="$PATH:$HOME/.dotnet/tools"
if command -v reportgenerator &> /dev/null; then
echo -e " ${GREEN}✓ reportgenerator found in PATH${NC}"
else
echo -e "${RED}❌ reportgenerator installation failed${NC}"
exit 1
fi
fi
else
echo -e " ${GREEN}✓ reportgenerator is available${NC}"
fi
# Generate coverage report
echo -e "\n${YELLOW}📈 Generating coverage report...${NC}"
# Suppress warnings about MessagePack generated files that get cleaned up
reportgenerator -reports:"$COVERAGE_FILE" -targetdir:"coverage-report" -reporttypes:"Html;HtmlSummary;Badges;TextSummary" 2>&1 | grep -v "MessagePack\.SourceGenerator.*does not exist"
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Failed to generate coverage report!${NC}"
exit 1
fi
echo -e " ${GREEN}✓ Coverage report generated successfully${NC}"
# Display summary
if [ -f "coverage-report/Summary.txt" ]; then
echo -e "\n${BLUE}📋 Coverage Summary:${NC}"
echo -e "${BLUE}===================${NC}"
grep -E "Line coverage:|Branch coverage:|Method coverage:" "coverage-report/Summary.txt" | while read line; do
echo -e " ${GREEN}$line${NC}"
done
fi
# Open report in browser
if [ -f "coverage-report/index.html" ]; then
REPORT_PATH="$(pwd)/coverage-report/index.html"
if [ "$OPEN_REPORT" = true ]; then
echo -e "\n${YELLOW}🌐 Opening coverage report in browser...${NC}"
# Try different browser opening commands based on platform
OPENED=false
# Linux
if command -v xdg-open &> /dev/null; then
xdg-open "file://$REPORT_PATH" 2>/dev/null &
OPENED=true
# macOS
elif command -v open &> /dev/null; then
open "file://$REPORT_PATH" 2>/dev/null &
OPENED=true
# Windows with WSL
elif command -v cmd.exe &> /dev/null; then
cmd.exe /c start "file://$REPORT_PATH" 2>/dev/null &
OPENED=true
# Try common browsers directly
elif command -v firefox &> /dev/null; then
firefox "file://$REPORT_PATH" 2>/dev/null &
OPENED=true
elif command -v google-chrome &> /dev/null; then
google-chrome "file://$REPORT_PATH" 2>/dev/null &
OPENED=true
elif command -v chromium &> /dev/null; then
chromium "file://$REPORT_PATH" 2>/dev/null &
OPENED=true
fi
if [ "$OPENED" = true ]; then
echo -e " ${GREEN}✓ Report opened: $REPORT_PATH${NC}"
else
echo -e " ${YELLOW}⚠️ Could not auto-open browser${NC}"
echo -e " ${YELLOW}💡 Please open this file manually: file://$REPORT_PATH${NC}"
fi
else
echo -e "\n${YELLOW}🌐 Coverage report ready!${NC}"
echo -e " ${GREEN}✓ Report location: $REPORT_PATH${NC}"
echo -e " ${BLUE}💡 Open in browser: file://$REPORT_PATH${NC}"
fi
fi
echo -e "\n${GREEN}✅ Coverage report generation completed!${NC}"
echo -e "${BLUE}📁 Report location: $(pwd)/coverage-report${NC}"