Improve error message when running `TestEnv.activate()` twice
in v1.6:
julia> TestEnv.activate()
┌ Warning: Could not use exact versions of packages in manifest, re-resolving
└ @ TestEnv ~/.julia/packages/TestEnv/0IT5L/src/activate_set.jl:60
"/var/folders/hx/1h0bbkfd18d4n1qrnwmrl4j00000gn/T/jl_HNWFMu/Project.toml"
julia> TestEnv.activate()
ERROR: type Nothing has no field name
Stacktrace:
[1] getproperty(x::Nothing, f::Symbol)
@ Base ./Base.jl:33
[2] current_pkg_name
@ ~/.julia/packages/TestEnv/0IT5L/src/common.jl:10 [inlined]
[3] activate()
@ TestEnv ~/.julia/packages/TestEnv/0IT5L/src/activate_set.jl:7
[4] top-level scope
@ REPL[1]:1
I accidentally ran TestEnv twice, i.e. ran TestEnv in a "test env", and didn't realise that's what i'd done, saw a scary error and paniced unneccarily (clearly i spook easily)
I think ideally this error or warn with something a little more informative
e.g. change (for the 1.4-1.6 code) https://github.com/JuliaTesting/TestEnv.jl/blob/7a329a2d1df9a84e43cca605a4f2fe6c6e83273a/src/common.jl#L10 to something like
function current_pkg_name()
env = Context().env
pkg = env.pkg
pkg == nothing && error("Not in a named project with test dependencies: $(env.project_file)")
return pkg.name
end
i've not tested/looked into other julia versions.
Sounds good. A PR would be appreciated. (Make a PR to one branch and I will cherry pick it for the others)
This also happens if you forget to activate a package and do it in the @x.x env
julia> using TestEnv
julia> TestEnv.activate()
ERROR: type Nothing has no field name
Stacktrace:
[1] getproperty(x::Nothing, f::Symbol)
@ Base ./Base.jl:33
[2] current_pkg_name
@ ~/.julia/packages/TestEnv/0IT5L/src/common.jl:10 [inlined]
[3] activate()
@ TestEnv ~/.julia/packages/TestEnv/0IT5L/src/activate_set.jl:7
[4] top-level scope
@ REPL[2]:1