Skip to content

Commit da4a30f

Browse files
Copilotfedejeanne
andcommitted
Add WSL/Windows verification script and sample XML for JUNIT.XSL whitespace fix
Agent-Logs-Url: https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/sessions/eb1d08ac-8aac-4de0-a889-9254eed0953a Co-authored-by: fedejeanne <2205684+fedejeanne@users.noreply.github.com>
1 parent 6794f11 commit da4a30f

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated HTML report produced by verify.sh — not tracked in source control
2+
report.html
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Sample JUnit XML result file used to manually verify JUNIT.XSL rendering.
4+
5+
The failure message intentionally contains multiple consecutive spaces and
6+
indentation so that the whitespace-preservation fix can be validated
7+
visually in the generated HTML report.
8+
9+
Expected (correct) rendering after the fix:
10+
String s = (String)o; <- four spaces between 's' and '='
11+
12+
Without the fix the browser collapses the spaces:
13+
String s = (String)o; <- only one space, indistinguishable from a
14+
different (passing) formatting
15+
-->
16+
<testsuites>
17+
<testsuite name="org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest"
18+
tests="3" errors="0" failures="1" skipped="1" time="0.312"
19+
timestamp="2024-11-15T10:30:00" hostname="build-agent">
20+
21+
<!-- Failing test: message has significant leading/internal whitespace -->
22+
<testcase name="testFormatAll01"
23+
classname="org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest"
24+
time="0.105">
25+
<failure message="contents was not formatted. Actual:&#10;package test1;&#10;public class E1 {&#10; public void foo( Object o ) {&#10; String s = (String)o;&#10; }&#10;}" type="java.lang.AssertionError">java.lang.AssertionError: contents was not formatted. Actual:
26+
package test1;
27+
public class E1 {
28+
public void foo( Object o ) {
29+
String s = (String)o;
30+
}
31+
}
32+
at org.junit.Assert.fail(Assert.java:89)
33+
at org.junit.Assert.failEquals(Assert.java:187)
34+
at org.junit.Assert.assertNotEquals(Assert.java:163)
35+
at org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest.assertChangedFromTo(SaveParticipantTest.java:986)
36+
at org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest.testFormatAll01(SaveParticipantTest.java:138)
37+
at java.base/java.lang.reflect.Method.invoke(Method.java:580)</failure>
38+
</testcase>
39+
40+
<!-- Passing test: included to show mixed results in the report -->
41+
<testcase name="testFormatAll02"
42+
classname="org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest"
43+
time="0.098"/>
44+
45+
<!-- Skipped test -->
46+
<testcase name="testFormatAll03"
47+
classname="org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest"
48+
time="0.109">
49+
<skipped/>
50+
</testcase>
51+
52+
</testsuite>
53+
</testsuites>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env bash
2+
# ---------------------------------------------------------------------------
3+
# verify.sh – Verify that JUNIT.XSL preserves whitespace in failure messages
4+
#
5+
# Works on Linux, macOS, and Windows Subsystem for Linux (WSL).
6+
#
7+
# Usage:
8+
# cd products/eclipse-junit-tests/src/main/scripts/verify
9+
# ./verify.sh
10+
#
11+
# The script transforms sample-results.xml with the parent JUNIT.XSL stylesheet
12+
# and opens the resulting HTML file in a browser.
13+
#
14+
# What to look for in the output:
15+
# In the "Type" column of the testFormatAll01 row you should see:
16+
#
17+
# contents was not formatted. Actual:
18+
# package test1;
19+
# public class E1 {
20+
# public void foo( Object o ) {
21+
# String s = (String)o; <-- four spaces preserved
22+
# }
23+
# }
24+
#
25+
# WITHOUT the fix, the browser collapses all whitespace sequences to a single
26+
# space, making "String s = (String)o;" look like "String s = (String)o;"
27+
# and the multiline message appears on one line.
28+
#
29+
# Requirements (one of the following):
30+
# • xsltproc – sudo apt-get install xsltproc (Ubuntu/WSL)
31+
# brew install libxslt (macOS)
32+
# • python3 – python3 -m pip install lxml
33+
# ---------------------------------------------------------------------------
34+
35+
set -euo pipefail
36+
37+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38+
XSL_FILE="$SCRIPT_DIR/../JUNIT.XSL"
39+
XML_FILE="$SCRIPT_DIR/sample-results.xml"
40+
OUT_FILE="$SCRIPT_DIR/report.html"
41+
42+
# Resolve the stylesheet path to an absolute URI (required by xsltproc)
43+
XSL_ABS="$(cd "$(dirname "$XSL_FILE")" && pwd)/$(basename "$XSL_FILE")"
44+
45+
echo "Input XML : $XML_FILE"
46+
echo "Stylesheet: $XSL_ABS"
47+
echo "Output : $OUT_FILE"
48+
echo ""
49+
50+
# ---------------------------------------------------------------------------
51+
# 1. Transform
52+
# ---------------------------------------------------------------------------
53+
if command -v xsltproc &>/dev/null; then
54+
echo "Using xsltproc..."
55+
xsltproc --novalid -o "$OUT_FILE" "$XSL_ABS" "$XML_FILE"
56+
57+
elif python3 -c "from lxml import etree" &>/dev/null 2>&1; then
58+
echo "Using python3 + lxml..."
59+
python3 - <<PYEOF
60+
from lxml import etree
61+
xml = etree.parse("$XML_FILE")
62+
xsl = etree.parse("$XSL_ABS")
63+
result = etree.XSLT(xsl)(xml)
64+
with open("$OUT_FILE", "w", encoding="utf-8") as f:
65+
f.write(str(result))
66+
PYEOF
67+
68+
else
69+
echo "ERROR: No XSLT processor found." >&2
70+
echo "" >&2
71+
echo "Install one of the following and re-run:" >&2
72+
echo " Ubuntu/WSL : sudo apt-get install xsltproc" >&2
73+
echo " macOS : brew install libxslt" >&2
74+
echo " Python : python3 -m pip install lxml" >&2
75+
exit 1
76+
fi
77+
78+
echo "HTML report written to: $OUT_FILE"
79+
echo ""
80+
81+
# ---------------------------------------------------------------------------
82+
# 2. Open in browser
83+
# ---------------------------------------------------------------------------
84+
open_in_browser() {
85+
local file="$1"
86+
87+
# WSL: use Windows explorer / default browser via wslview or explorer.exe
88+
if grep -qi microsoft /proc/version 2>/dev/null || \
89+
grep -qi wsl /proc/version 2>/dev/null; then
90+
# Convert the Linux path to a Windows path
91+
local win_path
92+
win_path="$(wslpath -w "$file" 2>/dev/null || echo "")"
93+
if [ -n "$win_path" ] && command -v explorer.exe &>/dev/null; then
94+
echo "Opening in Windows default browser via explorer.exe..."
95+
explorer.exe "$win_path"
96+
return
97+
fi
98+
fi
99+
100+
# macOS
101+
if command -v open &>/dev/null; then
102+
open "$file"
103+
return
104+
fi
105+
106+
# Linux (X11/Wayland)
107+
if command -v xdg-open &>/dev/null; then
108+
xdg-open "$file"
109+
return
110+
fi
111+
112+
echo "Could not open the browser automatically."
113+
echo "Open the following file manually in your browser:"
114+
echo " $file"
115+
}
116+
117+
open_in_browser "$OUT_FILE" || true

0 commit comments

Comments
 (0)