diff --git a/Project.toml b/Project.toml index 793759e..50c481e 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/to_xml.jl b/src/to_xml.jl index f163942..535c4a8 100644 --- a/src/to_xml.jl +++ b/src/to_xml.jl @@ -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) """ diff --git a/test/to_xml.jl b/test/to_xml.jl index dce88e9..11efea5 100644 --- a/test/to_xml.jl +++ b/test/to_xml.jl @@ -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