From 1574207f157f4a811935153e8a81ce147e135eb3 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Sat, 20 Jan 2018 12:11:43 -0500 Subject: [PATCH 1/2] test direct dependency loading (explicit, implicit) --- test/loading.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/loading.jl b/test/loading.jl index e3614d921972f..8e86e473515ea 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -306,6 +306,37 @@ end end end +@testset "direct dependency loading: explicit + implicit" begin + mktempdir() do depot + push!(empty!(DEPOT_PATH), depot) + pkgs = [PkgId(uuid, name) for uuid in uuids] + pairs = [gen_depot_ver(depot, pkg) for pkg in pkgs, _ in 1:2] + trees = first.(pairs) + paths = last.(pairs) + for i = 1:length(uuids), k = 1:2, + j = 1:length(uuids), l = 1:2, proj in ft(uuids[j]) + empty!(LOAD_PATH) + mktempdir() do dir1 + push!(LOAD_PATH, dir1) + gen_explicit(dir1) + gen_manifest(dir1, name, uuids[i], trees[i,k]) + @test identify_package(name) == pkgs[i] + @test locate_package(pkgs[i]) == paths[i,k] + path = uuids[i] == uuids[j] ? paths[i,k] : nothing + @test locate_package(pkgs[j]) == path + mktempdir() do dir2 + push!(LOAD_PATH, dir2) + path2 = gen_implicit(dir2, pkgs[j], proj) + @test identify_package(name) == pkgs[i] + @test locate_package(pkgs[i]) == paths[i,k] + path = uuids[i] == uuids[j] ? paths[i,k] : path2 + @test locate_package(pkgs[j]) == path + end + end + end + end +end + const uuidT = UUID("a54bd003-d8dc-4161-b186-d5516cd448e9") @testset "indirect dependency loading: explicit + explicit" begin From 8d792a4ff49c11808362201e9391cf432b4e8227 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Sat, 20 Jan 2018 13:21:50 -0500 Subject: [PATCH 2/2] loading: more tests for uuid == nothing cases --- base/loading.jl | 3 ++- test/loading.jl | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index acb6dd08349b2..aff82abbf9359 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -197,8 +197,9 @@ struct PkgId name::String PkgId(u::UUID, name::AbstractString) = new(UInt128(u) == 0 ? nothing : u, name) - PkgId(name::AbstractString) = new(nothing, name) + PkgId(::Nothing, name::AbstractString) = new(nothing, name) end +PkgId(name::AbstractString) = PkgId(nothing, name) function PkgId(m::Module) uuid = UUID(ccall(:jl_module_uuid, NTuple{2, UInt64}, (Any,), m)) diff --git a/test/loading.jl b/test/loading.jl index 8e86e473515ea..1523424f25590 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -206,7 +206,7 @@ function gen_implicit(dir::String, pkg::PkgId, proj::Bool, deps::Pair{String,UUI end function gen_depot_ver(depot::String, pkg::PkgId, deps::Pair{String,UUID}...) - pkg.uuid === nothing && error("package UUID required in explicit env") + pkg.uuid === nothing && return nothing, nothing tree = SHA1(rand(UInt8, 20)) # fake tree hash dir = joinpath(depot, "packages", version_slug(pkg.uuid, tree)) entry = joinpath(dir, "src", "$(pkg.name).jl") @@ -244,14 +244,14 @@ end const name = "Flarp" const uuidA = UUID("b2cb3794-8625-4058-bcde-7eeb13ac1c8b") const uuidB = UUID("1513c021-3639-4616-a37b-ee45c9d2f773") -const uuids = [uuidA, uuidB] +const uuids = [nothing, uuidA, uuidB] ft(::UUID) = true:true ft(::Nothing) = false:true @testset "direct dependency loading: implict + implicit" begin - for uuid1 in [nothing; uuids], proj1 in ft(uuid1), - uuid2 in [nothing; uuids], proj2 in ft(uuid2) + for uuid1 in uuids, proj1 in ft(uuid1), + uuid2 in uuids, proj2 in ft(uuid2) pkg1 = uuid1 === nothing ? PkgId(name) : PkgId(uuid1, name) pkg2 = uuid2 === nothing ? PkgId(name) : PkgId(uuid2, name) empty!(LOAD_PATH) @@ -283,6 +283,7 @@ end paths = last.(pairs) for i = 1:length(uuids), k = 1:2, j = 1:length(uuids), l = 1:2 + uuids[i] !== nothing && uuids[j] !== nothing || continue empty!(LOAD_PATH) mktempdir() do dir1 push!(LOAD_PATH, dir1) @@ -315,6 +316,7 @@ end paths = last.(pairs) for i = 1:length(uuids), k = 1:2, j = 1:length(uuids), l = 1:2, proj in ft(uuids[j]) + uuids[i] !== nothing || continue empty!(LOAD_PATH) mktempdir() do dir1 push!(LOAD_PATH, dir1) @@ -322,14 +324,14 @@ end gen_manifest(dir1, name, uuids[i], trees[i,k]) @test identify_package(name) == pkgs[i] @test locate_package(pkgs[i]) == paths[i,k] - path = uuids[i] == uuids[j] ? paths[i,k] : nothing + path = uuids[i] == coalesce(uuids[j], uuids[i]) ? paths[i,k] : nothing @test locate_package(pkgs[j]) == path mktempdir() do dir2 push!(LOAD_PATH, dir2) path2 = gen_implicit(dir2, pkgs[j], proj) @test identify_package(name) == pkgs[i] @test locate_package(pkgs[i]) == paths[i,k] - path = uuids[i] == uuids[j] ? paths[i,k] : path2 + path = uuids[i] == coalesce(uuids[j], uuids[i]) ? paths[i,k] : path2 @test locate_package(pkgs[j]) == path end end @@ -352,6 +354,7 @@ const uuidT = UUID("a54bd003-d8dc-4161-b186-d5516cd448e9") paths = last.(pairs) for i = 1:length(uuids), k = 1:2, s = false:true, j = 1:length(uuids), l = 1:2, t = false:true + uuids[i] !== nothing && uuids[j] !== nothing || continue empty!(LOAD_PATH) mktempdir() do dir1 push!(LOAD_PATH, dir1)