From df1931a9310dc3f9f0d6c53b5f23ac15e47ee6e7 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Thu, 16 Jan 2025 17:06:36 +0100 Subject: [PATCH] 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) --- test/extensions.jl | 5 ++--- test/new.jl | 10 ++++------ test/project_manifest.jl | 7 +++---- test/sources.jl | 5 ++--- test/utils.jl | 12 ++++++++++++ test/workspaces.jl | 5 ++--- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/test/extensions.jl b/test/extensions.jl index f7d7ab26b9..05a2a6bac6 100644 --- a/test/extensions.jl +++ b/test/extensions.jl @@ -98,9 +98,8 @@ 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")) - Pkg.activate(joinpath(dir, "TestWeakDepProject")) + path = copy_test_package(dir, "TestWeakDepProject") + Pkg.activate(path) Pkg.resolve() @test Pkg.dependencies()[UUID("2ab3a3ac-af41-5b50-aa03-7779005ae688")].version == v"0.3.26" diff --git a/test/new.jl b/test/new.jl index 7e0a51d82b..46f91168f7 100644 --- a/test/new.jl +++ b/test/new.jl @@ -3224,9 +3224,8 @@ 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")) - cd(joinpath(dir, "ProjectPath")) do + path = copy_test_package(dir, "ProjectPath") + cd(path) do with_current_env() do Pkg.resolve() @test success(run(`$(Base.julia_cmd()) --startup-file=no --project -e 'using ProjectPath'`)) @@ -3238,9 +3237,8 @@ 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")) - cd(joinpath(dir, "ResolveWithRev")) do + path = copy_test_package(dir, "ResolveWithRev") + cd(path) do with_current_env() do @test !isfile("Manifest.toml") @test !isdir(joinpath(DEPOT_PATH[1], "packages", "Example")) diff --git a/test/project_manifest.jl b/test/project_manifest.jl index ab6a6cc99f..41974ed612 100644 --- a/test/project_manifest.jl +++ b/test/project_manifest.jl @@ -7,9 +7,8 @@ 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")) - cd(joinpath(dir, "monorepo")) do + path = copy_test_package(dir, "monorepo") + cd(path) do with_current_env() do Pkg.develop(path="packages/B") end @@ -60,4 +59,4 @@ temp_pkg_dir() do project_path end end -end # module \ No newline at end of file +end # module diff --git a/test/sources.jl b/test/sources.jl index 1497464aab..e17c40d6c3 100644 --- a/test/sources.jl +++ b/test/sources.jl @@ -7,9 +7,8 @@ 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")) - cd(joinpath(dir, "WithSources")) do + path = copy_test_package(dir, "WithSources") + cd(path) do with_current_env() do Pkg.resolve() @test !isempty(Pkg.project().sources["Example"]) diff --git a/test/utils.jl b/test/utils.jl index ee19cb9bcb..7bbc606ade 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -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 | 0o100) + + 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 diff --git a/test/workspaces.jl b/test/workspaces.jl index acb41be7bd..33b75d2baa 100644 --- a/test/workspaces.jl +++ b/test/workspaces.jl @@ -148,9 +148,8 @@ end @testset "test resolve with tree hash" begin mktempdir() do dir - path = abspath(joinpath(@__DIR__, "../test", "test_packages", "WorkspaceTestInstantiate")) - cp(path, joinpath(dir, "WorkspaceTestInstantiate")) - cd(joinpath(dir, "WorkspaceTestInstantiate")) do + path = copy_test_package(dir, "WorkspaceTestInstantiate") + cd(path) do with_current_env() do @test !isfile("Manifest.toml") @test !isfile("test/Manifest.toml")