Skip to content

Commit

Permalink
Improve testing of Base.Test
Browse files Browse the repository at this point in the history
  • Loading branch information
IainNZ committed Nov 28, 2015
1 parent 4d0b1ac commit 9c682a0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
9 changes: 4 additions & 5 deletions base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ end
function Base.show(io::IO, t::Pass)
print_with_color(:green, io, "Test Passed\n")
print(io, " Expression: ", t.orig_expr)
if !isa(t.expr, Expr)
if t.test_type == :test_throws
# The correct type of exception was thrown
print(io, "\n Thrown: ", typeof(t.value))
elseif !isa(t.expr, Expr)
# Maybe just a constant, like true
print(io, "\n Evaluated: ", t.expr)
elseif t.test_type == :test && t.expr.head == :comparison
# The test was an expression, so display the term-by-term
# evaluated version as well
print(io, "\n Evaluated: ", t.expr)
elseif t.test_type == :test_throws
# The correct type of exception was thrown
print(io, "\n Thrown: ", typeof(t.value))
end
end

Expand Down Expand Up @@ -288,7 +288,6 @@ record(ts::FallbackTestSet, t::Pass) = t
function record(ts::FallbackTestSet, t::Union{Fail,Error})
println(t)
error("There was an error during testing")
t
end
# We don't need to do anything as we don't record anything
finish(ts::FallbackTestSet) = ts
Expand Down
32 changes: 28 additions & 4 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,42 @@ a[1,1,1,1,1] = 10

@test rand() != rand()

sprint(show, @test true)
sprint(show, @test 10 == 2*5)
sprint(show, @test !false)
# Test printing of result types
# Pass - constant
@test contains(sprint(show, @test true), "Expression: true")
# Pass - expression
@test contains(sprint(show, @test 10 == 2*5), "Evaluated: 10 == 10")
@test contains(sprint(show, @test !false), "Expression: !false")
# Pass - exception
@test contains(sprint(show, @test_throws ErrorException error()),
"Thrown: ErrorException")

# Test printing of a TestSetException
tse_str = sprint(show, Test.TestSetException(1,2,3))
@test contains(tse_str, "1 passed")
@test contains(tse_str, "2 failed")
@test contains(tse_str, "3 errored")

@test Test.finish(Test.FallbackTestSet()) != nothing

OLD_STDOUT = STDOUT
catch_out = IOStream("")
rd, wr = redirect_stdout()

# Check that the fallback test set throws immediately
@test_throws ErrorException (@test 1 == 2)

@testset "no errors" begin
@test true
@test 1 == 1
end

# Test entirely empty test set
@testset "outer" begin
@testset "inner" begin
end
end

try

@testset "outer" begin
Expand All @@ -54,6 +77,7 @@ try
@test 4 == 4
@test_throws ErrorException 1+1
@test_throws ErrorException error()
@test_throws RemoteException error()
@testset "errrrr" begin
@test "not bool"
@test error()
Expand Down Expand Up @@ -95,7 +119,7 @@ catch ex

@test isa(ex, Test.TestSetException)
@test ex.pass == 24
@test ex.fail == 5
@test ex.fail == 6
@test ex.error == 6
end

Expand Down

0 comments on commit 9c682a0

Please sign in to comment.