Skip to content

Commit

Permalink
Add Junit integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Apr 19, 2023
1 parent c473d69 commit 085abb0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
9 changes: 7 additions & 2 deletions integration/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,19 @@ def test_stdout_pattern(f, result):
actual_lines = re.split(r"\r?\n", actual)

if len(actual_lines) != len(expected_pattern_lines):
print(">>> error in stout / mismatch in number of lines")
print(">>> error in stdout / mismatch in number of lines")
print(
f"actual: {len(actual_lines)} lines\nexpected: {len(expected_pattern_lines)} lines"
)
print(f"actual <{actual}>")

with open("build/result.xml") as f:
content = f.read()
print(f"content <{content}>")
sys.exit(1)
for i in range(len(expected_pattern_lines)):
if not re.match(expected_pattern_lines[i], actual_lines[i]):
print(f">>> error in stout in line {i+1}")
print(f">>> error in stdout in line {i+1}")
print(f"actual: <{actual_lines[i]}>")
print(
f"expected: <{expected_lines[i]}> (translated to regex <{expected_pattern_lines[i]}>)"
Expand Down
18 changes: 18 additions & 0 deletions integration/tests_ok/junit.err.pattern
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests_ok~test.1.hurl: Running [1/2]
tests_ok~test.1.hurl: Success (1 request(s) in ~~~ ms)
tests_ok~test.2.hurl: Running [2/2]
tests_ok~test.2.hurl: Success (1 request(s) in ~~~ ms)
--------------------------------------------------------------------------------
Executed files: 2
Succeeded files: 2 (100.0%)
Failed files: 0 (0.0%)
Duration: ~ ms

tests_ok~test.3.hurl: Running [1/1]
tests_ok~test.3.hurl: Success (1 request(s) in ~~~ ms)
--------------------------------------------------------------------------------
Executed files: 1
Succeeded files: 1 (100.0%)
Failed files: 0 (0.0%)
Duration: ~~~ ms

1 change: 1 addition & 0 deletions integration/tests_ok/junit.out.pattern
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite><testcase id="tests_ok/test.1.hurl" name="tests_ok/test.1.hurl" time="~~~" /><testcase id="tests_ok/test.2.hurl" name="tests_ok/test.2.hurl" time="~~~" /></testsuite><testsuite><testcase id="tests_ok/test.3.hurl" name="tests_ok/test.3.hurl" time="~~~" /></testsuite></testsuites>
8 changes: 8 additions & 0 deletions integration/tests_ok/junit.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
if (Test-Path build/result.xml) {
Remove-Item build/result.xml
}
hurl --test --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
Get-Content build/result.xml -AsByteStream -Raw
6 changes: 6 additions & 0 deletions integration/tests_ok/junit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -Eeuo pipefail
rm -f build/result.xml
hurl --test --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
cat build/result.xml
4 changes: 2 additions & 2 deletions packages/hurl/src/report/junit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ pub fn write_report(filename: &str, testcases: &[Testcase]) -> Result<(), Error>
Ok(f) => f,
Err(e) => {
return Err(Error {
message: format!("Failed to produce junit report: {e:?}"),
message: format!("Failed to produce JUnit report: {e:?}"),
});
}
};
match report.write(file) {
Ok(_) => Ok(()),
Err(e) => Err(Error {
message: format!("Failed to produce junit report: {e:?}"),
message: format!("Failed to produce Junit report: {e:?}"),
}),
}
}
Expand Down

0 comments on commit 085abb0

Please sign in to comment.