@@ -79,11 +79,69 @@ mktempdir() do dir
79
79
end
80
80
end
81
81
82
+ # # unit tests of project parsing ##
83
+
82
84
import Base: SHA1, PkgId, load_path, identify_package, locate_package, version_slug, dummy_uuid
83
85
import UUIDs: UUID, uuid4, uuid_version
84
86
import Random: shuffle, randstring
85
87
using Test
86
88
89
+ function subset (v:: Vector{T} , m:: Int ) where T
90
+ T[v[j] for j = 1 : length (v) if ((m >>> (j - 1 )) & 1 ) == 1 ]
91
+ end
92
+
93
+ function perm (p:: Vector , i:: Int )
94
+ for j = length (p): - 1 : 1
95
+ i, k = divrem (i, j)
96
+ p[j], p[k+ 1 ] = p[k+ 1 ], p[j]
97
+ end
98
+ return p
99
+ end
100
+
101
+ @testset " explicit_project_deps_get" begin
102
+ project_file = " $(tempname ()) .toml"
103
+ touch (project_file) # dummy_uuid calls realpath
104
+ proj_uuid = dummy_uuid (project_file)
105
+ root_uuid = UUID (" 43306aae-ef21-43f3-9517-81724f2885ac" )
106
+ this_uuid = UUID (" b36283d3-af40-4a18-9ee0-d12ee9c142ac" )
107
+ lines = split ("""
108
+ name = "Root"
109
+ uuid = "$root_uuid "
110
+ [deps]
111
+ This = "$this_uuid "
112
+ """ , ' \n ' )
113
+ N = length (lines)
114
+ for m = 0 : 2 ^ N- 1
115
+ # for every subset of lines
116
+ s = subset (lines, m)
117
+ for i = 1 : factorial (count_ones (m))
118
+ # for every permutation of that subset
119
+ p = perm (s, i)
120
+ open (project_file, write= true ) do io
121
+ for line in p
122
+ println (io, line)
123
+ end
124
+ end
125
+ # look at lines and their order
126
+ n = findfirst (line -> startswith (line, " name" ), p)
127
+ u = findfirst (line -> startswith (line, " uuid" ), p)
128
+ d = findfirst (line -> line == " [deps]" , p)
129
+ t = findfirst (line -> startswith (line, " This" ), p)
130
+ # look up various packages by name
131
+ root = Base. explicit_project_deps_get (project_file, " Root" )
132
+ this = Base. explicit_project_deps_get (project_file, " This" )
133
+ that = Base. explicit_project_deps_get (project_file, " That" )
134
+ # test that the correct answers are given
135
+ @test root == (coalesce (n, N+ 1 ) ≥ coalesce (d, N+ 1 ) ? false :
136
+ coalesce (u, N+ 1 ) < coalesce (d, N+ 1 ) ? root_uuid : proj_uuid)
137
+ @test this == (coalesce (d, N+ 1 ) < coalesce (t, N+ 1 ) ≤ N ? this_uuid : false )
138
+ @test that == false
139
+ end
140
+ end
141
+ end
142
+
143
+ # # functional testing of package identification, location & loading ##
144
+
87
145
saved_load_path = copy (LOAD_PATH )
88
146
saved_depot_path = copy (DEPOT_PATH )
89
147
push! (empty! (LOAD_PATH ), " project" )
@@ -415,14 +473,14 @@ function test_find(
415
473
end
416
474
end
417
475
418
- @testset " identify_package with one env in load path" begin
476
+ @testset " find_package with one env in load path" begin
419
477
for (env, (_, _, roots, graph, paths)) in envs
420
478
push! (empty! (LOAD_PATH ), env)
421
479
test_find (roots, graph, paths)
422
480
end
423
481
end
424
482
425
- @testset " identify_package with two envs in load path" begin
483
+ @testset " find_package with two envs in load path" begin
426
484
for x = false : true ,
427
485
(env1, (_, _, roots1, graph1, paths1)) in (x ? envs : rand (envs, 10 )),
428
486
(env2, (_, _, roots2, graph2, paths2)) in (x ? rand (envs, 10 ) : envs)
434
492
end
435
493
end
436
494
437
- @testset " identify_package with three envs in load path" begin
495
+ @testset " find_package with three envs in load path" begin
438
496
for (env1, (_, _, roots1, graph1, paths1)) in rand (envs, 10 ),
439
497
(env2, (_, _, roots2, graph2, paths2)) in rand (envs, 10 ),
440
498
(env3, (_, _, roots3, graph3, paths3)) in rand (envs, 10 )
0 commit comments