Skip to content

Commit

Permalink
Decouple version switching test from ExpontentialUtils (#831)
Browse files Browse the repository at this point in the history
* Decouple version switching test from ExpontentialUtils

And also fix a bug when revising from a package that was previously
empty, where it would assume it hadn't been parsed yet because
`modexsigs` was empty.

* ALso fix start_late test

* For prerelease versions, get source by commit

* Adjust for release versions

* Properly escape path for windows

* Update test/switch_version.jl

Co-authored-by: Tim Holy <[email protected]>

---------

Co-authored-by: Tim Holy <[email protected]>
  • Loading branch information
Keno and timholy authored Jul 30, 2024
1 parent c6ae5f4 commit a7ebcfa
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 53 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ jobs:
else
REPL.eval_user_input(:(exit()), Base.active_repl_backend)
end' "Methods at REPL"
# Tests for out-of-process updates to manifest
echo "Switch version"
bash test/envs/use_exputils/setup.sh
julia --project --code-coverage=user test/envs/use_exputils/switch_version.jl
# We also need to pick up the Git tests, but for that we need to `dev` the package
echo "Git tests"
julia --code-coverage=user -e '
Expand All @@ -92,8 +88,8 @@ jobs:
# Check #697
echo "Test #697"
dn=$(mktemp -d)
ver=$(julia -e 'println(VERSION)')
curl -s -L https://github.com/JuliaLang/julia/archive/refs/tags/v$ver.tar.gz --output - | tar -xz -C $dn
path=$(julia -e '(!isempty(VERSION.prerelease) && VERSION.prerelease[1] == "DEV") ? println(Base.GIT_VERSION_INFO.commit) : println("refs/tags/v",VERSION)')
curl -s -L https://github.com/JuliaLang/julia/archive/$path.tar.gz --output - | tar -xz -C $dn
julia --project test/juliadir.jl "$dn/julia-$ver"
# # Running out of inotify storage (see #26)
Expand Down
4 changes: 3 additions & 1 deletion src/pkgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function maybe_parse_from_cache!(pkgdata::PkgData, file::AbstractString)
return add_definitions_from_repl(file)
end
fi = fileinfo(pkgdata, file)
if isempty(fi.modexsigs) && (!isempty(fi.cachefile) || !isempty(fi.cacheexprs))
if (isempty(fi.modexsigs) && !fi.parsed[]) && (!isempty(fi.cachefile) || !isempty(fi.cacheexprs))
# Source was never parsed, get it from the precompile cache
src = read_from_cache(pkgdata, file)
filep = joinpath(basedir(pkgdata), file)
Expand All @@ -121,6 +121,7 @@ function maybe_parse_from_cache!(pkgdata::PkgData, file::AbstractString)
end
add_modexs!(fi, fi.cacheexprs)
empty!(fi.cacheexprs)
fi.parsed[] = true
end
return fi
end
Expand Down Expand Up @@ -470,6 +471,7 @@ function watch_manifest(mfile)
end
add_modexs!(fi, fi.cacheexprs)
empty!(fi.cacheexprs)
fi.parsed[] = true
end
fi
end
Expand Down
5 changes: 3 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ struct FileInfo
cachefile::String
cacheexprs::Vector{Tuple{Module,Expr}} # "unprocessed" exprs, used to support @require
extracted::Base.RefValue{Bool} # true if signatures have been processed from modexsigs
parsed::Base.RefValue{Bool} # true if modexsigs have been parsed from cachefile
end
FileInfo(fm::ModuleExprsSigs, cachefile="") = FileInfo(fm, cachefile, Tuple{Module,Expr}[], Ref(false))
FileInfo(fm::ModuleExprsSigs, cachefile="") = FileInfo(fm, cachefile, Tuple{Module,Expr}[], Ref(false), Ref(false))

"""
FileInfo(mod::Module, cachefile="")
Expand All @@ -100,7 +101,7 @@ Initialize an empty FileInfo for a file that is `include`d into `mod`.
"""
FileInfo(mod::Module, cachefile::AbstractString="") = FileInfo(ModuleExprsSigs(mod), cachefile)

FileInfo(fm::ModuleExprsSigs, fi::FileInfo) = FileInfo(fm, fi.cachefile, copy(fi.cacheexprs), Ref(fi.extracted[]))
FileInfo(fm::ModuleExprsSigs, fi::FileInfo) = FileInfo(fm, fi.cachefile, copy(fi.cacheexprs), Ref(fi.extracted[]), Ref(fi.parsed[]))

function Base.show(io::IO, fi::FileInfo)
print(io, "FileInfo(")
Expand Down
8 changes: 0 additions & 8 deletions test/envs/use_exputils/install.jl

This file was deleted.

10 changes: 0 additions & 10 deletions test/envs/use_exputils/setup.sh

This file was deleted.

25 changes: 0 additions & 25 deletions test/envs/use_exputils/switch_version.jl

This file was deleted.

3 changes: 3 additions & 0 deletions test/pkgs/PkgChange_v1/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "PkgChange"
uuid = "ad1172b6-6378-44d8-862e-6490a202d023"
version = "0.1.0"
6 changes: 6 additions & 0 deletions test/pkgs/PkgChange_v1/src/PkgChange.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module PkgChange

# Deliberately empty. This test also tests revising from an empty file to a file
# with contents.

end
3 changes: 3 additions & 0 deletions test/pkgs/PkgChange_v2/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "PkgChange"
uuid = "ad1172b6-6378-44d8-862e-6490a202d023"
version = "0.2.0"
6 changes: 6 additions & 0 deletions test/pkgs/PkgChange_v2/src/PkgChange.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module PkgChange

export somemethod
somemethod() = 1

end
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3851,3 +3851,7 @@ do_test("Base signatures") && @testset "Base signatures" begin
# Using the extensive repository of code in Base as a testbed
include("sigtest.jl")
end

# Run this test in a separate julia process, since it messes with projects, and we don't want to have to
# worry about making sure it resets cleanly.
do_test("Switch Versions") && @test success(pipeline(`$(Base.julia_cmd()) switch_version.jl`, stderr=stderr))
6 changes: 5 additions & 1 deletion test/start_late.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

using Test

@async(Base.run_main_repl(true, true, false, true, false))
t = @async(
VERSION >= v"1.12.0-DEV.612" ? Base.run_main_repl(true, true, :no, true) :
VERSION >= v"1.11.0-DEV.222" ? Base.run_main_repl(true, true, :no, true, false) :
Base.run_main_repl(true, true, false, true, false))
isdefined(Base, :errormonitor) && Base.errormonitor(t)
while !isdefined(Base, :active_repl_backend) || isnothing(Base.active_repl_backend)
sleep(0.5)
end
Expand Down
29 changes: 29 additions & 0 deletions test/switch_version.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Revise, Pkg, Test
mktempdir() do thisdir
Pkg.activate(thisdir)

Pkg.develop(path = joinpath(dirname(@__FILE__), "pkgs", "PkgChange_v1"))

# This is only needed on Pkg versions that don't notify
Revise.active_project_watcher()

# Back to toplevel
@eval begin
using PkgChange
@test_throws UndefVarError somemethod() # not present in v1
# From a different process, switch the active version of ExponentialUtilities
v2_cmd = """using Pkg; Pkg.activate("."); Pkg.develop(path = joinpath("$(escape_string(dirname(@__FILE__)))", "pkgs", "PkgChange_v2"))"""
t = @async run(pipeline(Cmd(`$(Base.julia_cmd()) -e $v2_cmd`; dir=$thisdir); stderr, stdout))
isdefined(Base, :errormonitor) && Base.errormonitor(t)
wait(Revise.revision_event)
revise()
@test somemethod() === 1 # present in v2
# ...and then switch back (check that it's bidirectional and also to reset state)
v1_cmd = """using Pkg; Pkg.activate("."); Pkg.develop(path = joinpath("$(escape_string(dirname(@__FILE__)))", "pkgs", "PkgChange_v1"))"""
t = @async run(pipeline(Cmd(`$(Base.julia_cmd()) -e $v1_cmd`; dir=$thisdir); stderr, stdout))
isdefined(Base, :errormonitor) && Base.errormonitor(t)
wait(Revise.revision_event)
revise()
@test_throws MethodError somemethod() # not present in v1
end
end

0 comments on commit a7ebcfa

Please sign in to comment.