Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Help wanted: switch Base.Test to use testsets everywhere #17165

Closed
wants to merge 9 commits into from
57 changes: 36 additions & 21 deletions base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,32 +421,34 @@ record(ts::DefaultTestSet, t::Union{Pass,Broken}) = (push!(ts.results, t); t)
# For the other result types, immediately print the error message
# but do not terminate. Print a backtrace.
function record(ts::DefaultTestSet, t::Union{Fail, Error})
print_with_color(:white, ts.description, ": ")
print(t)
# don't print the backtrace for Errors because it gets printed in the show
# method
isa(t, Error) || Base.show_backtrace(STDOUT, backtrace())
println()
if myid() == 1
print_with_color(:white, ts.description, ": ")
print(t)
# don't print the backtrace for Errors because it gets printed in the show
# method
isa(t, Error) || Base.show_backtrace(STDERR, backtrace())
println()
end
push!(ts.results, t)
t
t, isa(t, Error) || backtrace()
end

# When a DefaultTestSet finishes, it records itself to its parent
# testset, if there is one. This allows for recursive printing of
# the results at the end of the tests
record(ts::DefaultTestSet, t::AbstractTestSet) = push!(ts.results, t)

# Called at the end of a @testset, behaviour depends on whether
# this is a child of another testset, or the "root" testset
function finish(ts::DefaultTestSet)
# If we are a nested test set, do not print a full summary
# now - let the parent test set do the printing
if get_testset_depth() != 0
# Attach this test set to the parent test set
parent_ts = get_testset()
record(parent_ts, ts)
return
function print_test_errors(ts::DefaultTestSet)
for t in ts.results
if (isa(t, Error) || isa(t, Fail)) && myid() == 1
Base.show(STDERR,t)
elseif isa(t, DefaultTestSet)
print_test_errors(t)
end
end
end

function print_test_results(ts::DefaultTestSet, depth_pad=0)
# Calculate the overall number for each type so each of
# the test result types are aligned
passes, fails, errors, broken, c_passes, c_fails, c_errors, c_broken = get_test_counts(ts)
Expand Down Expand Up @@ -489,11 +491,25 @@ function finish(ts::DefaultTestSet)
end
println()
# Recursively print a summary at every level
print_counts(ts, 0, align, pass_width, fail_width, error_width, broken_width, total_width)
print_counts(ts, depth_pad, align, pass_width, fail_width, error_width, broken_width, total_width)
end

# Called at the end of a @testset, behaviour depends on whether
# this is a child of another testset, or the "root" testset
function finish(ts::DefaultTestSet)
# If we are a nested test set, do not print a full summary
# now - let the parent test set do the printing
if get_testset_depth() != 0
# Attach this test set to the parent test set
parent_ts = get_testset()
record(parent_ts, ts)
return
end
# Finally throw an error as we are the outermost test set
if total != total_pass
#print_test_results(ts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats happening here now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed things so that now only the King of the Nodes outputs anything. Otherwise we were getting horrendous looking spam from each worker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So am I reading this right: if I'm just a general package, and I'm using Base.Test, there will be no output from test sets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can dump it explicitly with Base.Test.print_test_results(Base.Test.get_testset()) but yeah, it would be silent unless things fail. There's a reason I put WIP on this. I wish I could put bold in titles: WIP. Ideally I think we'd have a verbose/quiet flag you could pass depending if you want output or not. It would be good to just let packages use test/runtests.jl themselves, rather than hacking their own weird fake parallel testing together like happens now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. I was thinking that the solution for the Base testing setting would be making a different kind of test set, or as you say, maybe DefaultTestSet can have an option.

#=if total != total_pass
throw(TestSetException(total_pass,total_fail,total_error, total_broken))
end
end=#

# return the testset so it is returned from the @testset macro
ts
Expand Down Expand Up @@ -547,7 +563,6 @@ function print_counts(ts::DefaultTestSet, depth, align,
# through any child test sets
passes, fails, errors, broken, c_passes, c_fails, c_errors, c_broken = get_test_counts(ts)
subtotal = passes + fails + errors + broken + c_passes + c_fails + c_errors + c_broken

# Print test set header, with an alignment that ensures all
# the test results appear above each other
print(rpad(string(lpad(" ",depth), ts.description), align, " "), " | ")
Expand Down
2 changes: 0 additions & 2 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1788,8 +1788,6 @@ for op in (:.+, :.*, :.÷, :.%, :.<<, :.>>, :.-, :./, :.\, :.//, :.^)
@eval @test typeof($(op)(A,A)) == Matrix{Foo}
end

end

# Test that concatenations of dense matrices/vectors yield dense matrices/vectors
let
N = 4
Expand Down
4 changes: 3 additions & 1 deletion test/base64.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

@testset "base64" begin
const inputText = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."
const encodedMaxLine76 =
"""TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
Expand Down Expand Up @@ -41,3 +41,5 @@ ipipe = Base64DecodePipe(IOBuffer(string(encodedMaxLine76[1:end-2],"==")))
# Test incorrect format
ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76[1:end-3]))
@test_throws ArgumentError readstring(ipipe)

end
1 change: 0 additions & 1 deletion test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ end
@test big(5)^true == big(5)
@test big(5)^false == one(BigInt)


# operations that when applied to Int64 give Float64, should give BigFloat
@test typeof(exp(a)) == BigFloat
@test typeof(exp2(a)) == BigFloat
Expand Down
2 changes: 0 additions & 2 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

using Base.Test

tc{N}(r1::NTuple{N}, r2::NTuple{N}) = all(x->tc(x...), [zip(r1,r2)...])
tc{N}(r1::BitArray{N}, r2::Union{BitArray{N},Array{Bool,N}}) = true
tc{T}(r1::T, r2::T) = true
Expand Down
1 change: 1 addition & 0 deletions test/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,4 @@ for elty in [Float32, Float64, Complex64, Complex128]
@test_throws DimensionMismatch BLAS.syrk!('L','N',one(elty),eye(elty,5),one(elty),eye(elty,6))
end
end

1 change: 0 additions & 1 deletion test/broadcast.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

module TestBroadcastInternals

using Base.Broadcast: broadcast_indices, check_broadcast_indices,
check_broadcast_shape, newindex, _bcs, _bcsm
using Base: Test, OneTo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't using Base.Test redundant with using Base: Test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derp, yes. Thanks!

Expand Down
2 changes: 0 additions & 2 deletions test/char.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

#tests for /base/char.jl

@test typemin(Char) == Char(0)
@test ndims(Char) == 0
@test getindex('a', 1) == 'a'
Expand Down
2 changes: 0 additions & 2 deletions test/checked.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

# Checked integer arithmetic

import Base: checked_abs, checked_neg, checked_add, checked_sub, checked_mul,
checked_div, checked_rem, checked_fld, checked_mod, checked_cld

Expand Down
5 changes: 4 additions & 1 deletion test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ function choosetests(choices = [])
net_required_for = ["socket", "parallel", "libgit2"]
net_on = true
try
getipaddr()
ipa = getipaddr()
if ipa == ip"127.0.0.1"
net_on = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think net_on should only be false if getipaddr actually fails

end
catch
warn("Networking unavailable: Skipping tests [" * join(net_required_for, ", ") * "]")
net_on = false
Expand Down
4 changes: 4 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

@testset "cmdlineargs" begin

catcmd = `cat`
if is_windows()
try # use busybox-w32 on windows
Expand Down Expand Up @@ -339,3 +341,5 @@ for precomp in ("yes", "no")
@test length(lno.captures) == 1
@test parse(Int, lno.captures[1]) > 0
end

end
39 changes: 21 additions & 18 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ let
@test a==1 && b==2
end

# issue #1876
@testset "issue #1876" begin
let
tst = 1
m1(i) = (tst+=1;i-1)
Expand All @@ -1126,6 +1126,7 @@ let
X[r...] *= 2
@test X == [1,4,6,4]
end
end

# issue #1632
let
Expand Down Expand Up @@ -2301,24 +2302,26 @@ g9535() = (f9535(),f9535())

# weak references
type Obj; x; end
@noinline function mk_wr(r, wr)
x = Obj(1)
push!(r, x)
push!(wr, WeakRef(x))
end
test_wr(r,wr) = @test r[1] == wr[1].value
function test_wr()
ref = []
wref = []
mk_wr(ref, wref)
test_wr(ref, wref)
gc()
test_wr(ref, wref)
pop!(ref)
gc()
@test wref[1].value === nothing
@testset "weak references" begin
@noinline function mk_wr(r, wr)
x = Obj(1)
push!(r, x)
push!(wr, WeakRef(x))
end
test_wr(r,wr) = @test r[1] == wr[1].value
function test_wr()
ref = []
wref = []
mk_wr(ref, wref)
test_wr(ref, wref)
gc()
test_wr(ref, wref)
pop!(ref)
gc()
@test_broken wref[1].value == nothing
end
test_wr()
end
test_wr()

# issue #9947
function f9947()
Expand Down
4 changes: 2 additions & 2 deletions test/dates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module TestDates

using Base.Dates
using Base.Test

@testset "dates" begin
include("dates/types.jl")
include("dates/periods.jl")
include("dates/accessors.jl")
Expand All @@ -15,5 +15,5 @@ include("dates/ranges.jl")
include("dates/adjusters.jl")
include("dates/rounding.jl")
include("dates/io.jl")

end
end
1 change: 1 addition & 0 deletions test/dates/adjusters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,4 @@ end) == 251
end
return sum == 15
end) == 15 # On average, there's one of those months every year

1 change: 1 addition & 0 deletions test/dates/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,4 @@ t4 = [DateTime(2009,1,1,0,0,1), DateTime(2009,1,2,0,1), DateTime(2009,1,3,1)]
@test t4 - t3 == [Millisecond(1000), Millisecond(60000), Millisecond(3600000)]
@test (Date(2009,1,1):Week(1):Date(2009,1,21)) - (Date(2009,1,1):Day(1):Date(2009,1,3)) == [0d, 6d, 12d]
@test (DateTime(2009,1,1,1,1,1):Second(1):DateTime(2009,1,1,1,1,3)) - (DateTime(2009,1,1,1,1):Second(1):DateTime(2009,1,1,1,1,2)) == [1s, 1s, 1s]

1 change: 1 addition & 0 deletions test/dates/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ b = Dates.Date(2000)
@test convert(Date,730120) == b
@test convert(Date,730120.0) == b
@test convert(Date,Int32(730120)) == b

1 change: 1 addition & 0 deletions test/dates/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,4 @@ cpa = [1y+1s 1m+1s 1w+1s 1d+1s; 1h+1s 1mi+1s 2m+1s 1s+1ms]

@test [1y+1s 1m+1s; 1w+1s 1d+1s] + [1y+1h 1y+1mi; 1y+1s 1y+1ms] == [2y+1h+1s 1y+1m+1mi+1s; 1y+1w+2s 1y+1d+1s+1ms]
@test [1y+1s 1m+1s; 1w+1s 1d+1s] - [1y+1h 1y+1mi; 1y+1s 1y+1ms] == [1s-1h 1m+1s-1y-1mi; 1w-1y 1d+1s-1y-1ms]

1 change: 1 addition & 0 deletions test/dates/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,4 @@ end
@test Dates.dayofquarter(Dates.DateTime(2014,6,30)) == 91
@test Dates.dayofquarter(Dates.DateTime(2014,9,30)) == 92
@test Dates.dayofquarter(Dates.DateTime(2014,12,31)) == 92

4 changes: 4 additions & 0 deletions test/dates/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ testlengths(100000)
# Custom definition to override default step of DateTime ranges
@test typeof(step(Dates.DateTime(2000):Dates.DateTime(2001))) == Dates.Day

a = Dates.Date(2013,1,1)
b = Dates.Date(2013,2,1)
d = Dates.Date(2020,1,1)
@test length(a:Dates.Year(1):d) == 8
@test first(a:Dates.Year(1):d) == a
Expand All @@ -433,6 +435,8 @@ d = Dates.Date(2020,1,1)
@test first(a:Dates.Day(365):d) == a
@test last(a:Dates.Day(365):d) == Dates.Date(2019,12,31)

a = Dates.Date(2013,1,1)
b = Dates.Date(2013,2,1)
@test length(a:Dates.Year(1):Dates.Date(2020,2,1)) == 8
@test length(a:Dates.Year(1):Dates.Date(2020,6,1)) == 8
@test length(a:Dates.Year(1):Dates.Date(2020,11,1)) == 8
Expand Down
1 change: 1 addition & 0 deletions test/dates/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,4 @@ ms = Dates.Millisecond(1)

@test isfinite(Dates.Date)
@test isfinite(Dates.DateTime)

4 changes: 1 addition & 3 deletions test/enums.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

module TestEnums

using Base.Test

@test_throws MethodError convert(Enum, 1.0)

@test_throws ArgumentError eval(:(@enum Foo))
Expand Down Expand Up @@ -168,4 +166,4 @@ let b = IOBuffer()
@test deserialize(b) === apple
end

end # module
end
1 change: 0 additions & 1 deletion test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ if !zmq_found
end

include(joinpath(dir, "clustermanager/0mq/ZMQCM.jl"))

2 changes: 0 additions & 2 deletions test/fastmath.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

# fast math

# check expansions

@test macroexpand(:(@fastmath 1+2)) == :(Base.FastMath.add_fast(1,2))
Expand Down
1 change: 0 additions & 1 deletion test/fft.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

# fft
a = rand(8) + im*rand(8)
@test norm(ifft(fft(a)) - a) < 1e-8
@test norm(ifft(fft(a,1),1) - a) < 1e-8
Expand Down
3 changes: 1 addition & 2 deletions test/float16.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

using Base.Test

f = Float16(2.)
g = Float16(1.)

Expand Down Expand Up @@ -146,3 +144,4 @@ end

# issue #17148
@test rem(Float16(1.2), Float16(one(1.2))) == 0.20019531f0

1 change: 1 addition & 0 deletions test/floatapprox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@
@test [0,1] ≈ [1e-9, 1]
@test [0,Inf] ≈ [0,Inf]
@test [0,Inf] ≉ [0,-Inf]

6 changes: 2 additions & 4 deletions test/floatfuncs.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

using Base.Test

# test the basic floating point functions

@testset "floatfuncs" begin
# flipsign

for elty in (Float32,Float64)
Expand Down Expand Up @@ -68,3 +65,4 @@ for elty in (Float32,Float64)
@test round(elty2,A) == fill(round(elty2,x),(10,10,10))
end
end
end
3 changes: 1 addition & 2 deletions test/goto.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

# Basic goto tests

function goto_test1()
@goto a
return false
Expand Down Expand Up @@ -125,3 +123,4 @@ function f15561()
@label crater
end
@test f15561() === nothing

1 change: 1 addition & 0 deletions test/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1751,3 +1751,4 @@ len,point,neg = Grisu.grisu(1.0, Grisu.FIXED, 0, buffer)
@test 1 >= len-1
@test "1" == unsafe_string(pointer(buffer))
@test !neg

Loading