@@ -23,12 +23,11 @@ export detect_ambiguities, detect_unbound_args
23
23
export GenericString, GenericSet, GenericDict, GenericArray, GenericOrder
24
24
export TestSetException
25
25
26
- import Distributed: myid
27
-
28
26
using Random
29
27
using Random: AbstractRNG, default_rng
30
28
using InteractiveUtils: gen_call_with_extracted_types
31
29
using Base: typesplit
30
+ using Serialization: Serialization
32
31
33
32
const DISPLAY_FAILED = (
34
33
:isequal ,
@@ -85,15 +84,19 @@ struct Pass <: Result
85
84
orig_expr
86
85
data
87
86
value
87
+ function Pass (test_type:: Symbol , orig_expr, data, thrown)
88
+ return new (test_type, orig_expr, data, thrown isa String ? " String" : thrown)
89
+ end
88
90
end
91
+
89
92
function Base. show (io:: IO , t:: Pass )
90
93
printstyled (io, " Test Passed" ; bold = true , color= :green )
91
94
if ! (t. orig_expr === nothing )
92
95
print (io, " \n Expression: " , t. orig_expr)
93
96
end
94
97
if t. test_type === :test_throws
95
98
# The correct type of exception was thrown
96
- print (io, " \n Thrown: " , typeof (t. value))
99
+ print (io, " \n Thrown: " , t . value isa String ? t . value : typeof (t. value))
97
100
elseif t. test_type === :test && t. data != = nothing
98
101
# The test was an expression, so display the term-by-term
99
102
# evaluated version as well
@@ -107,13 +110,21 @@ end
107
110
The test condition was false, i.e. the expression evaluated to false or
108
111
the correct exception was not thrown.
109
112
"""
110
- mutable struct Fail <: Result
113
+ struct Fail <: Result
111
114
test_type:: Symbol
112
- orig_expr
113
- data
114
- value
115
+ orig_expr:: String
116
+ data:: Union{Nothing, String}
117
+ value:: String
115
118
source:: LineNumberNode
119
+ function Fail (test_type:: Symbol , orig_expr, data, value, source:: LineNumberNode )
120
+ return new (test_type,
121
+ string (orig_expr),
122
+ data === nothing ? nothing : string (data),
123
+ string (isa (data, Type) ? typeof (value) : value),
124
+ source)
125
+ end
116
126
end
127
+
117
128
function Base. show (io:: IO , t:: Fail )
118
129
printstyled (io, " Test Failed" ; bold= true , color= Base. error_color ())
119
130
print (io, " at " )
@@ -122,7 +133,7 @@ function Base.show(io::IO, t::Fail)
122
133
if t. test_type === :test_throws_wrong
123
134
# An exception was thrown, but it was of the wrong type
124
135
print (io, " \n Expected: " , t. data)
125
- print (io, " \n Thrown: " , isa (t . data, Type) ? typeof (t . value) : t. value)
136
+ print (io, " \n Thrown: " , t. value)
126
137
elseif t. test_type === :test_throws_nothing
127
138
# An exception was expected, but no exception was thrown
128
139
print (io, " \n Expected: " , t. data)
@@ -142,10 +153,10 @@ it evaluated to something other than a [`Bool`](@ref).
142
153
In the case of `@test_broken` it is used to indicate that an
143
154
unexpected `Pass` `Result` occurred.
144
155
"""
145
- mutable struct Error <: Result
156
+ struct Error <: Result
146
157
test_type:: Symbol
147
- orig_expr
148
- value
158
+ orig_expr:: String
159
+ value:: String
149
160
backtrace:: String
150
161
source:: LineNumberNode
151
162
@@ -158,13 +169,14 @@ mutable struct Error <: Result
158
169
else
159
170
bt_str = " "
160
171
end
161
- new (test_type,
162
- orig_expr,
172
+ return new (test_type,
173
+ string ( orig_expr) ,
163
174
sprint (show, value, context = :limit => true ),
164
175
bt_str,
165
176
source)
166
177
end
167
178
end
179
+
168
180
function Base. show (io:: IO , t:: Error )
169
181
if t. test_type === :test_interrupted
170
182
printstyled (io, " Interrupted" , color= Base. error_color ())
@@ -201,10 +213,11 @@ end
201
213
The test condition is the expected (failed) result of a broken test,
202
214
or was explicitly skipped with `@test_skip`.
203
215
"""
204
- mutable struct Broken <: Result
216
+ struct Broken <: Result
205
217
test_type:: Symbol
206
218
orig_expr
207
219
end
220
+
208
221
function Base. show (io:: IO , t:: Broken )
209
222
printstyled (io, " Test Broken\n " ; bold= true , color= Base. warn_color ())
210
223
if t. test_type === :skipped && ! (t. orig_expr === nothing )
@@ -214,6 +227,25 @@ function Base.show(io::IO, t::Broken)
214
227
end
215
228
end
216
229
230
+ # Types that appear in TestSetException.errors_and_fails we convert eagerly into strings
231
+ # other types we convert lazily
232
+ function Serialization. serialize (s:: Serialization.AbstractSerializer , t:: Pass )
233
+ Serialization. serialize_type (s, typeof (t))
234
+ Serialization. serialize (s, t. test_type)
235
+ Serialization. serialize (s, t. orig_expr === nothing ? nothing : string (t. orig_expr))
236
+ Serialization. serialize (s, t. data === nothing ? nothing : string (t. data))
237
+ Serialization. serialize (s, string (t. value))
238
+ nothing
239
+ end
240
+
241
+ function Serialization. serialize (s:: Serialization.AbstractSerializer , t:: Broken )
242
+ Serialization. serialize_type (s, typeof (t))
243
+ Serialization. serialize (s, t. test_type)
244
+ Serialization. serialize (s, t. orig_expr === nothing ? nothing : string (t. orig_expr))
245
+ nothing
246
+ end
247
+
248
+
217
249
# -----------------------------------------------------------------------
218
250
219
251
abstract type ExecutionResult end
730
762
731
763
# Records nothing, and throws an error immediately whenever a Fail or
732
764
# Error occurs. Takes no action in the event of a Pass or Broken result
733
- record (ts:: FallbackTestSet , t:: Union{Pass,Broken} ) = t
734
- function record (ts:: FallbackTestSet , t:: Union{Fail,Error} )
765
+ record (ts:: FallbackTestSet , t:: Union{Pass, Broken} ) = t
766
+ function record (ts:: FallbackTestSet , t:: Union{Fail, Error} )
735
767
println (t)
736
768
throw (FallbackTestSetException (" There was an error during testing" ))
737
769
end
@@ -763,7 +795,7 @@ record(ts::DefaultTestSet, t::Pass) = (ts.n_passed += 1; t)
763
795
# For the other result types, immediately print the error message
764
796
# but do not terminate. Print a backtrace.
765
797
function record (ts:: DefaultTestSet , t:: Union{Fail, Error} )
766
- if myid () == 1
798
+ if TESTSET_PRINT_ENABLE[]
767
799
printstyled (ts. description, " : " , color= :white )
768
800
# don't print for interrupted tests
769
801
if ! (t isa Error) || t. test_type != = :test_interrupted
@@ -775,7 +807,6 @@ function record(ts::DefaultTestSet, t::Union{Fail, Error})
775
807
end
776
808
end
777
809
push! (ts. results, t)
778
- isa (t, Error) || backtrace ()
779
810
return t
780
811
end
781
812
@@ -788,9 +819,9 @@ record(ts::DefaultTestSet, t::AbstractTestSet) = push!(ts.results, t)
788
819
789
820
function print_test_errors (ts:: DefaultTestSet )
790
821
for t in ts. results
791
- if ( isa (t, Error) || isa (t, Fail)) && myid () == 1
822
+ if isa (t, Error) || isa (t, Fail)
792
823
println (" Error in testset $(ts. description) :" )
793
- Base . show (stdout , t)
824
+ show (t)
794
825
println ()
795
826
elseif isa (t, DefaultTestSet)
796
827
print_test_errors (t)
@@ -874,7 +905,7 @@ function finish(ts::DefaultTestSet)
874
905
if total != total_pass + total_broken
875
906
# Get all the error/failures and bring them along for the ride
876
907
efs = filter_errors (ts)
877
- throw (TestSetException (total_pass,total_fail,total_error, total_broken, efs))
908
+ throw (TestSetException (total_pass, total_fail, total_error, total_broken, efs))
878
909
end
879
910
880
911
# return the testset so it is returned from the @testset macro
0 commit comments