Skip to content

Commit fcf487f

Browse files
committed
Improve message for at-test_throw fails
1 parent c741432 commit fcf487f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

base/test.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ end
7171
function Base.show(io::IO, t::Fail)
7272
print_with_color(:red, io, "Test Failed\n")
7373
print(io, " Expression: ", t.orig_expr)
74-
if t.test_type == :test_throws
75-
# Either no exception, or wrong exception
74+
if t.test_type == :test_throws_wrong
75+
# An exception was thrown, but it was of the wrong type
7676
print(io, "\n Expected: ", t.expr)
7777
print(io, "\n Thrown: ", typeof(t.value))
78+
elseif t.test_type == :test_throws_nothing
79+
# An exception was expected, but no exception was thrown
80+
print(io, "\n Expected: ", t.expr)
81+
print(io, "\n No exception thrown")
7882
elseif !isa(t.expr, Expr)
7983
# Maybe just a constant, like false
8084
print(io, "\n Evaluated: ", t.expr)
@@ -212,14 +216,14 @@ function do_test_throws(predicate, orig_expr, bt, extype)
212216
try
213217
predicate()
214218
# If we hit this line, no exception was thrown. We treat
215-
# this as equivalent to the wrong exception being thrown.
216-
Fail(:test_throws, orig_expr, extype, nothing)
219+
# this a failure equivalent to the wrong exception being thrown.
220+
Fail(:test_throws_nothing, orig_expr, extype, nothing)
217221
catch err
218222
# Check the right type of exception was thrown
219223
if isa(err, extype)
220224
Pass(:test_throws, orig_expr, extype, err)
221225
else
222-
Fail(:test_throws, orig_expr, extype, err)
226+
Fail(:test_throws_wrong, orig_expr, extype, err)
223227
end
224228
end)
225229
end

0 commit comments

Comments
 (0)