diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-09-28 20:00:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-28 20:00:15 +0200 |
| commit | e601554dc0e2443a286cf529c1463b00d8e1fdde (patch) | |
| tree | de7103745dbb021f425bfd5df1d0e6a1b4c5264c | |
| parent | 3c60e040b29c6b9cbf0ed1df31d7469d4634ac4d (diff) | |
| parent | 0911069febd6c247594c26e41c2e5cf8ffb8a74f (diff) | |
| download | rust-e601554dc0e2443a286cf529c1463b00d8e1fdde.tar.gz rust-e601554dc0e2443a286cf529c1463b00d8e1fdde.zip | |
Rollup merge of #89235 - yaahc:junit-formatting, r=kennytm
make junit output more consistent with default format The default format of libtest includes new-lines between each section to ensure the label output from cargo is on it's own line <pre><font color="#A1B56C"><b>❯</b></font> <font color="#A1B56C">cargo</font><font color="#D8D8D8"> </font><font color="#A1B56C">test</font> <font color="#A1B56C"><b> Compiling</b></font> test-test v0.1.0 (/home/jlusby/tmp/test-test) <font color="#A1B56C"><b> Finished</b></font> test [unoptimized + debuginfo] target(s) in 0.59s <font color="#A1B56C"><b> Running</b></font> unittests (target/debug/deps/test_test-639f369234319c09) running 1 test test tests::it_works ... <font color="#A1B56C">ok</font> test result: <font color="#A1B56C">ok</font>. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s <font color="#A1B56C"><b> Doc-tests</b></font> test-test running 0 tests test result: <font color="#A1B56C">ok</font>. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s </pre> But when the junit outputter was added to libtest these newlines were omitted, resulting in some "fun" output when run via cargo. Note the `Doc-tests` text at the end of the first line of xml. <pre><font color="#A1B56C"><b>❯</b></font> <font color="#A1B56C">cargo</font><font color="#D8D8D8"> </font><font color="#A1B56C">test</font><font color="#D8D8D8"> </font><font color="#A1B56C">--</font><font color="#D8D8D8"> </font><font color="#A1B56C">-Zunstable-options</font><font color="#D8D8D8"> </font><font color="#A1B56C">--format</font><font color="#D8D8D8"> </font><font color="#A1B56C">junit</font> <font color="#A1B56C"><b> Finished</b></font> test [unoptimized + debuginfo] target(s) in 0.00s <font color="#A1B56C"><b> Running</b></font> unittests (target/debug/deps/test_test-639f369234319c09) <?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="0" tests="1" skipped="0" ><testcase classname="tests" name="it_works" time="0"/><system-out/><system-err/></testsuite></testsuites><font color="#A1B56C"><b> Doc-tests</b></font> test-test <?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="0" tests="0" skipped="0" ><system-out/><system-err/></testsuite></testsuites> </pre> After this PR the junit output includes the same style of newlines as the pretty format <pre><font color="#A1B56C"><b>❯</b></font> <font color="#A1B56C">cargo</font><font color="#D8D8D8"> </font><font color="#A1B56C">test</font><font color="#D8D8D8"> </font><font color="#A1B56C">--</font><font color="#D8D8D8"> </font><font color="#A1B56C">-Zunstable-options</font><font color="#D8D8D8"> </font><font color="#A1B56C">--format</font><font color="#D8D8D8"> </font><font color="#A1B56C">junit</font> <font color="#A1B56C"><b> Compiling</b></font> test-test v0.1.0 (/home/jlusby/tmp/test-test) <font color="#A1B56C"><b> Finished</b></font> test [unoptimized + debuginfo] target(s) in 0.39s <font color="#A1B56C"><b> Running</b></font> unittests (target/debug/deps/test_test-42c2320bb9450c69) <?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="0" tests="1" skipped="0" ><testcase classname="tests" name="it_works" time="0"/><system-out/><system-err/></testsuite></testsuites> <font color="#A1B56C"><b> Doc-tests</b></font> test-test <?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="0" tests="0" skipped="0" ><system-out/><system-err/></testsuite></testsuites> </pre>
| -rw-r--r-- | library/test/src/formatters/junit.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/library/test/src/formatters/junit.rs b/library/test/src/formatters/junit.rs index aa244807514..04057906d1c 100644 --- a/library/test/src/formatters/junit.rs +++ b/library/test/src/formatters/junit.rs @@ -29,7 +29,8 @@ impl<T: Write> JunitFormatter<T> { impl<T: Write> OutputFormatter for JunitFormatter<T> { fn write_run_start(&mut self, _test_count: usize) -> io::Result<()> { // We write xml header on run start - self.write_message(&"<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + self.out.write_all(b"\n")?; + self.write_message("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") } fn write_test_start(&mut self, _desc: &TestDesc) -> io::Result<()> { @@ -133,6 +134,8 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> { self.write_message("</testsuite>")?; self.write_message("</testsuites>")?; + self.out.write_all(b"\n\n")?; + Ok(state.failed == 0) } } |
