Skip to content

Commit 5027315

Browse files
authored
Merge pull request #12 from mtsmfm/ignore
Ignore invalid XML files
2 parents f8a8262 + 697e487 commit 5027315

File tree

7 files changed

+76
-2
lines changed

7 files changed

+76
-2
lines changed

src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ fn get_test_file_results(junit_xml_report_dir: &PathBuf) -> Result<HashMap<PathB
8888
let mut test_file_results = HashMap::new();
8989

9090
for xml_path in expand_globs(&vec![String::from(xml_glob)])? {
91-
let reader = BufReader::new(File::open(xml_path)?);
92-
let test_result_xml: TestResultXml = from_reader(reader)?;
91+
let reader = BufReader::new(File::open(&xml_path)?);
92+
let test_result_xml: TestResultXml = from_reader(reader).unwrap_or_else(|err| {
93+
warn!("Failed to parse XML file {:?}: {}", xml_path, err);
94+
TestResultXml {
95+
test_suites: None,
96+
test_cases: None,
97+
}
98+
});
9399

94100
let test_suites = test_result_xml.test_suites.unwrap_or(vec![TestSuite {
95101
test_cases: test_result_xml.test_cases.unwrap_or(vec![]),

tests/fixtures/invalid/a_spec.rb

Whitespace-only changes.

tests/fixtures/invalid/b_spec.rb

Whitespace-only changes.

tests/fixtures/invalid/empty.xml

Whitespace-only changes.

tests/fixtures/invalid/foo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/home/mtsmfm/ghq/github.com/mtsmfm/split-test/tests/fixtures/invalid/a_spec.rb
2+
/home/mtsmfm/ghq/github.com/mtsmfm/split-test/tests/fixtures/invalid/b_spec.rb

tests/fixtures/invalid/foo.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo

tests/integration_test.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,68 @@ fn test_multiple_tests_glob_arg() -> Result<(), Box<dyn std::error::Error>> {
175175

176176
Ok(())
177177
}
178+
179+
#[test]
180+
fn test_invalid_report() -> Result<(), Box<dyn std::error::Error>> {
181+
let mut cmd = Command::cargo_bin("split-test")?;
182+
183+
cmd.current_dir("tests/fixtures/invalid")
184+
.arg("--junit-xml-report-dir")
185+
.arg(".")
186+
.arg("--node-index")
187+
.arg("0")
188+
.arg("--node-total")
189+
.arg("2")
190+
.arg("--tests-glob")
191+
.arg("**/*_spec.rb")
192+
.arg("--debug");
193+
194+
cmd.assert()
195+
.success()
196+
.stdout(predicate::str::contains("a_spec.rb"))
197+
.stdout(predicate::str::contains("b_spec.rb").not())
198+
.stderr(
199+
predicate::str::is_match(
200+
"Failed to parse XML file \".*/tests/fixtures/invalid/empty.xml\"",
201+
)
202+
.unwrap(),
203+
)
204+
.stderr(
205+
predicate::str::is_match(
206+
"Failed to parse XML file \".*/tests/fixtures/invalid/foo.xml\"",
207+
)
208+
.unwrap(),
209+
);
210+
211+
cmd = Command::cargo_bin("split-test")?;
212+
213+
cmd.current_dir("tests/fixtures/invalid")
214+
.arg("--junit-xml-report-dir")
215+
.arg(".")
216+
.arg("--node-index")
217+
.arg("1")
218+
.arg("--node-total")
219+
.arg("2")
220+
.arg("--tests-glob")
221+
.arg("**/*_spec.rb")
222+
.arg("--debug");
223+
224+
cmd.assert()
225+
.success()
226+
.stdout(predicate::str::contains("a_spec.rb").not())
227+
.stdout(predicate::str::contains("b_spec.rb"))
228+
.stderr(
229+
predicate::str::is_match(
230+
"Failed to parse XML file \".*/tests/fixtures/invalid/empty.xml\"",
231+
)
232+
.unwrap(),
233+
)
234+
.stderr(
235+
predicate::str::is_match(
236+
"Failed to parse XML file \".*/tests/fixtures/invalid/foo.xml\"",
237+
)
238+
.unwrap(),
239+
);
240+
241+
Ok(())
242+
}

0 commit comments

Comments
 (0)