mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# ignore-cross-compile
|
||||
include ../tools.mk
|
||||
|
||||
# Test expected libtest's junit output
|
||||
|
||||
OUTPUT_FILE_DEFAULT := $(TMPDIR)/libtest-junit-output-default.xml
|
||||
OUTPUT_FILE_STDOUT_SUCCESS := $(TMPDIR)/libtest-junit-output-stdout-success.xml
|
||||
|
||||
all: f.rs validate_junit.py output-default.xml output-stdout-success.xml
|
||||
$(RUSTC) --test f.rs
|
||||
RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=junit > $(OUTPUT_FILE_DEFAULT) || true
|
||||
RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=junit --show-output > $(OUTPUT_FILE_STDOUT_SUCCESS) || true
|
||||
|
||||
cat $(OUTPUT_FILE_DEFAULT) | "$(PYTHON)" validate_junit.py
|
||||
cat $(OUTPUT_FILE_STDOUT_SUCCESS) | "$(PYTHON)" validate_junit.py
|
||||
|
||||
# Normalize the actual output and compare to expected output file
|
||||
cat $(OUTPUT_FILE_DEFAULT) | sed 's/time="[0-9.]*"/time="$$TIME"/g' | diff output-default.xml -
|
||||
cat $(OUTPUT_FILE_STDOUT_SUCCESS) | sed 's/time="[0-9.]*"/time="$$TIME"/g' | diff output-stdout-success.xml -
|
||||
@@ -0,0 +1,23 @@
|
||||
#[test]
|
||||
fn a() {
|
||||
println!("print from successful test");
|
||||
// Should pass
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn b() {
|
||||
println!("print from failing test");
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn c() {
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "msg"]
|
||||
fn d() {
|
||||
assert!(false);
|
||||
}
|
||||
@@ -0,0 +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>
|
||||
@@ -0,0 +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>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
# Try to decode line in order to ensure it is a valid XML document
|
||||
for line in sys.stdin:
|
||||
try:
|
||||
ET.fromstring(line)
|
||||
except ET.ParseError as pe:
|
||||
print("Invalid xml: %r" % line)
|
||||
raise
|
||||
Reference in New Issue
Block a user