Description
This issue is related to #85563. The junit formatter of libtest does not produce correct XML for some doctests. Take the following as an example:
use std::marker::PhantomData;
pub struct WithGeneric<A> {
marker: PhantomData<A>
}
impl<A> WithGeneric<A> {
///
/// This is a doctest:
///
/// ```
/// let _ = hello_world::WithGeneric::<()>::new();
/// ```
///
pub fn new() -> Self {
WithGeneric { marker: PhantomData }
}
}
When running cargo +nightly-2022-07-26 test --doc -- -Z unstable-options --format junit
, the following (invalid) XML is generated (formatted with an external tool):
<?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="src/lib.rs" name="WithGeneric<A>::new (line 12)" time="0"/>
<system-out/>
<system-err/>
</testsuite>
</testsuites>
The XML is invalid because of the name
attribute of the testcase
element. It contains the invalid characters <
and >
, which should be escaped to <
and >
as far as I understand.
Proposed solution
In a quick and dirty way I would implement something similar to what the JSON formatter does to escape the strings to valid XML attributes - I just did not have time to make a PR so far.
Apart from that I never contributed to this repository, nor am I specifically familiar with libtest. What would it take to implement the serialization based on serde and a crate like serde_xml_rs? Could I just add these crates as a dependency? I feel like this would be much cleaner than just repeating what the json formatter does.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status