Skip to content
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "TestReports"
uuid = "dcd651b4-b50a-5b6b-8f22-87e9f253a252"
version = "1.3.0"
version = "1.4.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
14 changes: 14 additions & 0 deletions src/to_xml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ function to_xml(v::Error)
x_testcase, ntest, 0, 1 # Increment number of errors by 1
end

function to_xml(v::Result)
# Generic fallback, that hopefully works for any user-defined failure types.
# if not they need to implement this in an extension package
if occursin("Fail", string(typeof(v)))
# This works for TestLogFailure and JETTestFailure
# and is based on:
# https://github.com/aviatesk/JET.jl/blob/8f2ecffc3bef6c556b2617458f031d29f1a00a4b/src/JETBase.jl#L1439-L1440
# https://github.com/JuliaLang/julia/blob/5d3ab49433e14fae9e64f1a5001a06cbf53fa7f0/stdlib/Test/src/logging.jl#L169-L170
return to_xml(Fail(:test, v.orig_expr, v, nothing, v.source))
else
throw(MethodError(to_xml, (v,)))
end
end

to_xml(v::ReportingResult) = to_xml(v.result)

"""
Expand Down
11 changes: 11 additions & 0 deletions test/to_xml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ end
result = Error(:test_nonbool, :orig_expr, nothing, nothing, LineNumberNode(1))
node, _, _, _ = TestReports.to_xml(result)
@test node.name == "testcase"


struct WeirdFailure <: Result
orig_expr
source::LineNumberNode
some_nonsense
end
result = WeirdFailure(:orig_expr, LineNumberNode(1), 3.1415)
node, _, _, _ = TestReports.to_xml(result)
@test node.name == "testcase"

end
Loading