Skip to content

Commit

Permalink
Use copy_test_packages in some places, and ensure that the copied tes…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
rbvermaa committed Jan 14, 2025
1 parent bc9fb21 commit 28030c1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
3 changes: 1 addition & 2 deletions test/extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ using UUIDs
isolate(loaded_depot=false) do
mktempdir() do dir
Pkg.Registry.add("General")
path = joinpath(@__DIR__, "test_packages", "TestWeakDepProject")
cp(path, joinpath(dir, "TestWeakDepProject"))
copy_test_package("TestWeakDepProject")
Pkg.activate(joinpath(dir, "TestWeakDepProject"))
Pkg.resolve()
@test Pkg.dependencies()[UUID("2ab3a3ac-af41-5b50-aa03-7779005ae688")].version == v"0.3.26"
Expand Down
6 changes: 2 additions & 4 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3224,8 +3224,7 @@ end
temp_pkg_dir() do project_path
@testset "test entryfile entries" begin
mktempdir() do dir
path = abspath(joinpath(dirname(pathof(Pkg)), "../test", "test_packages", "ProjectPath"))
cp(path, joinpath(dir, "ProjectPath"))
copy_test_package("ProjectPath")
cd(joinpath(dir, "ProjectPath")) do
with_current_env() do
Pkg.resolve()
Expand All @@ -3238,8 +3237,7 @@ temp_pkg_dir() do project_path
end
@testset "test resolve with tree hash" begin
mktempdir() do dir
path = abspath(joinpath(@__DIR__, "../test", "test_packages", "ResolveWithRev"))
cp(path, joinpath(dir, "ResolveWithRev"))
copy_test_package("ResolveWithRev")
cd(joinpath(dir, "ResolveWithRev")) do
with_current_env() do
@test !isfile("Manifest.toml")
Expand Down
5 changes: 2 additions & 3 deletions test/project_manifest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ using ..Utils
temp_pkg_dir() do project_path
@testset "test Project.toml manifest" begin
mktempdir() do dir
path = abspath(joinpath(dirname(pathof(Pkg)), "../test", "test_packages", "monorepo"))
cp(path, joinpath(dir, "monorepo"))
copy_test_package(dir, "monorepo")
cd(joinpath(dir, "monorepo")) do
with_current_env() do
Pkg.develop(path="packages/B")
Expand Down Expand Up @@ -60,4 +59,4 @@ temp_pkg_dir() do project_path
end
end

end # module
end # module
3 changes: 1 addition & 2 deletions test/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ using ..Utils
temp_pkg_dir() do project_path
@testset "test Project.toml [sources]" begin
mktempdir() do dir
path = abspath(joinpath(dirname(pathof(Pkg)), "../test", "test_packages", "WithSources"))
cp(path, joinpath(dir, "WithSources"))
copy_test_package("WithSources")
cd(joinpath(dir, "WithSources")) do
with_current_env() do
Pkg.resolve()
Expand Down
12 changes: 12 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,21 @@ function git_init_package(tmp, path)
return pkgpath
end

function ensure_test_package_user_writable(dir)
for (root, _, files) in walkdir(dir)
chmod(root, filemode(root) | 0o200)

for file in files
filepath = joinpath(root, file)
chmod(filepath, filemode(filepath) | 0o200)
end
end
end

function copy_test_package(tmpdir::String, name::String; use_pkg=true)
target = joinpath(tmpdir, name)
cp(joinpath(@__DIR__, "test_packages", name), target)
ensure_test_package_user_writable(target)
use_pkg || return target

# The known Pkg UUID, and whatever UUID we're currently using for testing
Expand Down
3 changes: 1 addition & 2 deletions test/workspaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ end

@testset "test resolve with tree hash" begin
mktempdir() do dir
path = abspath(joinpath(@__DIR__, "../test", "test_packages", "WorkspaceTestInstantiate"))
cp(path, joinpath(dir, "WorkspaceTestInstantiate"))
copy_test_package("WorkspaceTestInstantiate")
cd(joinpath(dir, "WorkspaceTestInstantiate")) do
with_current_env() do
@test !isfile("Manifest.toml")
Expand Down

0 comments on commit 28030c1

Please sign in to comment.