diff --git a/test/Serialization/basic_types.jl b/test/Serialization/basic_types.jl index f36fa320c9c4..349d3b069ceb 100644 --- a/test/Serialization/basic_types.jl +++ b/test/Serialization/basic_types.jl @@ -1,46 +1,3 @@ -function test_save_load_roundtrip(func, path, original::T; params=nothing) where T - # save and load from a file - filename = joinpath(path, "original.json") - save(filename, original) - loaded = load(filename; params=params) - if T <: Vector - @test loaded isa Vector - else - @test loaded isa T - end - func(loaded) - - # save and load from an IO buffer - io = IOBuffer() - save(io, original) - seekstart(io) - loaded = load(io; params=params) - - if T <: Vector - @test loaded isa Vector - else - @test loaded isa T - end - func(loaded) - - # save and load from an IO buffer, with prescribed type - io = IOBuffer() - save(io, original) - seekstart(io) - loaded = load(io, type=T, params=params) - if T <: Vector - @test loaded isa Vector - else - @test loaded isa T - end - func(loaded) - - # test loading on a empty state - save(filename, original) - reset_global_serializer_state() - loaded = load(filename; params=params) -end - @testset "basic_types" begin mktempdir() do path diff --git a/test/init_tests.jl b/test/init_tests.jl new file mode 100644 index 000000000000..1876387cfea4 --- /dev/null +++ b/test/init_tests.jl @@ -0,0 +1,46 @@ +# This file is dedicated for code that needs to be run on every worker before +# running the tests. This is useful for test-code that is called from multiple files +# that may run on different workers. + +function test_save_load_roundtrip(func, path, original::T; params=nothing) where T + # save and load from a file + filename = joinpath(path, "original.json") + save(filename, original) + loaded = load(filename; params=params) + if T <: Vector + @test loaded isa Vector + else + @test loaded isa T + end + func(loaded) + + # save and load from an IO buffer + io = IOBuffer() + save(io, original) + seekstart(io) + loaded = load(io; params=params) + + if T <: Vector + @test loaded isa Vector + else + @test loaded isa T + end + func(loaded) + + # save and load from an IO buffer, with prescribed type + io = IOBuffer() + save(io, original) + seekstart(io) + loaded = load(io, type=T, params=params) + if T <: Vector + @test loaded isa Vector + else + @test loaded isa T + end + func(loaded) + + # test loading on a empty state + save(filename, original) + reset_global_serializer_state() + loaded = load(filename; params=params) +end diff --git a/test/runtests.jl b/test/runtests.jl index 325a834eaa01..cec0e2cebe37 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -104,7 +104,7 @@ end Base.cumulative_compile_timing(true) end -println("Making test list") +@everywhere include("init_tests.jl") testlist = [