Skip to content

Commit

Permalink
Catch up on 1.8/1.9 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff committed Jun 13, 2023
1 parent 323b579 commit 25d9afb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/julia-1.8/activate_do.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Indeed this is basically extracted from what `Pkg.test()` does.
function activate(f, pkg::AbstractString=current_pkg_name())
ctx, pkgspec = ctx_and_pkgspec(pkg)

test_project_override = maybe_gen_project_override!(ctx, pkgspec)
return sandbox(ctx, pkgspec, pkgspec.path, joinpath(pkgspec.path, "test"), test_project_override) do
test_project_override = maybe_gen_project_override!(ctx, pkgspec)
path = pkgspec.path::String
return sandbox(ctx, pkgspec, path, joinpath(path, "test"), test_project_override) do
flush(stdout)
f()
end
Expand Down
4 changes: 2 additions & 2 deletions src/julia-1.8/activate_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function activate(pkg::AbstractString=current_pkg_name())
# This needs to be first as `gen_target_project` fixes `pkgspec.path` if it is nothing
sandbox_project_override = maybe_gen_project_override!(ctx, pkgspec)

sandbox_path = joinpath(pkgspec.path, "test")
sandbox_path = joinpath(pkgspec.path::String, "test")
sandbox_project = projectfile_path(sandbox_path)

tmp = mktempdir()
Expand Down Expand Up @@ -71,7 +71,7 @@ function activate(pkg::AbstractString=current_pkg_name())
# Absolutify stdlibs paths
for (uuid, entry) in temp_ctx.env.manifest
if is_stdlib(uuid)
entry.path = Types.stdlib_path(entry.name)
entry.path = Types.stdlib_path(entry.name::String)
end
end
write_env(temp_ctx.env; update_undo=false)
Expand Down
17 changes: 11 additions & 6 deletions src/julia-1.8/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ function Base.showerror(io::IO, ex::TestEnvError, bt; backtrace=true)
printstyled(io, ex.msg, color=Base.error_color())
end


current_pkg_name() = (Context().env.pkg::PackageSpec).name
function current_pkg_name()
ctx = Context()
ctx.env.pkg === nothing && throw(TestEnvError("trying to activate test environment of an unnamed project"))
return ctx.env.pkg.name
end

"""
ctx, pkgspec = ctx_and_pkgspec(pkg::AbstractString)
Expand Down Expand Up @@ -46,7 +49,9 @@ end


function test_dir_has_project_file(ctx, pkgspec)
return isfile(joinpath(get_test_dir(ctx, pkgspec), "Project.toml"))
test_dir = get_test_dir(ctx, pkgspec)
test_dir === nothing && return false
return isfile(joinpath(test_dir, "Project.toml"))
end

"""
Expand All @@ -60,16 +65,16 @@ function get_test_dir(ctx::Context, pkgspec::Pkg.Types.PackageSpec)
pkgspec.path = dirname(ctx.env.project_file)
pkgspec.version = ctx.env.pkg.version
else
is_stdlib(pkgspec.uuid) && return
is_stdlib(pkgspec.uuid::Base.UUID) && return
entry = manifest_info(ctx.env.manifest, pkgspec.uuid)
pkgspec.version = entry.version
pkgspec.tree_hash = entry.tree_hash
pkgspec.repo = entry.repo
pkgspec.path = entry.path
pkgspec.pinned = entry.pinned
pkgspec.path = project_rel_path(ctx.env, source_path(ctx.env.project_file, pkgspec))
pkgspec.path = project_rel_path(ctx.env, source_path(ctx.env.project_file, pkgspec)::String)
end
pkgfilepath = source_path(ctx.env.project_file, pkgspec)
pkgfilepath = source_path(ctx.env.project_file, pkgspec)::String
return joinpath(pkgfilepath, "test")
end

Expand Down
5 changes: 3 additions & 2 deletions src/julia-1.9/activate_do.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Indeed this is basically extracted from what `Pkg.test()` does.
function activate(f, pkg::AbstractString=current_pkg_name())
ctx, pkgspec = ctx_and_pkgspec(pkg)

test_project_override = maybe_gen_project_override!(ctx, pkgspec)
return sandbox(ctx, pkgspec, pkgspec.path, joinpath(pkgspec.path, "test"), test_project_override) do
test_project_override = maybe_gen_project_override!(ctx, pkgspec)
path = pkgspec.path::String
return sandbox(ctx, pkgspec, path, joinpath(path, "test"), test_project_override) do
flush(stdout)
f()
end
Expand Down
4 changes: 2 additions & 2 deletions src/julia-1.9/activate_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function activate(pkg::AbstractString=current_pkg_name())
# This needs to be first as `gen_target_project` fixes `pkgspec.path` if it is nothing
sandbox_project_override = maybe_gen_project_override!(ctx, pkgspec)

sandbox_path = joinpath(pkgspec.path, "test")
sandbox_path = joinpath(pkgspec.path::String, "test")
sandbox_project = projectfile_path(sandbox_path)

tmp = mktempdir()
Expand Down Expand Up @@ -71,7 +71,7 @@ function activate(pkg::AbstractString=current_pkg_name())
# Absolutify stdlibs paths
for (uuid, entry) in temp_ctx.env.manifest
if is_stdlib(uuid)
entry.path = Types.stdlib_path(entry.name)
entry.path = Types.stdlib_path(entry.name::String)
end
end
write_env(temp_ctx.env; update_undo=false)
Expand Down
17 changes: 11 additions & 6 deletions src/julia-1.9/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ function Base.showerror(io::IO, ex::TestEnvError, bt; backtrace=true)
printstyled(io, ex.msg, color=Base.error_color())
end


current_pkg_name() = (Context().env.pkg::PackageSpec).name
function current_pkg_name()
ctx = Context()
ctx.env.pkg === nothing && throw(TestEnvError("trying to activate test environment of an unnamed project"))
return ctx.env.pkg.name
end

"""
ctx, pkgspec = ctx_and_pkgspec(pkg::AbstractString)
Expand Down Expand Up @@ -46,7 +49,9 @@ end


function test_dir_has_project_file(ctx, pkgspec)
return isfile(joinpath(get_test_dir(ctx, pkgspec), "Project.toml"))
test_dir = get_test_dir(ctx, pkgspec)
test_dir === nothing && return false
return isfile(joinpath(test_dir, "Project.toml"))
end

"""
Expand All @@ -60,16 +65,16 @@ function get_test_dir(ctx::Context, pkgspec::Pkg.Types.PackageSpec)
pkgspec.path = dirname(ctx.env.project_file)
pkgspec.version = ctx.env.pkg.version
else
is_stdlib(pkgspec.uuid) && return
is_stdlib(pkgspec.uuid::Base.UUID) && return
entry = manifest_info(ctx.env.manifest, pkgspec.uuid)
pkgspec.version = entry.version
pkgspec.tree_hash = entry.tree_hash
pkgspec.repo = entry.repo
pkgspec.path = entry.path
pkgspec.pinned = entry.pinned
pkgspec.path = project_rel_path(ctx.env, source_path(ctx.env.project_file, pkgspec))
pkgspec.path = project_rel_path(ctx.env, source_path(ctx.env.project_file, pkgspec)::String)
end
pkgfilepath = source_path(ctx.env.project_file, pkgspec)
pkgfilepath = source_path(ctx.env.project_file, pkgspec)::String
return joinpath(pkgfilepath, "test")
end

Expand Down

0 comments on commit 25d9afb

Please sign in to comment.