Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create intermediary directories if necessary when producing JUnit report #2862

Merged
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
15 changes: 10 additions & 5 deletions integration/hurl/tests_ok/junit.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
if (Test-Path build/result.xml) {
Remove-Item build/result.xml
if (Test-Path build/junit/result.xml) {
Remove-Item build/junit/result.xml
}

# test.2.hurl is KO but we want the script to continue until the end
$ErrorActionPreference = 'Continue'
# We use --jobs 1 to force the standard error order to be test1 then test2.
hurl --test --jobs 1 --report-junit build/result.xml tests_ok/test.1.hurl tests_ok/test.2.hurl
hurl --test --report-junit build/result.xml tests_ok/test.3.hurl
Write-Host (Get-Content build/result.xml -Raw) -NoNewLine
hurl --test --jobs 1 --report-junit build/junit/result.xml tests_ok/test.1.hurl tests_ok/test.2.hurl
hurl --test --report-junit build/junit/result.xml tests_ok/test.3.hurl
$ErrorActionPreference = 'Stop'

Write-Host (Get-Content build/junit/result.xml -Raw) -NoNewLine
8 changes: 4 additions & 4 deletions integration/hurl/tests_ok/junit.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash
set -Eeuo pipefail
rm -f build/result.xml
rm -f build/junit/result.xml

# test.2.hurl is KO but we want the script to continue until the end
set +eo pipefail
# We use --jobs 1 to force the standard error order to be test1 then test2.
hurl --test --jobs 1 --report-junit build/result.xml tests_ok/test.1.hurl tests_ok/test.2.hurl
hurl --test --report-junit build/result.xml tests_ok/test.3.hurl
hurl --test --jobs 1 --report-junit build/junit/result.xml tests_ok/test.1.hurl tests_ok/test.2.hurl
hurl --test --report-junit build/junit/result.xml tests_ok/test.3.hurl
set -Eeuo pipefail

cat build/result.xml
cat build/junit/result.xml
16 changes: 15 additions & 1 deletion packages/hurl/src/report/junit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,21 @@ use crate::report::ReportError;

/// Creates a JUnit from a list of `testcases`.
pub fn write_report(filename: &Path, testcases: &[Testcase]) -> Result<(), ReportError> {
// If there is an existing JUnit report, we parses it to insert a new testsuite.
// We ensure that parent folder is created.
if let Some(parent) = filename.parent() {
match std::fs::create_dir_all(parent) {
Ok(_) => {}
Err(err) => {
return Err(ReportError::from_error(
err,
filename,
"Issue writing Junit report",
))
}
}
}

// If there is an existing JUnit report, we parse it to insert a new testsuite.
let mut root = if filename.exists() {
let file = match File::open(filename) {
Ok(s) => s,
Expand Down
Loading