@@ -7,103 +7,85 @@ Check that test target of the root project and test project
77Julia < 1.2 while recording test-only dependency compatibility in
88`test/Project.toml`.
99"""
10- function test_project_extras (packages)
11- @testset " $(result. label) " for result in analyze_project_extras (packages)
12- @debug result. label result
13- @test result ⊜ true
14- end
10+ function test_project_extras (pkg:: PkgId ; kwargs... )
11+ msgs = analyze_project_extras (pkg; kwargs... )
12+ @test isempty (msgs)
1513end
1614
17- function project_toml_path (dir)
18- candidates = joinpath .(dir, [ " Project.toml " , " JuliaProject.toml " ] )
19- i = findfirst (isfile, candidates)
20- i === nothing && return candidates[ 1 ], false
21- return candidates[i], true
15+ # Remove with next breaking version
16+ function test_project_extras (packages :: Vector{<:Union{Module,PkgId}} ; kwargs ... )
17+ @testset " $pkg " for pkg in packages
18+ test_project_extras (pkg; kwargs ... )
19+ end
2220end
2321
24- analyze_project_extras (packages) = map (_analyze_project_extras, aspkgids (packages))
22+ function test_project_extras (mod:: Module ; kwargs... )
23+ test_project_extras (aspkgid (mod); kwargs... )
24+ end
2525
2626is_julia12_or_later (compat:: AbstractString ) = is_julia12_or_later (semver_spec (compat))
2727is_julia12_or_later (compat:: VersionSpec ) = isempty (compat ∩ semver_spec (" 1.0 - 1.1" ))
2828
29- function _analyze_project_extras (pkg:: PkgId )
30- label = string (pkg)
29+ function analyze_project_extras (pkg:: PkgId )
30+ root_project_path, found = root_project_toml (pkg)
31+ found || error (" Unable to locate Project.toml" )
3132
32- result = root_project_or_failed_lazytest (pkg)
33- result isa LazyTestResult && return result
34- root_project_path = result
35-
36- package_loc = Base. locate_package (pkg)
37- package_loc === nothing &&
38- return LazyTestResult (label, " Base.locate_package failed." , false )
39- pkgpath = dirname (dirname (package_loc))
40- test_project_path, found = project_toml_path (joinpath (pkgpath, " test" ))
41- if ! found
42- return LazyTestResult (label, " test/Project.toml file does not exist." , true )
43- end
33+ test_project_path, found =
34+ project_toml_path (joinpath (dirname (root_project_path), " test" ))
35+ found || return String[] # having no test/Project.toml is fine
4436 root_project = TOML. parsefile (root_project_path)
4537 test_project = TOML. parsefile (test_project_path)
4638
4739 # Ignore root project's extras if only supporting julia 1.2 or later.
4840 # See: # https://julialang.github.io/Pkg.jl/v1/creating-packages/#Test-specific-dependencies-in-Julia-1.2-and-above-1
49- julia_version = get (get (root_project, " compat" , Dict ()), " julia" , " 1" )
50- if is_julia12_or_later (julia_version)
51- return LazyTestResult (
52- label,
53- string (
54- " Supporting only post-1.2 `julia` ($julia_version ); " ,
55- " ignoring root project." ,
56- ),
57- true ,
58- )
59- end
41+ julia_version = get (get (root_project, " compat" , Dict {String,Any} ()), " julia" , nothing )
42+ isnothing (julia_version) && return String[" Could not find `julia` compat." ]
43+ is_julia12_or_later (julia_version) && return String[]
6044
61- # `extras_deps`: test-only dependencies according to /Project.toml
62- all_extras_deps = get (root_project, " extras" , Dict ())
63- target = Set {String} (get (get (root_project, " targets" , Dict ()), " test" , []))
64- extras_deps = setdiff (
65- Set {Pair{String,String}} (p for p in all_extras_deps if first (p) in target),
66- Set {Pair{String,String}} (get (root_project, " deps" , [])),
45+ # `extras_test_deps`: test-only dependencies according to Project.toml
46+ deps = [PkgId (UUID (v), k) for (k, v) in get (root_project, " deps" , Dict {String,Any} ())]
47+ target =
48+ Set {String} (get (get (root_project, " targets" , Dict {String,Any} ()), " test" , String[]))
49+ extras_test_deps = setdiff (
50+ [
51+ PkgId (UUID (v), k) for
52+ (k, v) in get (root_project, " extras" , Dict {String,Any} ()) if k in target
53+ ],
54+ deps,
6755 )
6856
69- # `test_deps`: test-only dependencies according to / test/Project.toml:
57+ # `test_deps`: test-only dependencies according to test/Project.toml:
7058 test_deps = setdiff (
71- Set {Pair{String,String}} ( get (test_project, " deps" , [])) ,
72- Set {Pair{String,String}} ( get (root_project, " deps" , [])) ,
73- [root_project[" name " ] => root_project[" uuid " ] ],
59+ [ PkgId ( UUID (v), k) for (k, v) in get (test_project, " deps" , Dict {String,Any} ())] ,
60+ deps,
61+ [PkgId ( UUID ( root_project[" uuid " ]), root_project[" name " ]) ],
7462 )
7563
76- not_in_extras = setdiff (test_deps, extras_deps )
77- not_in_test = setdiff (extras_deps , test_deps)
64+ not_in_extras = setdiff (test_deps, extras_test_deps )
65+ not_in_test = setdiff (extras_test_deps , test_deps)
7866 if isempty (not_in_extras) && isempty (not_in_test)
79- return LazyTestResult (
80- label,
81- """
82- Root and test projects are consistent.
83- Root project: $root_project_path
84- Test project: $test_project_path
85- """ ,
86- true ,
87- )
67+ return String[]
8868 else
89- msg = sprint () do io
90- println (
91- io,
92- " Root and test projects should be consistent for projects supporting Julia <= 1.1." ,
93- )
94- if ! isempty (not_in_extras)
95- println (io, " Test dependencies not in root project ($root_project_path ):" )
96- for (name, uuid) in sort! (collect (not_in_extras))
97- println (io, " $name = \" $uuid \" " )
98- end
69+ msgs = String[]
70+ push! (
71+ msgs,
72+ " Root and test projects should be consistent for projects supporting Julia <= 1.1." ,
73+ )
74+ if ! isempty (not_in_extras)
75+ msg = " Test dependencies not in root project ($root_project_path ):"
76+ for pkgs in sort! (collect (not_in_extras); by = (pkg -> pkg. name))
77+ msg *= " \n\t $pkgs "
9978 end
100- if ! isempty (not_in_test)
101- println (io, " Dependencies not in test project ($test_project_path ):" )
102- for (name, uuid) in sort! (collect (not_in_test))
103- println (io, " $name = \" $uuid \" " )
104- end
79+ push! (msgs, msg)
80+ end
81+ if ! isempty (not_in_test)
82+ msg = " Dependencies not in test project ($test_project_path ):"
83+ for pkgs in sort! (collect (not_in_test); by = (pkg -> pkg. name))
84+ msg *= " \n\t $pkgs "
10585 end
86+ push! (msgs, msg)
10687 end
107- return LazyTestResult (label, msg, false )
88+
89+ return msgs
10890 end
10991end
0 commit comments