Skip to content

Commit

Permalink
Initial registry construction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHatherly committed Jun 20, 2024
1 parent a6b931e commit d9c4499
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 16 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module TestPackage

import Example

greet() = Example.hello("World!")
greet() = Example.hello("0.1.0!")

end # module TestPackage
7 changes: 7 additions & 0 deletions test/packages/TestPackage/0.2.0/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "TestPackage"
uuid = "8346427c-08d3-4941-a1ec-6285c85e2ad6"
authors = ["MichaelHatherly <[email protected]>"]
version = "0.2.0"

[deps]
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
7 changes: 7 additions & 0 deletions test/packages/TestPackage/0.2.0/src/TestPackage.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module TestPackage

import Example

greet() = Example.hello("0.2.0!")

end # module TestPackage
61 changes: 46 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,21 @@ function with_testdir(f::Function)
end
end

# Windows requires file:/// while Unix requires file:// prefixes for the `git`
# commands to work correctly.
function local_url(path::AbstractString)
prefix = "file://"
return @static Sys.iswindows() ? "$(prefix)/$(path)" : "$(prefix)$(path)"
end

function prepare_package(packages_dir::String, project_dir::String)
project_file = joinpath(project_dir, "Project.toml")
project_data = TOML.parsefile(project_file)
name = project_data["name"]
version = project_data["version"]

package_dir = joinpath(packages_dir, name)
repo = "file://$(Sys.iswindows() ? "/$(package_dir)" : "$(package_dir)")"
repo = local_url(package_dir)
mkpath(joinpath(package_dir, "src"))

git = LocalRegistry.gitcmd(package_dir, TEST_GITCONFIG)
Expand Down Expand Up @@ -89,7 +96,7 @@ function with_empty_registry(f::Function)
run(`$upstream_git init -q --bare`)

downstream_dir = joinpath(testdir, "PackageBundlerTestRegistry")
repo = "file://$(Sys.iswindows() ? "/$(upstream_dir)" : "$(upstream_dir)")"
repo = local_url(upstream_dir)
LocalRegistry.create_registry(
downstream_dir,
repo;
Expand All @@ -108,21 +115,45 @@ end

@testset "PackageBundler" begin
with_empty_registry() do registry_dir, packages_dir
prepare_package(packages_dir, joinpath(@__DIR__, "packages", "TestPackage"))
LocalRegistry.register(
joinpath(packages_dir, "TestPackage");
registry = registry_dir,
gitconfig = TEST_GITCONFIG,
push = true,
)

# Register our test package at two different versions:
for version in ["0.1.0", "0.2.0"]
prepare_package(
packages_dir,
joinpath(@__DIR__, "packages", "TestPackage", version),
)
LocalRegistry.register(
joinpath(packages_dir, "TestPackage");
registry = registry_dir,
gitconfig = TEST_GITCONFIG,
push = true,
)
end
# Note: We have to update the registry to make the new packages
# available.
Pkg.Registry.update()

run(`ls -R $(DEPOT_PATH[1])`)
regs = Pkg.Registry.reachable_registries()
reg = regs[1]
@show reg.name
foreach(display, reg.pkgs)
@testset "Registry Consistency" begin
reg = nothing
regs = Pkg.Registry.reachable_registries()
for r in regs
if r.name == "PackageBundlerTestRegistry"
reg = r
break
end
end
@test !isnothing(reg)

@test length(reg.pkgs) == 1
pkg_entry = reg.pkgs[Base.UUID("8346427c-08d3-4941-a1ec-6285c85e2ad6")]
@test pkg_entry.name == "TestPackage"

test_package_tomls = joinpath(reg.path, "T", "TestPackage")
@test isdir(test_package_tomls)
versions_file = joinpath(test_package_tomls, "Versions.toml")
@test isfile(versions_file)
versions = TOML.parsefile(versions_file)
@test keys(versions) == Set(["0.1.0", "0.2.0"])
end

mktempdir() do script_dir
script = joinpath(script_dir, "script.jl")
Expand Down

0 comments on commit d9c4499

Please sign in to comment.