@@ -9,7 +9,7 @@ const TEST_RESULT_COLLAPSE_THRESHOLD = 2
99const MAX_REPORTED_FAILURES_PER_TESTSET = 5
1010
1111"""
12- tojson(output ::String, ts::ReportingTestSet)
12+ tojson(general_output ::String, ts::ReportingTestSet)
1313
1414Takes user output and a ReportingTestSet and converts it to a JSON string as
1515expected by the interface.
@@ -55,7 +55,7 @@ For more information, check the reference:
5555https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md
5656"""
5757# TODO : Capture output per-test
58- function tojson (output :: String , ts:: ReportingTestSet )
58+ function tojson (general_output :: String , ts:: ReportingTestSet )
5959 if length (ts. results) == 1 && ts. results[1 ] isa Test. Error
6060 # There has been a syntax error or similar and no tests have run.
6161 # Otherwise ts.results[1] will be a ReportingTestSet.
@@ -82,22 +82,31 @@ function tojson(output::String, ts::ReportingTestSet)
8282 # Flag set in push_result!(), used for top-level status property
8383 any_failed = false
8484 # All stdout from the top level test set, used for all tests.
85- output = truncate_output (output)
85+ general_output = truncate_output (general_output)
86+
87+ unescape (e) = e
88+ unescape (e:: String ) = startswith (e, " \$ (" ) ? unescape (Meta. parse (e[3 : end - 1 ])) : e
89+ unescape (e:: Expr ) = e. head == :escape ? unescape (e. args[1 ]) : e
8690
8791 function test_code (result:: Test.Result )
92+ if haskey (test_outputs, result)
93+ expr = test_outputs[result]. expr
94+ else
95+ expr = unescape (result. orig_expr)
96+ end
8897 if result isa Test. Pass && result. test_type == :test_throws
89- " @test_throws $(result. data) $(result . orig_expr ) "
98+ " @test_throws $(result. data) $(expr ) "
9099 elseif result isa Test. Fail && startswith (string (result. test_type), " test_throws" )
91- " @test_throws $(result. data) $(result . orig_expr ) "
100+ " @test_throws $(result. data) $(expr ) "
92101 elseif result isa Test. LogTestFailure
93- " @test_logs $(join (result. patterns, ' ' )) $(result . orig_expr ) "
102+ " @test_logs $(join (result. patterns, ' ' )) $(expr ) "
94103 elseif result isa Test. Error && result. test_type == :test_unbroken
95- " @test_broken $(result . orig_expr ) "
104+ " @test_broken $(expr ) "
96105 elseif result isa Test. Broken
97106 macro_name = result. test_type === :skipped ? " @test_skip " : " @test_broken "
98- " $macro_name $(result . orig_expr ) "
107+ " $macro_name $(expr ) "
99108 else
100- " @test $(result . orig_expr ) "
109+ " @test $(expr ) "
101110 end
102111 end
103112
@@ -133,6 +142,12 @@ function tojson(output::String, ts::ReportingTestSet)
133142
134143 any_failed = any_failed || status in (" fail" , " error" )
135144
145+ if haskey (test_outputs, result)
146+ output = truncate_output (test_outputs[result]. output)
147+ else
148+ output = general_output
149+ end
150+
136151 return push! (tests, Dict (filter ( ((k, v),) -> ! isnothing (v), (
137152 " name" => name,
138153 " status" => status,
0 commit comments