Skip to content

Commit

Permalink
Correct @test using chained comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Jun 9, 2017
1 parent 50fa8d5 commit f2805a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 1 addition & 4 deletions base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,7 @@ function get_test_result(ex)
$(esc(ex.args[2])), $(esc(ex.args[1])), $(esc(ex.args[3])))))
elseif isa(ex, Expr) && ex.head == :comparison
# pass all terms of the comparison to `eval_comparison`, as an Expr
terms = ex.args
for i = 1:length(terms)
terms[i] = esc(terms[i])
end
terms = [esc(arg) for arg in ex.args]
testret = :(eval_comparison(Expr(:comparison, $(terms...))))
else
testret = :(Returned($(esc(ex)), nothing))
Expand Down
7 changes: 5 additions & 2 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ fails = @testset NoThrowTestSet begin
@test_throws OverflowError 1 + 1
# Fail - comparison
@test 1+1 == 2+2
# Fail - chained comparison
@test 1+0 == 2+0 == 3+0
# Error - unexpected pass
@test_broken true
end
for i in 1:3
for i in 1:length(fails) - 1
@test isa(fails[i], Base.Test.Fail)
end
@test contains(sprint(show, fails[1]), "Thrown: ErrorException")
@test contains(sprint(show, fails[2]), "No exception thrown")
@test contains(sprint(show, fails[3]), "Evaluated: 2 == 4")
@test contains(sprint(show, fails[4]), "Unexpected Pass")
@test contains(sprint(show, fails[4]), "Evaluated: 1 == 2 == 3")
@test contains(sprint(show, fails[5]), "Unexpected Pass")

# Test printing of a TestSetException
tse_str = sprint(show, Test.TestSetException(1,2,3,4,Vector{Union{Base.Test.Error, Base.Test.Fail}}()))
Expand Down

0 comments on commit f2805a5

Please sign in to comment.