Skip to content

Commit

Permalink
add unit test for track_content
Browse files Browse the repository at this point in the history
  • Loading branch information
fatteneder committed Oct 29, 2023
1 parent b361cee commit b38ad18
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
2 changes: 2 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ relocatedepot:
@cp -R $(build_datarootdir)/julia $(SRCDIR)/relocatedepot
@cp -R $(SRCDIR)/RelocationTestPkg1 $(SRCDIR)/relocatedepot
@cp -R $(SRCDIR)/RelocationTestPkg2 $(SRCDIR)/relocatedepot
@cp -R $(SRCDIR)/RelocationTestPkg3 $(SRCDIR)/relocatedepot
@cd $(SRCDIR) && \
$(call PRINT_JULIA, $(call spawn,RELOCATEDEPOT="" JULIA_DEPOT_PATH=$(SRCDIR)/relocatedepot/julia $(JULIA_EXECUTABLE)) --check-bounds=yes --startup-file=no --depwarn=error ./runtests.jl $@)

Expand All @@ -53,6 +54,7 @@ revise-relocatedepot: revise-% :
@cp -R $(build_datarootdir)/julia $(SRCDIR)/relocatedepot
@cp -R $(SRCDIR)/RelocationTestPkg1 $(SRCDIR)/relocatedepot
@cp -R $(SRCDIR)/RelocationTestPkg2 $(SRCDIR)/relocatedepot
@cp -R $(SRCDIR)/RelocationTestPkg3 $(SRCDIR)/relocatedepot
@cd $(SRCDIR) && \
$(call PRINT_JULIA, $(call spawn,RELOCATEDEPOT="" JULIA_DEPOT_PATH=$(SRCDIR)/relocatedepot/julia $(JULIA_EXECUTABLE)) --check-bounds=yes --startup-file=no --depwarn=error ./runtests.jl --revise $*)

Expand Down
3 changes: 3 additions & 0 deletions test/RelocationTestPkg3/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "RelocationTestPkg3"
uuid = "1ba4f954-9da9-4cd2-9ca7-6250235df52c"
version = "0.1.0"
7 changes: 7 additions & 0 deletions test/RelocationTestPkg3/src/RelocationTestPkg3.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module RelocationTestPkg3

include_dependency("bar.txt", track_content=true)
include_dependency("bardir", track_content=true)
greet() = print("Hello World!")

end # module RelocationTestPkg3
Empty file.
52 changes: 41 additions & 11 deletions test/relocatedepot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ function test_harness(@nospecialize(fn))
end
end

# We test relocation with three dummy pkgs:
# - RelocationTestPkg1 - no include_dependency
# - RelocationTestPkg2 - with include_dependency tracked by `mtime`
# - RelocationTestPkg3 - with include_dependency tracked by content

if !test_relocated_depot

Expand All @@ -28,39 +32,55 @@ if !test_relocated_depot
cachefiles = Base.find_all_in_cache_path(pkg)
rm.(cachefiles, force=true)
@test Base.isprecompiled(pkg) == false
Base.require(pkg) # precompile
Base.require(pkg)
@test Base.isprecompiled(pkg, ignore_loaded=true) == true
end
end

@testset "precompile RelocationTestPkg2 (contains include_dependency)" begin
@testset "precompile RelocationTestPkg2" begin
pkgname = "RelocationTestPkg2"
test_harness() do
push!(LOAD_PATH, @__DIR__)
push!(DEPOT_PATH, @__DIR__)
pkg = Base.identify_package(pkgname)
cachefiles = Base.find_all_in_cache_path(pkg)
rm.(cachefiles, force=true)
rm(joinpath(@__DIR__, pkgname, "src", "foodir"))
rm(joinpath(@__DIR__, pkgname, "src", "foodir"), force=true, recursive=true)
@test Base.isprecompiled(pkg) == false
touch(joinpath(@__DIR__, pkgname, "src", "foo.txt"))
mkdir(joinpath(@__DIR__, pkgname, "src", "foodir"))
Base.require(pkg) # precompile
Base.require(pkg)
@test Base.isprecompiled(pkg, ignore_loaded=true) == true
end
end

@testset "precompile RelocationTestPkg3" begin
pkgname = "RelocationTestPkg3"
test_harness() do
push!(LOAD_PATH, @__DIR__)
push!(DEPOT_PATH, @__DIR__)
pkg = Base.identify_package(pkgname)
cachefiles = Base.find_all_in_cache_path(pkg)
rm.(cachefiles, force=true)
rm(joinpath(@__DIR__, pkgname, "src", "bardir"), force=true, recursive=true)
@test Base.isprecompiled(pkg) == false
touch(joinpath(@__DIR__, pkgname, "src", "bar.txt"))
mkdir(joinpath(@__DIR__, pkgname, "src", "bardir"))
Base.require(pkg)
@test Base.isprecompiled(pkg, ignore_loaded=true) == true
end
end

else

# must come before any of the load tests, because the will recompile and generate new cache files
@testset "attempt loading precompiled pkgs when depot is missing" begin
@testset "attempt loading when depot is missing" begin
test_harness() do
empty!(LOAD_PATH)
push!(LOAD_PATH, joinpath(@__DIR__, "relocatedepot"))
for pkgname in ("RelocationTestPkg1", "RelocationTestPkg2")
for pkgname in ("RelocationTestPkg1", "RelocationTestPkg2", "RelocationTestPkg3")
pkg = Base.identify_package(pkgname)
cachefile = only(Base.find_all_in_cache_path(pkg))
@info cachefile
@test_throws ArgumentError("""
Failed to determine depot from srctext files in cache file $cachefile.
- Make sure you have adjusted DEPOT_PATH in case you relocated depots.""") Base.isprecompiled(pkg)
Expand All @@ -85,23 +105,33 @@ else
push!(DEPOT_PATH, joinpath(@__DIR__, "relocatedepot"))
pkg = Base.identify_package(pkgname)
@test Base.isprecompiled(pkg) == true
Base.require(pkg) # re-precompile
@test Base.isprecompiled(pkg) == true
end
end

@testset "load RelocationTestPkg2 (contains include_dependency) from test/relocatedepot" begin
@testset "load RelocationTestPkg2 from test/relocatedepot" begin
pkgname = "RelocationTestPkg2"
test_harness() do
push!(LOAD_PATH, joinpath(@__DIR__, "relocatedepot"))
push!(DEPOT_PATH, joinpath(@__DIR__, "relocatedepot"))
pkg = Base.identify_package(pkgname)
@test Base.isprecompiled(pkg) == false # moving depot changes mtime of include_dependency
Base.require(pkg) # re-precompile
Base.require(pkg)
@test Base.isprecompiled(pkg) == true
touch(joinpath(@__DIR__, "relocatedepot", "RelocationTestPkg2", "src", "foodir", "foofoo"))
@test Base.isprecompiled(pkg) == false
end
end

@testset "load RelocationTestPkg3 from test/relocatedepot" begin
pkgname = "RelocationTestPkg3"
test_harness() do
push!(LOAD_PATH, joinpath(@__DIR__, "relocatedepot"))
push!(DEPOT_PATH, joinpath(@__DIR__, "relocatedepot"))
pkg = Base.identify_package(pkgname)
@test Base.isprecompiled(pkg) == true
touch(joinpath(@__DIR__, "relocatedepot", "RelocationTestPkg3", "src", "bardir", "barbar"))
@test Base.isprecompiled(pkg) == false
end
end

end

0 comments on commit b38ad18

Please sign in to comment.