Skip to content

Commit

Permalink
Add information to passing tests (#25483)
Browse files Browse the repository at this point in the history
Remove printing of detailed Pass information, not used before this change
  • Loading branch information
mmiller-max committed Aug 23, 2020
1 parent e3696f9 commit 0492c37
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
12 changes: 3 additions & 9 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,13 @@ struct Pass <: Result
orig_expr
data
value
source::LineNumberNode
end
function Base.show(io::IO, t::Pass)
printstyled(io, "Test Passed"; bold = true, color=:green)
if !(t.orig_expr === nothing)
print(io, "\n Expression: ", t.orig_expr)
end
if t.test_type === :test_throws
# The correct type of exception was thrown
print(io, "\n Thrown: ", typeof(t.value))
elseif t.test_type === :test && t.data !== nothing
# The test was an expression, so display the term-by-term
# evaluated version as well
print(io, "\n Evaluated: ", t.data)
end
end

Expand Down Expand Up @@ -505,7 +499,7 @@ function do_test(result::ExecutionResult, orig_expr)
value = result.value
testres = if isa(value, Bool)
# a true value Passes
value ? Pass(:test, nothing, nothing, value) :
value ? Pass(:test, orig_expr, result.data, value, result.source) :
Fail(:test, orig_expr, result.data, value, result.source)
else
# If the result is non-Boolean, this counts as an Error
Expand Down Expand Up @@ -590,7 +584,7 @@ function do_test_throws(result::ExecutionResult, orig_expr, extype)
end
end
if success
testres = Pass(:test_throws, nothing, nothing, exc)
testres = Pass(:test_throws, orig_expr, extype, exc, result.source)
else
testres = Fail(:test_throws_wrong, orig_expr, extype, exc, result.source)
end
Expand Down
28 changes: 27 additions & 1 deletion stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ end

let retval_tests = @testset NoThrowTestSet begin
ts = Test.DefaultTestSet("Mock for testing retval of record(::DefaultTestSet, ::T <: Result) methods")
pass_mock = Test.Pass(:test, 1, 2, LineNumberNode(0, "A Pass Mock"))
pass_mock = Test.Pass(:test, 1, 2, 3, LineNumberNode(0, "A Pass Mock"))
@test Test.record(ts, pass_mock) isa Test.Pass
error_mock = Test.Error(:test, 1, 2, 3, LineNumberNode(0, "An Error Mock"))
@test Test.record(ts, error_mock) isa Test.Error
Expand Down Expand Up @@ -946,3 +946,29 @@ end
end
@test ok
end

# Issue 25483
mutable struct PassInformationTestSet <: Test.AbstractTestSet
results::Vector
PassInformationTestSet(desc) = new([])
end
Test.record(ts::PassInformationTestSet, t::Test.Result) = (push!(ts.results, t); t)
Test.finish(ts::PassInformationTestSet) = ts
@testset "Information in Pass result (Issue 25483)" begin
ts = @testset PassInformationTestSet begin
@test 1 == 1
@test_throws ErrorException throw(ErrorException("Msg"))
end
test_line_number = (@__LINE__) - 3
test_throws_line_number = (@__LINE__) - 3
@test ts.results[1].test_type == :test
@test ts.results[1].orig_expr == :(1 == 1)
@test ts.results[1].data == Expr(:comparison, 1, :(==), 1)
@test ts.results[1].value == true
@test ts.results[1].source == LineNumberNode(test_line_number, @__FILE__)
@test ts.results[2].test_type == :test_throws
@test ts.results[2].orig_expr == :(throw(ErrorException("Msg")))
@test ts.results[2].data == ErrorException
@test ts.results[2].value == ErrorException("Msg")
@test ts.results[2].source == LineNumberNode(test_throws_line_number, @__FILE__)
end

0 comments on commit 0492c37

Please sign in to comment.