From e68d1b3cc732a4cb4ab49307eeff2ca0d9d6f80a Mon Sep 17 00:00:00 2001 From: Justin Willmert Date: Thu, 12 Jul 2018 12:56:10 -0500 Subject: [PATCH 1/2] Add tests --- test/runtests.jl | 68 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index d6a21e0..d263d6a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,26 @@ using Test -function writepkg(name, precomp::Bool) +function writepkg(name, precomp::Bool, submod::Bool) + action = """ + global flag = true + """ + + if submod + open("$(name)_submod.jl", "w") do io + println(io, """ + export SubModule + module SubModule + using JSON + flag = true + end + """) + end + + action *= """ + include("$(name)_submod.jl") + """ + end + open("$name.jl", "w") do io println(io, """ __precompile__($precomp) @@ -12,7 +32,9 @@ using Requires flag = false function __init__() - @require JSON="682c06a0-de6a-54ab-a142-c8b1cf79cde6" global flag = true + @require JSON="682c06a0-de6a-54ab-a142-c8b1cf79cde6" begin + $(action) + end end end @@ -26,12 +48,22 @@ end npcdir = joinpath("FooNPC", "src") mkpath(npcdir) cd(npcdir) do - writepkg("FooNPC", false) + writepkg("FooNPC", false, false) end npcdir = joinpath("FooPC", "src") mkpath(npcdir) cd(npcdir) do - writepkg("FooPC", true) + writepkg("FooPC", true, false) + end + npcdir = joinpath("FooSubNPC", "src") + mkpath(npcdir) + cd(npcdir) do + writepkg("FooSubNPC", false, true) + end + npcdir = joinpath("FooSubPC", "src") + mkpath(npcdir) + cd(npcdir) do + writepkg("FooSubPC", true, true) end end push!(LOAD_PATH, pkgsdir) @@ -40,28 +72,52 @@ end @test !FooNPC.flag @eval using FooPC @test !FooPC.flag + @eval using FooSubNPC + @test !(:SubModule in names(FooSubNPC)) + @eval using FooSubPC + @test !(:SubModule in names(FooSubPC)) @eval using JSON @test FooNPC.flag @test FooPC.flag + @test :SubModule in names(FooSubNPC) + @test FooSubNPC.SubModule.flag + @test :SubModule in names(FooSubPC) + @test FooSubPC.SubModule.flag cd(pkgsdir) do npcdir = joinpath("FooAfterNPC", "src") mkpath(npcdir) cd(npcdir) do - writepkg("FooAfterNPC", false) + writepkg("FooAfterNPC", false, false) end pcidr = joinpath("FooAfterPC", "src") mkpath(pcidr) cd(pcidr) do - writepkg("FooAfterPC", true) + writepkg("FooAfterPC", true, false) + end + sanpcdir = joinpath("FooSubAfterNPC", "src") + mkpath(sanpcdir) + cd(sanpcdir) do + writepkg("FooSubAfterNPC", false, true) + end + sapcdir = joinpath("FooSubAfterPC", "src") + mkpath(sapcdir) + cd(sapcdir) do + writepkg("FooSubAfterPC", true, true) end end @eval using FooAfterNPC @eval using FooAfterPC + @eval using FooSubAfterNPC + @eval using FooSubAfterPC @test FooAfterNPC.flag @test FooAfterPC.flag + @test :SubModule in names(FooSubAfterNPC) + @test FooSubAfterNPC.SubModule.flag + @test :SubModule in names(FooSubAfterPC) + @test FooSubAfterPC.SubModule.flag end end From 993077226e61c2b63362318920a9b51a25761f7b Mon Sep 17 00:00:00 2001 From: Justin Willmert Date: Thu, 12 Jul 2018 14:39:28 -0500 Subject: [PATCH 2/2] Switch from JSON to Colors package The tests need to load a package which itself has non-stdlib packages as sub-dependencies for this to trigger load errors. --- test/REQUIRE | 2 +- test/runtests.jl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/REQUIRE b/test/REQUIRE index 732835a..303e7ea 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1 +1 @@ -JSON +Colors diff --git a/test/runtests.jl b/test/runtests.jl index d263d6a..d7d40d5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,7 +10,7 @@ function writepkg(name, precomp::Bool, submod::Bool) println(io, """ export SubModule module SubModule - using JSON + using Colors flag = true end """) @@ -32,7 +32,7 @@ using Requires flag = false function __init__() - @require JSON="682c06a0-de6a-54ab-a142-c8b1cf79cde6" begin + @require Colors="5ae59095-9a9b-59fe-a467-6f913c188581" begin $(action) end end @@ -77,7 +77,7 @@ end @eval using FooSubPC @test !(:SubModule in names(FooSubPC)) - @eval using JSON + @eval using Colors @test FooNPC.flag @test FooPC.flag