Skip to content

Commit b47150e

Browse files
committed
Add testing of Test.Fail printing
1 parent 9f4c001 commit b47150e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

test/test.jl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ a[1,1,1,1,1] = 10
1818

1919
@test rand() != rand()
2020

21-
# Test printing of result types
21+
# Test printing of Pass results
2222
# Pass - constant
2323
@test contains(sprint(show, @test true), "Expression: true")
2424
# Pass - expression
@@ -28,6 +28,31 @@ a[1,1,1,1,1] = 10
2828
@test contains(sprint(show, @test_throws ErrorException error()),
2929
"Thrown: ErrorException")
3030

31+
# Test printing of Fail results
32+
type NoThrowTestSet <: Base.Test.AbstractTestSet
33+
results::Vector
34+
NoThrowTestSet(desc) = new([])
35+
end
36+
Base.Test.record(ts::NoThrowTestSet, t::Base.Test.Result) = (push!(ts.results, t); t)
37+
Base.Test.finish(ts::NoThrowTestSet) = ts.results
38+
fails = @testset NoThrowTestSet begin
39+
# Fail - wrong exception
40+
@test_throws OverflowError error()
41+
# Fail - no exception
42+
@test_throws OverflowError 1 + 1
43+
# Fail - const
44+
@test false
45+
# Fail - comparison
46+
@test 1+1 == 2+2
47+
end
48+
for i in 1:4
49+
@test isa(fails[i], Base.Test.Fail)
50+
end
51+
@test contains(sprint(show, fails[1]), "Thrown: ErrorException")
52+
@test contains(sprint(show, fails[2]), "No exception thrown")
53+
@test contains(sprint(show, fails[3]), "Evaluated: false")
54+
@test contains(sprint(show, fails[4]), "Evaluated: 2 == 4")
55+
3156
# Test printing of a TestSetException
3257
tse_str = sprint(show, Test.TestSetException(1,2,3))
3358
@test contains(tse_str, "1 passed")

0 commit comments

Comments
 (0)