132
132
@test_throws ArgumentError parse (UUID, " not a UUID" )
133
133
@test tryparse (UUID, " either is this" ) === nothing
134
134
135
- function subset (v:: Vector{T} , m:: Int ) where T
136
- T[v[j] for j = 1 : length (v) if ((m >>> (j - 1 )) & 1 ) == 1 ]
137
- end
138
-
139
- function perm (p:: Vector , i:: Int )
140
- for j = length (p): - 1 : 1
141
- i, k = divrem (i, j)
142
- p[j], p[k+ 1 ] = p[k+ 1 ], p[j]
143
- end
144
- return p
145
- end
146
-
147
135
@testset " explicit_project_deps_get" begin
148
136
mktempdir () do dir
149
137
project_file = joinpath (dir, " Project.toml" )
@@ -152,39 +140,40 @@ end
152
140
proj_uuid = dummy_uuid (project_file)
153
141
root_uuid = uuid4 ()
154
142
this_uuid = uuid4 ()
155
- # project file to subset/permute
156
- lines = split ("""
157
- name = "Root"
158
- uuid = "$root_uuid "
159
- [deps]
160
- This = "$this_uuid "
161
- """ , ' \n ' )
162
- N = length (lines)
163
- # test every permutation of every subset of lines
164
- for m = 0 : 2 ^ N- 1
165
- s = subset (lines, m) # each subset of lines
166
- for i = 1 : factorial (count_ones (m))
167
- p = perm (s, i) # each permutation of the subset
168
- open (project_file, write= true ) do io
169
- for line in p
170
- println (io, line)
171
- end
172
- end
173
- # look at lines and their order
174
- n = findfirst (line -> startswith (line, " name" ), p)
175
- u = findfirst (line -> startswith (line, " uuid" ), p)
176
- d = findfirst (line -> line == " [deps]" , p)
177
- t = findfirst (line -> startswith (line, " This" ), p)
178
- # look up various packages by name
179
- root = Base. explicit_project_deps_get (project_file, " Root" )
180
- this = Base. explicit_project_deps_get (project_file, " This" )
181
- that = Base. explicit_project_deps_get (project_file, " That" )
182
- # test that the correct answers are given
183
- @test root == (something (n, N+ 1 ) ≥ something (d, N+ 1 ) ? nothing :
184
- something (u, N+ 1 ) < something (d, N+ 1 ) ? root_uuid : proj_uuid)
185
- @test this == (something (d, N+ 1 ) < something (t, N+ 1 ) ≤ N ? this_uuid : nothing )
186
- @test that == nothing
187
- end
143
+
144
+ old_load_path = copy (LOAD_PATH )
145
+ try
146
+ copy! (LOAD_PATH , [project_file])
147
+ write (project_file, """
148
+ name = "Root"
149
+ uuid = "$root_uuid "
150
+ [deps]
151
+ This = "$this_uuid "
152
+ """ )
153
+ # look up various packages by name
154
+ root = Base. identify_package (" Root" )
155
+ this = Base. identify_package (" This" )
156
+ that = Base. identify_package (" That" )
157
+
158
+ @test root. uuid == root_uuid
159
+ @test this. uuid == this_uuid
160
+ @test that == nothing
161
+
162
+ write (project_file, """
163
+ name = "Root"
164
+ This = "$this_uuid "
165
+ [deps]
166
+ """ )
167
+ # look up various packages by name
168
+ root = Base. identify_package (" Root" )
169
+ this = Base. identify_package (" This" )
170
+ that = Base. identify_package (" That" )
171
+
172
+ @test root. uuid == proj_uuid
173
+ @test this == nothing
174
+ @test that == nothing
175
+ finally
176
+ copy! (LOAD_PATH , old_load_path)
188
177
end
189
178
end
190
179
end
0 commit comments