@@ -4,6 +4,32 @@ using Test, UUIDs, Dates, TOML
44import .. Pkg, LibGit2
55using .. Utils
66
7+ # used with the reference manifests in `test/manifest/formats`
8+ # ensures the manifests are valid and restored after test
9+ function reference_manifest_isolated_test (f, dir:: String ; v1:: Bool = false )
10+ env_dir = joinpath (@__DIR__ , " manifest" , " formats" , dir)
11+ env_manifest = joinpath (env_dir, " Manifest.toml" )
12+ env_project = joinpath (env_dir, " Project.toml" )
13+ cp (env_manifest, string (env_manifest, " _backup" ))
14+ cp (env_project, string (env_project, " _backup" ))
15+ try
16+ isfile (env_manifest) || error (" Reference manifest is missing" )
17+ if Base. is_v1_format_manifest (Base. parsed_toml (env_manifest)) == ! v1
18+ error (" Reference manifest file at $(env_manifest) is invalid" )
19+ end
20+ isolate (loaded_depot= true ) do
21+ f (env_dir, env_manifest)
22+ end
23+ finally
24+ cp (string (env_manifest, " _backup" ), env_manifest, force = true )
25+ rm (string (env_manifest, " _backup" ))
26+ cp (string (env_project, " _backup" ), env_project, force = true )
27+ rm (string (env_project, " _backup" ))
28+ end
29+ end
30+
31+ # #
32+
733@testset " Manifest.toml formats" begin
834 @testset " Default manifest format is v2" begin
935 isolate (loaded_depot= true ) do
@@ -19,13 +45,7 @@ using ..Utils
1945 end
2046
2147 @testset " v1.0: activate, change, maintain manifest format" begin
22- env_dir = joinpath (@__DIR__ , " manifest" , " formats" , " v1.0" )
23- env_manifest = joinpath (env_dir, " Manifest.toml" )
24- isfile (env_manifest) || error (" Reference manifest is missing" )
25- if Base. is_v1_format_manifest (Base. parsed_toml (env_manifest)) == false
26- error (" Reference manifest file at $(env_manifest) is invalid" )
27- end
28- isolate (loaded_depot= true ) do
48+ reference_manifest_isolated_test (" v1.0" , v1 = true ) do env_dir, env_manifest
2949 io = IOBuffer ()
3050 Pkg. activate (env_dir; io= io)
3151 output = String (take! (io))
@@ -41,13 +61,7 @@ using ..Utils
4161 end
4262
4363 @testset " v2.0: activate, change, maintain manifest format" begin
44- env_dir = joinpath (@__DIR__ , " manifest" , " formats" , " v2.0" )
45- env_manifest = joinpath (env_dir, " Manifest.toml" )
46- isfile (env_manifest) || error (" Reference manifest is missing" )
47- if Base. is_v1_format_manifest (Base. parsed_toml (env_manifest))
48- error (" Reference manifest file at $(env_manifest) is invalid" )
49- end
50- isolate (loaded_depot= true ) do
64+ reference_manifest_isolated_test (" v2.0" ) do env_dir, env_manifest
5165 io = IOBuffer ()
5266 Pkg. activate (env_dir; io= io)
5367 output = String (take! (io))
@@ -72,50 +86,69 @@ using ..Utils
7286 @test m. manifest_format == m2. manifest_format
7387 @test m. other == m2. other
7488 end
75-
7689 end
7790 end
7891
7992 @testset " v3.0: unknown format, warn" begin
8093 # the reference file here is not actually v3.0. It just represents an unknown manifest format
81- env_dir = joinpath (@__DIR__ , " manifest" , " formats" , " v3.0_unknown" )
82- env_manifest = joinpath (env_dir, " Manifest.toml" )
83- isfile (env_manifest) || error (" Reference manifest is missing" )
84- isolate (loaded_depot= true ) do
94+ reference_manifest_isolated_test (" v3.0_unknown" ) do env_dir, env_manifest
8595 io = IOBuffer ()
8696 @test_logs (:warn ,) Pkg. activate (env_dir; io= io)
8797 end
8898 end
8999
90100 @testset " Pkg.upgrade_manifest()" begin
91- env_dir = joinpath (@__DIR__ , " manifest" , " formats" , " v1.0" )
92- env_manifest = joinpath (env_dir, " Manifest.toml" )
93- cp (env_manifest, string (env_manifest, " _backup" ))
94- try
95- isfile (env_manifest) || error (" Reference manifest is missing" )
96- if Base. is_v1_format_manifest (Base. parsed_toml (env_manifest)) == false
97- error (" Reference manifest file at $(env_manifest) is invalid" )
98- end
101+ reference_manifest_isolated_test (" v1.0" , v1 = true ) do env_dir, env_manifest
102+ io = IOBuffer ()
103+ Pkg. activate (env_dir; io= io)
104+ output = String (take! (io))
105+ @test occursin (r" Activating.*project at.*`.*v1.0`" , output)
106+ @test Base. is_v1_format_manifest (Base. parsed_toml (env_manifest))
107+
108+ Pkg. upgrade_manifest ()
109+ @test Base. is_v1_format_manifest (Base. parsed_toml (env_manifest)) == false
110+ Pkg. activate (env_dir; io= io)
111+ output = String (take! (io))
112+ @test occursin (r" Activating.*project at.*`.*v1.0`" , output)
113+ @test Pkg. Types. Context (). env. manifest. manifest_format == v " 2.0.0"
114+ end
115+ end
116+ end
117+
118+ @testset " Manifest metadata" begin
119+ @testset " julia_version" begin
120+ @testset " new environment: value is `nothing`, then `VERSION` after resolve" begin
99121 isolate (loaded_depot= true ) do
100- io = IOBuffer ()
101- Pkg. activate (env_dir; io= io)
102- output = String (take! (io))
103- @test occursin (r" Activating.*project at.*`.*v1.0`" , output)
104- @test Base. is_v1_format_manifest (Base. parsed_toml (env_manifest))
105-
106- Pkg. upgrade_manifest ()
107- @test Base. is_v1_format_manifest (Base. parsed_toml (env_manifest)) == false
108- Pkg. activate (env_dir; io= io)
109- output = String (take! (io))
110- @test occursin (r" Activating.*project at.*`.*v1.0`" , output)
111- @test Pkg. Types. Context (). env. manifest. manifest_format == v " 2.0.0"
122+ Pkg. activate (; temp= true )
123+ @test Pkg. Types. Context (). env. manifest. julia_version == nothing
124+ Pkg. add (" Profile" )
125+ @test Pkg. Types. Context (). env. manifest. julia_version == VERSION
126+ end
127+ end
128+ @testset " activating old environment: maintains old version, then `VERSION` after resolve" begin
129+ reference_manifest_isolated_test (" v2.0" ) do env_dir, env_manifest
130+ Pkg. activate (env_dir)
131+ @test Pkg. Types. Context (). env. manifest. julia_version == v " 1.7.0-DEV.1199"
132+
133+ Pkg. add (" Profile" )
134+ @test Pkg. Types. Context (). env. manifest. julia_version == VERSION
135+ end
136+ end
137+ @testset " instantiate manifest from different julia_version" begin
138+ reference_manifest_isolated_test (" v1.0" , v1 = true ) do env_dir, env_manifest
139+ Pkg. activate (env_dir)
140+ @test_logs (:warn , r" The active manifest file" ) Pkg. instantiate ()
141+ @test Pkg. Types. Context (). env. manifest. julia_version == nothing
142+ end
143+ if VERSION >= v " 1.8"
144+ reference_manifest_isolated_test (" v2.0" ) do env_dir, env_manifest
145+ Pkg. activate (env_dir)
146+ @test_logs (:warn , r" The active manifest file" ) Pkg. instantiate ()
147+ @test Pkg. Types. Context (). env. manifest. julia_version == v " 1.7.0-DEV.1199"
148+ end
112149 end
113- finally
114- cp (string (env_manifest, " _backup" ), env_manifest, force = true )
115- rm (string (env_manifest, " _backup" ))
116150 end
117151 end
118152end
119153
120-
121154end # module
0 commit comments