Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/+junit-case-name.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
`eb-junit` now gives every case a unique name. A case whose name lost
a character during escaping could share a name with another case,
and GitLab then showed only one of them.
32 changes: 24 additions & 8 deletions src/bin/eb-junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use eb_pipeline::{exit, run, util};
use serde_json::{Map, Number, Value};
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
use std::ffi::OsString;
use std::path::{Path, PathBuf};
use std::process::ExitCode;
Expand Down Expand Up @@ -639,16 +639,16 @@ fn write_case(out: &mut String, class: &str, case: &Case) {
}

fn disambiguate(names: &[String]) -> Vec<String> {
let mut seen = BTreeMap::<String, usize>::new();
let mut used = BTreeSet::new();
let mut out = Vec::with_capacity(names.len());
for name in names {
let n = seen.entry(escape_attr(name)).or_insert(0);
*n += 1;
if *n == 1 {
out.push(name.clone());
} else {
out.push(format!("{name} #{n}"));
let mut n = 1usize;
let mut candidate = name.clone();
while !used.insert(escape_attr(&candidate)) {
n += 1;
candidate = format!("{name} #{n}");
}
out.push(candidate);
}
out
}
Expand Down Expand Up @@ -855,6 +855,22 @@ mod tests {
assert!(xml.contains("name=\"cpu/Ok-1.0.eb #2\""));
}

#[test]
fn a_numbered_suffix_does_not_reuse_another_xml_safe_name() {
let text = concat!(
r#"{"schema_version":1,"kind":"result","site":"example","target":"cpu","#,
r#""build_type":"production","run_id":"n","exit_code":1,"lines":["#,
r#"{"easyconfig":"A.eb","unit":"all","phase":"build","status":"failed"},"#,
r#"{"easyconfig":"A.eb","unit":"all","phase":"build","status":"failed"},"#,
"{\"easyconfig\":\"A\\u0001.eb #2\",\"unit\":\"all\",\"phase\":\"build\",\"status\":\"failed\"}",
"]}"
);
let xml = render(text).unwrap();
assert_eq!(xml.matches("name=\"cpu/A.eb\"").count(), 1, "{xml}");
assert_eq!(xml.matches("name=\"cpu/A.eb #2\"").count(), 1, "{xml}");
assert_eq!(xml.matches("name=\"cpu/A.eb #2 #2\"").count(), 1, "{xml}");
}

#[test]
fn a_run_that_stops_before_a_line_fails_is_one_exit_case() {
let text = r#"{
Expand Down
Loading