Skip to content

Commit

Permalink
Record errors before logs in XML reports (#88)
Browse files Browse the repository at this point in the history
* Record errors before logs in XML reports

* Bump version

* Update docstring
  • Loading branch information
nickrobinson251 authored Jun 23, 2023
1 parent 0859990 commit 1949ab3
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 507 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.9.0"
version = "1.10.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 1 addition & 1 deletion src/junit_xml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function JUnitTestCase(ti::TestItem, run_number::Int)
message = nothing
else
io = IOBuffer()
print_errors_and_captured_logs(io, ti, run_number)
print_errors_and_captured_logs(io, ti, run_number; errors_first=true)
logs = take!(io)
message = _error_message(ts, ti)
end
Expand Down
22 changes: 16 additions & 6 deletions src/log_capture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ _mem_watermark() = string(
)

"""
print_errors_and_captured_logs(ti::TestItem, run_number::Int; logs=:batched)
print_errors_and_captured_logs(ti::TestItem, run_number::Int; logs=:batched, errors_first=false)
When a testitem doesn't succeed, we print the corresponding error/failure reports
from the testset and any logs that we captured while the testitem was eval()'d.
Expand All @@ -156,20 +156,30 @@ For `:eager` mode of `logs` we don't print any logs as they bypass log capture.
means we print logs even for passing test items, whereas `:issues` means we are only printing
captured logs if there were any errors or failures.
If `errors_first=true`, then the test errors are printed first and the logs second.
The default `errors_first=false`, prints the logs firsts.
Nothing is printed when no logs were captures and no failures or errors occured.
"""
print_errors_and_captured_logs(ti::TestItem, run_number::Int; logs=:batched) =
print_errors_and_captured_logs(DEFAULT_STDOUT[], ti, run_number; logs)
function print_errors_and_captured_logs(io, ti::TestItem, run_number::Int; logs=:batched)
print_errors_and_captured_logs(ti::TestItem, run_number::Int; kwargs...) =
print_errors_and_captured_logs(DEFAULT_STDOUT[], ti, run_number; kwargs...)
function print_errors_and_captured_logs(
io, ti::TestItem, run_number::Int; logs=:batched, errors_first::Bool=false,
)
ts = ti.testsets[run_number]
has_errors = ts.anynonpass
has_logs = _has_logs(ti, run_number) || any(_has_logs, ti.testsetups)
if has_errors || logs == :batched
report_iob = IOContext(IOBuffer(), :color=>Base.get_have_color())
println(report_iob)
# in :eager mode, the logs were already printed
logs != :eager && _print_captured_logs(report_iob, ti, run_number)
has_errors && _print_test_errors(report_iob, ts, _on_worker(ti))
if errors_first
has_errors && _print_test_errors(report_iob, ts, _on_worker(ti))
logs != :eager && _print_captured_logs(report_iob, ti, run_number)
else
logs != :eager && _print_captured_logs(report_iob, ti, run_number)
has_errors && _print_test_errors(report_iob, ts, _on_worker(ti))
end
if has_errors || has_logs
# a newline to visually separate the report for the current test item
println(report_iob)
Expand Down
170 changes: 71 additions & 99 deletions test/references/junit_xml_test_report.xml

Large diffs are not rendered by default.

314 changes: 129 additions & 185 deletions test/references/junit_xml_test_report_retries.xml

Large diffs are not rendered by default.

190 changes: 95 additions & 95 deletions test/references/retry_tests_report_0worker.xml

Large diffs are not rendered by default.

240 changes: 120 additions & 120 deletions test/references/retry_tests_report_1worker.xml

Large diffs are not rendered by default.

2 comments on commit 1949ab3

@nickrobinson251
Copy link
Collaborator Author

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/86128

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.10.0 -m "<description of version>" 1949ab3f086a7aee972c1d96252fe4cda5c84084
git push origin v1.10.0

Please sign in to comment.