|
5 | 5 | Pkg.add(PackageSpec(name="ChainRulesCore", version="1.0.2")) |
6 | 6 |
|
7 | 7 | orig_project_toml_path = Base.active_project() |
| 8 | + orig_load_path = copy(LOAD_PATH) |
8 | 9 | push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing |
9 | | - orig_load_path = Base.LOAD_PATH |
10 | 10 | try |
11 | 11 | TestEnv.activate("ChainRulesCore") |
12 | 12 | new_project_toml_path = Base.active_project() |
13 | 13 | @test new_project_toml_path != orig_project_toml_path |
14 | | - @test orig_load_path == Base.LOAD_PATH |
15 | 14 |
|
16 | 15 | @eval using StaticArrays # From ChainRulesCore [extras] Project.toml |
17 | 16 | @test Base.invokelatest(isdefined, @__MODULE__, :StaticArrays) |
|
22 | 21 | Pkg.activate(orig_project_toml_path) |
23 | 22 | # No longer is enviroment active |
24 | 23 | @test_throws ArgumentError @eval using OffsetArrays |
| 24 | + pop!(LOAD_PATH) |
| 25 | + @test orig_load_path == LOAD_PATH |
25 | 26 | end |
26 | 27 | end |
27 | 28 | end |
|
34 | 35 | Pkg.add(PackageSpec(name="YAXArrays", version="0.1.3")) |
35 | 36 |
|
36 | 37 | orig_project_toml_path = Base.active_project() |
| 38 | + orig_load_path = copy(LOAD_PATH) |
37 | 39 | push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing |
38 | | - orig_load_path = Base.LOAD_PATH |
39 | 40 | try |
40 | 41 | # YAXArrays has a test/Project.toml, which contains CSV |
41 | 42 | if VERSION >= v"1.8-" |
|
46 | 47 | TestEnv.activate("YAXArrays"; kw...) |
47 | 48 | new_project_toml_path = Base.active_project() |
48 | 49 | @test new_project_toml_path != orig_project_toml_path |
49 | | - @test orig_load_path == Base.LOAD_PATH |
50 | 50 |
|
51 | 51 | @eval using CSV |
52 | 52 | @test Base.invokelatest(isdefined, @__MODULE__, :CSV) |
53 | 53 |
|
54 | 54 | finally |
55 | 55 | Pkg.activate(orig_project_toml_path) |
| 56 | + pop!(LOAD_PATH) |
| 57 | + @test orig_load_path == LOAD_PATH |
56 | 58 | end |
57 | 59 | elseif VERSION >= v"1.2-" |
58 | 60 | Pkg.add(PackageSpec(name="ConstraintSolver", version="0.6.10")) |
59 | 61 |
|
60 | 62 | orig_project_toml_path = Base.active_project() |
| 63 | + orig_load_path = copy(LOAD_PATH) |
61 | 64 | push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing |
62 | | - orig_load_path = Base.LOAD_PATH |
63 | 65 | try |
64 | 66 | # ConstraintSolver has a test/Project.toml, which contains CSV |
65 | 67 | if VERSION >= v"1.8-" |
|
70 | 72 | TestEnv.activate("ConstraintSolver"; kw...) |
71 | 73 | new_project_toml_path = Base.active_project() |
72 | 74 | @test new_project_toml_path != orig_project_toml_path |
73 | | - @test orig_load_path == Base.LOAD_PATH |
74 | 75 |
|
75 | 76 | @eval using JSON |
76 | 77 | @test Base.invokelatest(isdefined, @__MODULE__, :JSON) |
77 | 78 |
|
78 | 79 | finally |
79 | 80 | Pkg.activate(orig_project_toml_path) |
| 81 | + pop!(LOAD_PATH) |
| 82 | + @test orig_load_path == LOAD_PATH |
80 | 83 | end |
81 | 84 | end |
82 | 85 | end |
|
90 | 93 | if VERSION >= v"1.11" |
91 | 94 | @testset "activate with [sources]" begin |
92 | 95 | orig_project_toml_path = Base.active_project() |
| 96 | + orig_load_path = copy(LOAD_PATH) |
93 | 97 | push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing |
94 | | - orig_load_path = Base.LOAD_PATH |
95 | 98 | try |
96 | 99 | Pkg.activate(joinpath(@__DIR__, "sources", "MainEnv")) |
97 | 100 | TestEnv.activate() |
98 | 101 | new_project_toml_path = Base.active_project() |
99 | 102 | @test new_project_toml_path != orig_project_toml_path |
100 | | - @test orig_load_path == Base.LOAD_PATH |
101 | 103 | @eval using MainEnv |
102 | 104 | @test isdefined(@__MODULE__, :MainEnv) |
103 | 105 | @test MainEnv.bar() == 42 |
104 | 106 | finally |
105 | 107 | Pkg.activate(orig_project_toml_path) |
| 108 | + pop!(LOAD_PATH) |
| 109 | + @test orig_load_path == LOAD_PATH |
106 | 110 | end |
107 | 111 | end |
108 | 112 | @testset "activate with [sources] and two Project.toml approach" begin |
109 | 113 | orig_project_toml_path = Base.active_project() |
| 114 | + orig_load_path = copy(LOAD_PATH) |
110 | 115 | push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing |
111 | | - orig_load_path = Base.LOAD_PATH |
112 | 116 | try |
113 | 117 | Pkg.activate(joinpath(@__DIR__, "sources", "MainTestProjectEnv")) |
114 | 118 | TestEnv.activate() |
115 | 119 | new_project_toml_path = Base.active_project() |
116 | 120 | @test new_project_toml_path != orig_project_toml_path |
117 | | - @test orig_load_path == Base.LOAD_PATH |
118 | 121 | @eval using MainTestProjectEnv |
119 | 122 | @test isdefined(@__MODULE__, :MainTestProjectEnv) |
120 | 123 | @test MainTestProjectEnv.bar() == 42 |
121 | 124 | finally |
122 | 125 | Pkg.activate(orig_project_toml_path) |
| 126 | + pop!(LOAD_PATH) |
| 127 | + @test orig_load_path == LOAD_PATH |
123 | 128 | end |
124 | 129 | end |
125 | 130 | end |
126 | 131 |
|
127 | 132 | if VERSION >= v"1.12-" |
128 | 133 | @testset "activate [workspace] test env" begin |
129 | 134 | orig_project_toml_path = Base.active_project() |
| 135 | + orig_load_path = copy(LOAD_PATH) |
130 | 136 | push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing |
131 | | - orig_load_path = Base.LOAD_PATH |
132 | 137 | try |
133 | 138 | Pkg.activate(joinpath(@__DIR__, "sources", "WorkspaceTestEnv")) |
134 | 139 | TestEnv.activate() |
135 | 140 | new_project_toml_path = Base.active_project() |
136 | 141 | @test new_project_toml_path != orig_project_toml_path |
137 | | - @test orig_load_path == Base.LOAD_PATH |
138 | 142 | @eval using WorkspaceTestEnv |
139 | 143 | @test isdefined(@__MODULE__, :WorkspaceTestEnv) |
140 | 144 | @test WorkspaceTestEnv.foo() == 42 |
141 | 145 | finally |
142 | 146 | Pkg.activate(orig_project_toml_path) |
| 147 | + pop!(LOAD_PATH) |
| 148 | + @test orig_load_path == LOAD_PATH |
| 149 | + end |
| 150 | + end |
| 151 | + end |
| 152 | + |
| 153 | + if VERSION >= v"1.6" # JULIA_PKG_PRECOMPILE_AUTO was introduced in 1.6 |
| 154 | + @testset "JULIA_PKG_PRECOMPILE_AUTO compatibility" begin |
| 155 | + mktempdir() do p |
| 156 | + withenv("JULIA_PKG_PRECOMPILE_AUTO" => "0") do |
| 157 | + orig_load_path = copy(LOAD_PATH) |
| 158 | + push!(empty!(LOAD_PATH), p) |
| 159 | + |
| 160 | + # Restrict the depot path to avoid grabbing a precompiled version from a |
| 161 | + # stacked environment |
| 162 | + orig_depot_path = copy(DEPOT_PATH) |
| 163 | + push!(empty!(DEPOT_PATH), mkdir(joinpath(p, ".julia"))) |
| 164 | + |
| 165 | + try |
| 166 | + Pkg.activate(p) |
| 167 | + orig_project_toml_path = Base.active_project() |
| 168 | + try |
| 169 | + Pkg.develop(PackageSpec(path=pkgdir(TestEnv))) |
| 170 | + Pkg.add(PackageSpec(name="Example")) |
| 171 | + try |
| 172 | + TestEnv.activate("Example") |
| 173 | + if VERSION < v"1.10" # Base.isprecompiled was added in 1.10 |
| 174 | + cache_dir = Base.compilecache_dir(Base.identify_package("Example")) |
| 175 | + @test !isdir(cache_dir) || isempty(readdir(cache_dir)) |
| 176 | + else |
| 177 | + @test !Base.isprecompiled(Base.identify_package("Example")) |
| 178 | + end |
| 179 | + catch e |
| 180 | + @error "Error during TestEnv.activate/isprecompiled check" exception=(e, catch_backtrace()) |
| 181 | + @test false |
| 182 | + end |
| 183 | + new_project_toml_path = Base.active_project() |
| 184 | + @test new_project_toml_path != orig_project_toml_path |
| 185 | + finally |
| 186 | + Pkg.activate(orig_project_toml_path) |
| 187 | + end |
| 188 | + finally |
| 189 | + if isdefined(@__MODULE__, :orig_load_path) |
| 190 | + pop!(LOAD_PATH) |
| 191 | + append!(LOAD_PATH, orig_load_path) |
| 192 | + end |
| 193 | + if isdefined(@__MODULE__, :orig_depot_path) |
| 194 | + pop!(DEPOT_PATH) |
| 195 | + append!(DEPOT_PATH, orig_depot_path) |
| 196 | + end |
| 197 | + end |
| 198 | + end |
143 | 199 | end |
144 | 200 | end |
145 | 201 | end |
|
0 commit comments