Skip to content
Open
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
35 changes: 20 additions & 15 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ unregistered_uuid = UUID("dcb67f36-efa0-11e8-0cef-2fc465ed98ae")
simple_package_uuid = UUID("fc6b7c0f-8a2f-4256-bbf4-8c72c30df5be")
pngjll_uuid = UUID("b53b4c65-9356-5827-b1ea-8c7a1a84506f")

# Create Unregistered test package once for all tests
const UNREGISTERED_TEMPDIR = mktempdir(; cleanup = false)
const UNREGISTERED_PATH = git_init_unregistered_package(UNREGISTERED_TEMPDIR)
const UNREGISTERED_URL = make_file_url(UNREGISTERED_PATH)

# Disable auto-gc for these tests
Pkg._auto_gc_enabled[] = false

Expand Down Expand Up @@ -106,7 +111,7 @@ Pkg._auto_gc_enabled[] = false
@test isdir(Pkg.Types.add_repo_cache_path(pkg.git_source))
end
# Also check that unregistered packages are installed properly.
Pkg.add(url = "https://github.com/00vareladavid/Unregistered.jl")
Pkg.add(url = UNREGISTERED_URL)
Pkg.dependencies(unregistered_uuid) do pkg
@test isdir(pkg.source)
@test isdir(Pkg.Types.add_repo_cache_path(pkg.git_source))
Expand Down Expand Up @@ -289,7 +294,7 @@ end
Pkg.activate(path)
inside_test_sandbox() do
Pkg.dependencies(unregistered_uuid) do pkg
@test pkg.git_source == "https://github.com/00vareladavid/Unregistered.jl"
@test pkg.git_source == UNREGISTERED_URL
@test !pkg.is_tracking_registry
end
end
Expand All @@ -313,7 +318,7 @@ end
inside_test_sandbox() do
Pkg.dependencies(unregistered_uuid) do pkg
@test !pkg.is_tracking_registry
@test pkg.git_source == "https://github.com/00vareladavid/Unregistered.jl"
@test pkg.git_source == UNREGISTERED_URL
end
end
end
Expand Down Expand Up @@ -815,9 +820,9 @@ end
end
# It should be possible to switch branches by reusing the URL.
isolate(loaded_depot = true) do
Pkg.add(url = "https://github.com/00vareladavid/Unregistered.jl", rev = "0.2.0")
Pkg.add(url = UNREGISTERED_URL, rev = "0.2.0")
Pkg.dependencies(unregistered_uuid) do pkg
@test pkg.git_source == "https://github.com/00vareladavid/Unregistered.jl"
@test pkg.git_source == UNREGISTERED_URL
@test !pkg.is_tracking_registry
@test pkg.git_revision == "0.2.0"
# We check that we have the correct branch by checking its dependencies.
Expand All @@ -826,7 +831,7 @@ end
# Now we refer to it by name so to check that we reuse the URL.
Pkg.add(name = "Unregistered", rev = "0.1.0")
Pkg.dependencies(unregistered_uuid) do pkg
@test pkg.git_source == "https://github.com/00vareladavid/Unregistered.jl"
@test pkg.git_source == UNREGISTERED_URL
@test !pkg.is_tracking_registry
@test pkg.git_revision == "0.1.0"
# We check that we have the correct branch by checking its dependencies.
Expand Down Expand Up @@ -1066,7 +1071,7 @@ end
# Now we test packages added by URL.
isolate(loaded_depot = true) do
# Details: `master` is past `0.1.0`
Pkg.add(url = "https://github.com/00vareladavid/Unregistered.jl", rev = "0.1.0")
Pkg.add(url = UNREGISTERED_URL, rev = "0.1.0")
Pkg.dependencies(unregistered_uuid) do pkg
@test pkg.name == "Unregistered"
@test isdir(pkg.source)
Expand Down Expand Up @@ -1813,7 +1818,7 @@ end
end
# develop tries to resolve from the manifest
isolate(loaded_depot = true) do
remote_url = "https://github.com/00vareladavid/Unregistered.jl"
remote_url = UNREGISTERED_URL
Pkg.add(Pkg.PackageSpec(url = remote_url))
Pkg.develop("Unregistered")
Pkg.dependencies(unregistered_uuid) do pkg
Expand Down Expand Up @@ -2203,7 +2208,7 @@ end
end
# make sure that we preserve the state of packages which are not the target
isolate(loaded_depot = true) do
Pkg.add(url = "https://github.com/00vareladavid/Unregistered.jl")
Pkg.add(url = UNREGISTERED_URL)
Pkg.develop("Example")
Pkg.add(name = "JSON", version = "0.18.0")
Pkg.add("Markdown")
Expand Down Expand Up @@ -2315,7 +2320,7 @@ end
end
# pinning to an arbitrary version should check for unregistered packages
isolate(loaded_depot = true) do
Pkg.add(url = "https://github.com/00vareladavid/Unregistered.jl")
Pkg.add(url = UNREGISTERED_URL)
@test_throws PkgError(
"unable to pin unregistered package `Unregistered [dcb67f36]` to an arbitrary version"
) Pkg.pin(name = "Unregistered", version = "0.1.0")
Expand All @@ -2339,7 +2344,7 @@ end
end
# package tracking repo
isolate(loaded_depot = true) do
Pkg.add(url = "https://github.com/00vareladavid/Unregistered.jl")
Pkg.add(url = UNREGISTERED_URL)
Pkg.pin("Unregistered")
Pkg.dependencies(unregistered_uuid) do pkg
@test !pkg.is_tracking_registry
Expand Down Expand Up @@ -2413,11 +2418,11 @@ end
end
# free should error when called on packages tracking unregistered packages
isolate(loaded_depot = true) do
Pkg.add(url = "https://github.com/00vareladavid/Unregistered.jl")
Pkg.add(url = UNREGISTERED_URL)
@test_throws PkgError("unable to free unregistered package `Unregistered [dcb67f36]`") Pkg.free("Unregistered")
end
isolate(loaded_depot = true) do
Pkg.develop(url = "https://github.com/00vareladavid/Unregistered.jl")
Pkg.develop(url = UNREGISTERED_URL)
@test_throws PkgError("unable to free unregistered package `Unregistered [dcb67f36]`") Pkg.free("Unregistered")
end
end
Expand Down Expand Up @@ -2927,12 +2932,12 @@ end
Pkg.add("Markdown")
Pkg.add(name = "JSON", version = "0.18.0")
Pkg.develop("Example")
Pkg.add(url = "https://github.com/00vareladavid/Unregistered.jl")
Pkg.add(url = UNREGISTERED_URL)
Pkg.status(; io = io)
@test occursin(r"Status `.+Project\.toml`", readline(io))
@test occursin(r"\[7876af07\] Example\s*v\d\.\d\.\d\s*`.+`", readline(io))
@test occursin(r"\[682c06a0\] JSON\s*v0.18.0", readline(io))
@test occursin(r"\[dcb67f36\] Unregistered\s*v\d\.\d\.\d\s*`https://github\.com/00vareladavid/Unregistered\.jl#master`", readline(io))
@test occursin(r"\[dcb67f36\] Unregistered\s*v\d\.\d\.\d\s*`file://.+Unregistered#master`", readline(io))
@test occursin(r"\[d6f4376e\] Markdown", readline(io))
end
## status warns when package not installed
Expand Down
6 changes: 6 additions & 0 deletions test/test_packages/Unregistered/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "Unregistered"
uuid = "dcb67f36-efa0-11e8-0cef-2fc465ed98ae"
authors = ["David Varela <[email protected]>"]
version = "0.1.0"

[deps]
5 changes: 5 additions & 0 deletions test/test_packages/Unregistered/src/Unregistered.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Unregistered

greet() = print("Hello World!")

end # module
48 changes: 47 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using UUIDs

export temp_pkg_dir, cd_tempdir, isinstalled, write_build, with_current_env,
with_temp_env, with_pkg_env, git_init_and_commit, copy_test_package,
git_init_package, add_this_pkg, TEST_SIG, TEST_PKG, isolate, LOADED_DEPOT,
git_init_package, git_init_unregistered_package, make_file_url, add_this_pkg, TEST_SIG, TEST_PKG, isolate, LOADED_DEPOT,
list_tarball_files, recursive_rm_cov_files, copy_this_pkg_cache

const CACHE_DIRECTORY = realpath(mktempdir(; cleanup = true))
Expand Down Expand Up @@ -289,6 +289,52 @@ function git_init_package(tmp, path)
return pkgpath
end

function make_file_url(path)
# Convert a path into a file URL.
# Turn the slashes on Windows. In case the path starts with a
# drive letter, an extra slash will be needed in the file URL.
path = replace(path, "\\" => "/")
if !startswith(path, "/")
path = "/" * path
end
return "file://$(path)"
end

function git_init_unregistered_package(tmp)
# Create Unregistered package with two tagged versions (0.1.0 and 0.2.0)
path = joinpath(@__DIR__, "test_packages", "Unregistered")
base = basename(path)
pkgpath = joinpath(tmp, base)
cp(path, pkgpath)

# Initialize git and create version 0.1.0
LibGit2.with(LibGit2.init(pkgpath)) do repo
LibGit2.add!(repo, "*")
commit_oid = LibGit2.commit(repo, "Version 0.1.0"; author = TEST_SIG, committer = TEST_SIG)
LibGit2.tag_create(repo, "0.1.0", commit_oid, sig = TEST_SIG, msg = "Version 0.1.0")

# Update to version 0.2.0 with Example dependency
project_path = joinpath(pkgpath, "Project.toml")
write(
project_path, """
name = "Unregistered"
uuid = "dcb67f36-efa0-11e8-0cef-2fc465ed98ae"
authors = ["David Varela <[email protected]>"]
version = "0.2.0"

[deps]
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
"""
)

LibGit2.add!(repo, "Project.toml")
commit_oid = LibGit2.commit(repo, "Version 0.2.0"; author = TEST_SIG, committer = TEST_SIG)
LibGit2.tag_create(repo, "0.2.0", commit_oid, sig = TEST_SIG, msg = "Version 0.2.0")
end

return pkgpath
end

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