Skip to content

Commit be2e19c

Browse files
fix: parse XML test results instead of HTML for accurate test counts
- Switch from HTML to XML test result parsing for reliability - Parse test results from build/test-results/jvmTest/*.xml - Sum up tests from all XML files per module - Fail CI if no tests are found (prevents false positives) - Show per-module results before overall summary 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent ff943fc commit be2e19c

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

.github/workflows/test.yml

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,49 @@ jobs:
121121
total_tests=0
122122
total_failures=0
123123
total_errors=0
124+
total_skipped=0
124125
125126
for module in kotlin-core kotlin-client kotlin-tools; do
126-
html_file="$module/build/reports/tests/jvmTest/index.html"
127-
if [ -f "$html_file" ]; then
128-
# Extract test counts from HTML using grep and sed
129-
tests=$(grep -o '[0-9]* tests' "$html_file" | head -1 | sed 's/ tests//')
130-
failures=$(grep -o '[0-9]* failures' "$html_file" | head -1 | sed 's/ failures//' || echo "0")
131-
errors=$(grep -o '[0-9]* errors' "$html_file" | head -1 | sed 's/ errors//' || echo "0")
132-
133-
if [ -n "$tests" ]; then
134-
echo "✅ $module: $tests tests, $failures failures, $errors errors"
135-
total_tests=$((total_tests + tests))
136-
total_failures=$((total_failures + failures))
137-
total_errors=$((total_errors + errors))
127+
xml_dir="$module/build/test-results/jvmTest"
128+
if [ -d "$xml_dir" ]; then
129+
module_tests=0
130+
module_failures=0
131+
module_errors=0
132+
module_skipped=0
133+
134+
# Parse XML test results
135+
for xml_file in "$xml_dir"/*.xml; do
136+
if [ -f "$xml_file" ]; then
137+
tests=$(grep -o 'tests="[0-9]*"' "$xml_file" | sed 's/tests="\([0-9]*\)"/\1/')
138+
failures=$(grep -o 'failures="[0-9]*"' "$xml_file" | sed 's/failures="\([0-9]*\)"/\1/')
139+
errors=$(grep -o 'errors="[0-9]*"' "$xml_file" | sed 's/errors="\([0-9]*\)"/\1/')
140+
skipped=$(grep -o 'skipped="[0-9]*"' "$xml_file" | sed 's/skipped="\([0-9]*\)"/\1/')
141+
142+
module_tests=$((module_tests + ${tests:-0}))
143+
module_failures=$((module_failures + ${failures:-0}))
144+
module_errors=$((module_errors + ${errors:-0}))
145+
module_skipped=$((module_skipped + ${skipped:-0}))
146+
fi
147+
done
148+
149+
if [ $module_tests -gt 0 ]; then
150+
echo "✅ $module: $module_tests tests, $module_failures failures, $module_errors errors"
151+
total_tests=$((total_tests + module_tests))
152+
total_failures=$((total_failures + module_failures))
153+
total_errors=$((total_errors + module_errors))
154+
total_skipped=$((total_skipped + module_skipped))
138155
fi
139156
fi
140157
done
141158
159+
echo "---"
142160
echo "## Overall Results: $total_tests tests, $total_failures failures, $total_errors errors"
143161
if [ $total_failures -gt 0 ] || [ $total_errors -gt 0 ]; then
144162
echo "❌ Some tests failed"
145163
exit 1
164+
elif [ $total_tests -eq 0 ]; then
165+
echo "⚠️ No tests were found or executed"
166+
exit 1
146167
else
147-
echo "✅ All tests passed!"
168+
echo "✅ All $total_tests tests passed!"
148169
fi

0 commit comments

Comments
 (0)