Skip to content

Commit df1931a

Browse files
authored
Use copy_test_packages in some places, and ensure that the copied test package is user writable. This allows running the Pkg tests as part of Base.runtests of an installed Julia installation, where sources might be readonly. (#4136)
1 parent 2609a94 commit df1931a

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

test/extensions.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ using UUIDs
9898
isolate(loaded_depot=false) do
9999
mktempdir() do dir
100100
Pkg.Registry.add("General")
101-
path = joinpath(@__DIR__, "test_packages", "TestWeakDepProject")
102-
cp(path, joinpath(dir, "TestWeakDepProject"))
103-
Pkg.activate(joinpath(dir, "TestWeakDepProject"))
101+
path = copy_test_package(dir, "TestWeakDepProject")
102+
Pkg.activate(path)
104103
Pkg.resolve()
105104
@test Pkg.dependencies()[UUID("2ab3a3ac-af41-5b50-aa03-7779005ae688")].version == v"0.3.26"
106105

test/new.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,9 +3224,8 @@ end
32243224
temp_pkg_dir() do project_path
32253225
@testset "test entryfile entries" begin
32263226
mktempdir() do dir
3227-
path = abspath(joinpath(dirname(pathof(Pkg)), "../test", "test_packages", "ProjectPath"))
3228-
cp(path, joinpath(dir, "ProjectPath"))
3229-
cd(joinpath(dir, "ProjectPath")) do
3227+
path = copy_test_package(dir, "ProjectPath")
3228+
cd(path) do
32303229
with_current_env() do
32313230
Pkg.resolve()
32323231
@test success(run(`$(Base.julia_cmd()) --startup-file=no --project -e 'using ProjectPath'`))
@@ -3238,9 +3237,8 @@ temp_pkg_dir() do project_path
32383237
end
32393238
@testset "test resolve with tree hash" begin
32403239
mktempdir() do dir
3241-
path = abspath(joinpath(@__DIR__, "../test", "test_packages", "ResolveWithRev"))
3242-
cp(path, joinpath(dir, "ResolveWithRev"))
3243-
cd(joinpath(dir, "ResolveWithRev")) do
3240+
path = copy_test_package(dir, "ResolveWithRev")
3241+
cd(path) do
32443242
with_current_env() do
32453243
@test !isfile("Manifest.toml")
32463244
@test !isdir(joinpath(DEPOT_PATH[1], "packages", "Example"))

test/project_manifest.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ using ..Utils
77
temp_pkg_dir() do project_path
88
@testset "test Project.toml manifest" begin
99
mktempdir() do dir
10-
path = abspath(joinpath(dirname(pathof(Pkg)), "../test", "test_packages", "monorepo"))
11-
cp(path, joinpath(dir, "monorepo"))
12-
cd(joinpath(dir, "monorepo")) do
10+
path = copy_test_package(dir, "monorepo")
11+
cd(path) do
1312
with_current_env() do
1413
Pkg.develop(path="packages/B")
1514
end
@@ -60,4 +59,4 @@ temp_pkg_dir() do project_path
6059
end
6160
end
6261

63-
end # module
62+
end # module

test/sources.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ using ..Utils
77
temp_pkg_dir() do project_path
88
@testset "test Project.toml [sources]" begin
99
mktempdir() do dir
10-
path = abspath(joinpath(dirname(pathof(Pkg)), "../test", "test_packages", "WithSources"))
11-
cp(path, joinpath(dir, "WithSources"))
12-
cd(joinpath(dir, "WithSources")) do
10+
path = copy_test_package(dir, "WithSources")
11+
cd(path) do
1312
with_current_env() do
1413
Pkg.resolve()
1514
@test !isempty(Pkg.project().sources["Example"])

test/utils.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,21 @@ function git_init_package(tmp, path)
270270
return pkgpath
271271
end
272272

273+
function ensure_test_package_user_writable(dir)
274+
for (root, _, files) in walkdir(dir)
275+
chmod(root, filemode(root) | 0o200 | 0o100)
276+
277+
for file in files
278+
filepath = joinpath(root, file)
279+
chmod(filepath, filemode(filepath) | 0o200)
280+
end
281+
end
282+
end
283+
273284
function copy_test_package(tmpdir::String, name::String; use_pkg=true)
274285
target = joinpath(tmpdir, name)
275286
cp(joinpath(@__DIR__, "test_packages", name), target)
287+
ensure_test_package_user_writable(target)
276288
use_pkg || return target
277289

278290
# The known Pkg UUID, and whatever UUID we're currently using for testing

test/workspaces.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ end
148148

149149
@testset "test resolve with tree hash" begin
150150
mktempdir() do dir
151-
path = abspath(joinpath(@__DIR__, "../test", "test_packages", "WorkspaceTestInstantiate"))
152-
cp(path, joinpath(dir, "WorkspaceTestInstantiate"))
153-
cd(joinpath(dir, "WorkspaceTestInstantiate")) do
151+
path = copy_test_package(dir, "WorkspaceTestInstantiate")
152+
cd(path) do
154153
with_current_env() do
155154
@test !isfile("Manifest.toml")
156155
@test !isfile("test/Manifest.toml")

0 commit comments

Comments
 (0)