Skip to content

Commit d77f636

Browse files
committed
libtest: add tests for junit output format
I'm about to make some changes here, and it was making me uneasy to modify the output format without test coverage.
1 parent 1151ea6 commit d77f636

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

tests/run-make/libtest-junit/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ignore-cross-compile
2+
include ../tools.mk
3+
4+
# Test expected libtest's junit output
5+
6+
OUTPUT_FILE_DEFAULT := $(TMPDIR)/libtest-junit-output-default.xml
7+
OUTPUT_FILE_STDOUT_SUCCESS := $(TMPDIR)/libtest-junit-output-stdout-success.xml
8+
9+
all: f.rs validate_junit.py output-default.xml output-stdout-success.xml
10+
$(RUSTC) --test f.rs
11+
RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=junit > $(OUTPUT_FILE_DEFAULT) || true
12+
RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=junit --show-output > $(OUTPUT_FILE_STDOUT_SUCCESS) || true
13+
14+
cat $(OUTPUT_FILE_DEFAULT) | "$(PYTHON)" validate_junit.py
15+
cat $(OUTPUT_FILE_STDOUT_SUCCESS) | "$(PYTHON)" validate_junit.py
16+
17+
# Normalize the actual output and compare to expected output file
18+
cat $(OUTPUT_FILE_DEFAULT) | sed 's/time="[0-9.]*"/time="$$TIME"/g' | diff output-default.xml -
19+
cat $(OUTPUT_FILE_STDOUT_SUCCESS) | sed 's/time="[0-9.]*"/time="$$TIME"/g' | diff output-stdout-success.xml -

tests/run-make/libtest-junit/f.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[test]
2+
fn a() {
3+
println!("print from successful test");
4+
// Should pass
5+
}
6+
7+
#[test]
8+
fn b() {
9+
println!("print from failing test");
10+
assert!(false);
11+
}
12+
13+
#[test]
14+
#[should_panic]
15+
fn c() {
16+
assert!(false);
17+
}
18+
19+
#[test]
20+
#[ignore = "msg"]
21+
fn d() {
22+
assert!(false);
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="1" tests="4" skipped="1" ><testcase classname="unknown" name="a" time="$TIME"/><testcase classname="unknown" name="b" time="$TIME"><failure type="assert"/></testcase><testcase classname="unknown" name="c" time="$TIME"/><system-out/><system-err/></testsuite></testsuites>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="1" tests="4" skipped="1" ><testcase classname="unknown" name="a" time="$TIME"/><testcase classname="unknown" name="b" time="$TIME"><failure type="assert"/></testcase><testcase classname="unknown" name="c" time="$TIME"/><system-out/><system-err/></testsuite></testsuites>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import xml.etree.ElementTree as ET
5+
6+
# Try to decode line in order to ensure it is a valid XML document
7+
for line in sys.stdin:
8+
try:
9+
ET.fromstring(line)
10+
except ET.ParseError as pe:
11+
print("Invalid xml: %r" % line)
12+
raise

0 commit comments

Comments
 (0)