Skip to content

Commit

Permalink
Add error element when error/failures happens, even if there are no l…
Browse files Browse the repository at this point in the history
…ogs available. (#144)

* Add error element when error/failures happens, even if there are no logs available. Needed for Datadog

* Update version
  • Loading branch information
rbvermaa authored Jan 29, 2024
1 parent 60d93f1 commit a3388ad
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ReTestItems"
uuid = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
version = "1.23.0"
version = "1.23.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
10 changes: 6 additions & 4 deletions src/junit_xml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,12 @@ function write_junit_xml(io, tc::JUnitTestCase)
write_counts(io, tc.counts)
write(io, ">")
write_dd_tags(io, tc)
if !isnothing(tc.logs)
write(io, "\n\t\t<error")
!isnothing(tc.error_message) && write(io, " message=", xml_markup(tc.error_message))
write(io, ">", xml_content(strip(String(tc.logs))))
if (tc.counts.failures + tc.counts.errors) > 0
err_msg = something(tc.error_message, "Test errored but no error message was captured.")
write(io, "\n\t\t<error message=", xml_markup(err_msg), ">")
if !isnothing(tc.logs)
write(io, xml_content(strip(String(tc.logs))))
end
write(io, "\n\t\t</error>")
end
write(io, "\n\t</testcase>")
Expand Down
48 changes: 48 additions & 0 deletions test/junit_xml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,52 @@ end
end
end

@testset "Manual JUnitTestSuite/JUnitTestCase with error no logs" begin
using ReTestItems: JUnitTestCase, JUnitTestSuite
using Dates: datetime2unix, DateTime

function get_test_suite(suite_name, test_name)
ts = @testset "$test_name" begin
# would rather make this false, but failing @test makes the ReTestItems test fail as well
@test true
end
# Make the test time deterministic to make testing report output easier
ts.time_start = datetime2unix(DateTime(2023, 01, 15, 16, 42))
ts.time_end = datetime2unix(DateTime(2023, 01, 15, 16, 42, 30))

# should be able to construct a TestCase from a TestSet
tc = JUnitTestCase(ts)
@test tc isa JUnitTestCase

# once wrapped in a TestSuite, this should have enough info to write out a report
suite = JUnitTestSuite(suite_name)
junit_record!(suite, tc)
@test suite isa JUnitTestSuite
return suite
end
suite = get_test_suite("manual", "test")
# pretend there is a failure
suite.counts.failures = 1
suite.testcases[1].counts.failures = 1

mktemp() do path, io
write_junit_file(path, suite)
report_string = read(io, String)
expected = """
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="manual" timestamp="2023-01-15T16:42:00.0" time="30.0" tests="1" skipped="0" failures="1" errors="0">
\t<testcase name="test" timestamp="2023-01-15T16:42:00.0" time="30.0" tests="1" skipped="0" failures="1" errors="0">
\t\t<properties>
\t\t<property name=\"dd_tags[test.id]\" value=\"$(repr(hash("test")))\"></property>
\t\t</properties>
\t\t<error message="Test errored but no error message was captured.">
\t\t</error>
\t</testcase>
</testsuite>
"""
# leading/trailing whitespace isn't important
@test strip(report_string) == strip(expected)
end
end

end # junit_xml.jl testset

2 comments on commit a3388ad

@nickrobinson251
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/99746

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.23.1 -m "<description of version>" a3388ad442ac58dac395424ebcdf849939ac6515
git push origin v1.23.1

Please sign in to comment.