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

loading: a bug fix, complete tests, delete old/redundant tests #26260

Merged
merged 2 commits into from
Feb 28, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
loading tests: delete old, redundant tests
  • Loading branch information
StefanKarpinski committed Feb 28, 2018
commit ec75c58462e85fdb45dd9b5a91e1782d27b4efa6
209 changes: 0 additions & 209 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,215 +176,6 @@ end
@test Foo.which == "path"
end

function gen_entry_point(entry::String, pkg::PkgId)
mkpath(dirname(entry))
open(entry, "w") do io
print(io, """
__precompile__(true)
module $(pkg.name)
uuid = $(pkg.uuid === nothing ? "nothing" : "Base.UUID(\"$(pkg.uuid)\")")
name = "$(pkg.name)"
end
""")
end
end

function gen_project_file(project_file::String, pkg::PkgId, deps::Pair{String,UUID}...)
mkpath(dirname(project_file))
open(project_file, "w") do io
println(io, "name = $(repr(pkg.name))")
pkg.uuid !== nothing && println(io, "uuid = $(repr(string(pkg.uuid)))")
println(io, "\n[deps]")
for (name, uuid) in deps
println(io, "$name = ", repr(string(uuid)))
end
end
end

function gen_implicit(dir::String, pkg::PkgId, proj::Bool, deps::Pair{String,UUID}...)
entry_point = joinpath(dir, pkg.name, "src", "$(pkg.name).jl")
gen_entry_point(entry_point, pkg)
proj && gen_project_file(joinpath(dir, pkg.name, "Project.toml"), pkg, deps...)
return entry_point
end

function gen_depot_ver(depot::String, pkg::PkgId, deps::Pair{String,UUID}...)
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")
gen_entry_point(entry, pkg)
gen_project_file(joinpath(dir, "Project.toml"), pkg, deps...)
return tree, entry
end

let n = 0
global function gen_explicit(dir::String, pkg::PkgId=PkgId("Env$(n += 1)"))
gen_project_file(joinpath(dir, "Project.toml"), pkg)
close(open(joinpath(dir, "Manifest.toml"), "w"))
end
end

function gen_manifest(dir::String, name::String, uuid::UUID, tree::SHA1,
deps::Pair{String,UUID}...; toplevel::Bool = true)
toplevel && open(joinpath(dir, "Project.toml"), "a") do io
println(io, "$name = \"$uuid\"")
end
open(joinpath(dir, "Manifest.toml"), "a") do io
println(io, "[[$name]]")
println(io, "uuid = \"$uuid\"")
println(io, "git-tree-sha1 = \"$(bytes2hex(tree.bytes))\"")
if !isempty(deps)
println(io, " [$name.deps]")
for (n, u) in deps
println(io, " $n = \"$u\"")
end
end
println(io)
end
end

false && let name = "Flarp"
uuidA = UUID("b2cb3794-8625-4058-bcde-7eeb13ac1c8b")
uuidB = UUID("1513c021-3639-4616-a37b-ee45c9d2f773")
uuids = [nothing, uuidA, uuidB]

ft(::UUID) = true:true
ft(::Nothing) = false:true

@testset "direct dependency loading: implict + implicit" begin
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)
mktempdir() do dir1
push!(LOAD_PATH, dir1)
path1 = gen_implicit(dir1, pkg1, proj1)
@test identify_package(name) == pkg1
@test locate_package(pkg1) == path1
path = uuid1 == coalesce(uuid2, uuid1) ? path1 : nothing
@test locate_package(pkg2) == path
mktempdir() do dir2
push!(LOAD_PATH, dir2)
path2 = gen_implicit(dir2, pkg2, proj2)
@test identify_package(name) == pkg1
@test locate_package(pkg1) == path1
path = uuid1 == coalesce(uuid2, uuid1) ? path1 : path2
@test locate_package(pkg2) == path
end
end
end
end

@testset "direct dependency loading: explicit + explicit" 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
uuids[i] !== nothing && uuids[j] !== nothing || continue
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)
gen_explicit(dir2)
gen_manifest(dir2, name, uuids[j], trees[j,l])
@test identify_package(name) == pkgs[i]
@test locate_package(pkgs[i]) == paths[i,k]
path = uuids[i] == uuids[j] ? paths[i,k] : paths[j,l]
@test locate_package(pkgs[j]) == path
end
end
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])
uuids[i] !== nothing || continue
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] == 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] == coalesce(uuids[j], uuids[i]) ? paths[i,k] : path2
@test locate_package(pkgs[j]) == path
end
end
end
end
end

uuidT = UUID("a54bd003-d8dc-4161-b186-d5516cd448e9")

@testset "indirect dependency loading: explicit + explicit" begin
mktempdir() do depot
push!(empty!(DEPOT_PATH), depot)
# generate top-level package
top = PkgId(uuidT, "TopLevel")
top_tree, _ = gen_depot_ver(depot, top)
# generate dependency packages
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, 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)
gen_explicit(dir1)
gen_manifest(dir1, name, uuids[i], trees[i,k], toplevel=false)
s && gen_manifest(dir1, top.name, top.uuid, top_tree, name => uuids[i])
@test identify_package(top, name) == (s ? pkgs[i] : nothing)
@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)
gen_explicit(dir2)
t && gen_manifest(dir1, top.name, top.uuid, top_tree, name => uuids[j])
gen_manifest(dir2, name, uuids[j], trees[j,l], toplevel=false)
pkg = (s ? pkgs[i] : t ? pkgs[j] : nothing)
@test identify_package(top, name) == pkg
@test locate_package(pkgs[i]) == paths[i,k]
path = uuids[i] == uuids[j] ? paths[i,k] : paths[j,l]
@test locate_package(pkgs[j]) == path
end
end
end
end
end
end # let

## systematic generation of test environments ##

const M = 3 # number of node names
Expand Down