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

Use mktempdir shim (until bugfix is complete) #504

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 8 additions & 8 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ temp_pkg_dir() do project_path
Pkg.add(TEST_PKG.name)
old_v = Pkg.installed()[TEST_PKG.name]
Pkg.rm(TEST_PKG.name)
mktempdir() do devdir
tempdir_util() do devdir
withenv("JULIA_PKG_DEVDIR" => devdir) do
Pkg.REPLMode.pkgstr("develop $(TEST_PKG.name)")
@test isinstalled(TEST_PKG)
Expand Down Expand Up @@ -231,7 +231,7 @@ temp_pkg_dir() do project_path
end

@testset "protocols" begin
mktempdir() do devdir
tempdir_util() do devdir
withenv("JULIA_PKG_DEVDIR" => devdir) do
try
Pkg.setprotocol!("notarealprotocol")
Expand Down Expand Up @@ -261,7 +261,7 @@ temp_pkg_dir() do project_path
Pkg.rm(TEST_PKG.name)

@testset "legacy CI script" begin
mktempdir() do dir
tempdir_util() do dir
LibGit2.with(LibGit2.clone("https://github.com/JuliaLang/Example.jl", joinpath(dir, "Example.jl"))) do r
cd(joinpath(dir, "Example.jl")) do
let Pkg = Pkg
Expand All @@ -280,7 +280,7 @@ temp_pkg_dir() do project_path
end

@testset "up in Project without manifest" begin
mktempdir() do dir
tempdir_util() do dir
cp(joinpath(@__DIR__, "test_packages", "UnregisteredWithProject"), joinpath(dir, "UnregisteredWithProject"))
cd(joinpath(dir, "UnregisteredWithProject")) do
with_current_env() do
Expand All @@ -292,7 +292,7 @@ temp_pkg_dir() do project_path
end

@testset "failing building a package should throw" begin
mktempdir() do path
tempdir_util() do path
cd(path) do
Pkg.generate("FailBuildPkg")
cd("FailBuildPkg")
Expand All @@ -314,7 +314,7 @@ temp_pkg_dir() do project_path
end

@testset "preview generate" begin
mktempdir() do tmp
tempdir_util() do tmp
cd(tmp) do
Pkg.generate("Foo"; preview=true)
@test !isdir(joinpath(tmp, "Foo"))
Expand All @@ -324,7 +324,7 @@ end

temp_pkg_dir() do project_path
@testset "test should instantiate" begin
mktempdir() do dir
tempdir_util() do dir
cp(joinpath(@__DIR__, "test_packages", "UnregisteredWithProject"), joinpath(dir, "UnregisteredWithProject"))
cd(joinpath(dir, "UnregisteredWithProject")) do
with_current_env() do
Expand All @@ -351,7 +351,7 @@ temp_pkg_dir() do project_path
end

cd(project_path) do
mktempdir() do tmp; cd(tmp) do
tempdir_util() do tmp; cd(tmp) do
pkg_name = "FooBar"
# create a project and grab its uuid
Pkg.generate(pkg_name)
Expand Down
18 changes: 9 additions & 9 deletions test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
@test_throws CommandError pkg"generate"
end

mktempdir() do project_path
tempdir_util() do project_path
cd(project_path) do
withenv("USER" => "Test User") do
pkg"generate HelloWorld"
Expand Down Expand Up @@ -93,7 +93,7 @@ end
@test repr(tokens[1][3]) == "VersionRange(\"0.5.0\")"
end

temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
temp_pkg_dir() do project_path; cd(project_path) do; tempdir_util() do tmp_pkg_path
pkg"activate ."
pkg"add Example"
@test isinstalled(TEST_PKG)
Expand Down Expand Up @@ -147,7 +147,7 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
Pkg.REPLMode.pkgstr("add $p2#$c")
end

mktempdir() do tmp_dev_dir
tempdir_util() do tmp_dev_dir
withenv("JULIA_PKG_DEVDIR" => tmp_dev_dir) do
pkg"develop Example"

Expand All @@ -161,7 +161,7 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
empty!(DEPOT_PATH)
write("Project.toml", proj)
write("Manifest.toml", manifest)
mktempdir() do depot_dir
tempdir_util() do depot_dir
pushfirst!(DEPOT_PATH, depot_dir)
pkg"instantiate"
@test Pkg.installed()[pkg2] == v"0.2.0"
Expand All @@ -179,8 +179,8 @@ end # temp_pkg_dir


temp_pkg_dir() do project_path; cd(project_path) do
mktempdir() do tmp
mktempdir() do depot_dir
tempdir_util() do tmp
tempdir_util() do depot_dir
old_depot = copy(DEPOT_PATH)
try
empty!(DEPOT_PATH)
Expand Down Expand Up @@ -214,8 +214,8 @@ temp_pkg_dir() do project_path; cd(project_path) do
end # withenv
end # mktempdir
# nested
mktempdir() do other_dir
mktempdir() do tmp;
tempdir_util() do other_dir
tempdir_util() do tmp;
cd(tmp)
withenv("USER" => "Test User") do
pkg"generate HelloWorld"
Expand Down Expand Up @@ -311,7 +311,7 @@ temp_pkg_dir() do project_path; cd(project_path) do
end end

temp_pkg_dir() do project_path; cd(project_path) do
mktempdir() do tmp
tempdir_util() do tmp
cp(joinpath(@__DIR__, "test_packages", "BigProject"), joinpath(tmp, "BigProject"))
cd(joinpath(tmp, "BigProject"))
with_current_env() do
Expand Down
22 changes: 20 additions & 2 deletions test/utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# this function should temporarily be used instead of `mktempdir`
function tempdir_util(fn::Function)
tempdir = mktempdir()
try
fn(tempdir)
finally
try
rm(tempdir; recursive=true, force=true)
catch ex
if ex isa SystemError && ex.prefix == "rmdir" && ex.errnum == 13
@error "tempdir_util: error while cleaning up: $ex"
else
throw(ex)
end
end
end
end

function temp_pkg_dir(fn::Function)
local env_dir
local old_load_path
Expand All @@ -13,8 +31,8 @@ function temp_pkg_dir(fn::Function)
empty!(DEPOT_PATH)
Base.HOME_PROJECT[] = nothing
Base.ACTIVE_PROJECT[] = nothing
mktempdir() do env_dir
mktempdir() do depot_dir
tempdir_util() do env_dir
tempdir_util() do depot_dir
push!(LOAD_PATH, "@", "@v#.#", "@stdlib")
push!(DEPOT_PATH, depot_dir)
fn(env_dir)
Expand Down