Skip to content

Commit 0496961

Browse files
committed
Test ambiguities in package extension
1 parent 067e6ac commit 0496961

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed

src/ambiguities.jl

+72-9
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,87 @@ function reprexclude(exspecs::Vector{ExcludeSpec})
8484
return string("Aqua.ExcludeSpec[", join(itemreprs, ", "), "]")
8585
end
8686

87-
function _test_ambiguities(packages::Vector{PkgId}; broken::Bool = false, kwargs...)
88-
num_ambiguities, strout, strerr = _find_ambiguities(packages; kwargs...)
87+
function _test_ambiguities(
88+
packages::Vector{PkgId};
89+
broken::Bool = false,
90+
extension_combinations = :default,
91+
kwargs...,
92+
)
93+
if extension_combinations == :default
94+
extension_combinations = Vector{String}[]
95+
push!(extension_combinations, String[])
96+
@static if JULIA_HAS_EXTENSIONS
97+
all_exts = String[]
98+
for pkg in setdiff(packages, [PkgId(Base), PkgId(Core)])
99+
exts, _, _ = get_extension_data_from_toml(pkg)
100+
for e in keys(exts)
101+
push!(extension_combinations, [e])
102+
end
103+
push!(extension_combinations, collect(keys(exts)))
104+
append!(all_exts, collect(keys(exts)))
105+
end
106+
push!(extension_combinations, all_exts)
107+
end
108+
unique!(extension_combinations)
109+
end
110+
for extensions in extension_combinations
111+
@info "Testing ambiguities with extensions: $extensions"
112+
num_ambiguities, strout, strerr =
113+
_find_ambiguities(packages; extensions = extensions, kwargs...)
89114

90-
print(stderr, strerr)
91-
print(stdout, strout)
115+
print(stderr, strerr)
116+
print(stdout, strout)
92117

93-
if broken
94-
@test_broken num_ambiguities == 0
95-
else
96-
@test num_ambiguities == 0
118+
if broken
119+
@test_broken num_ambiguities == 0
120+
else
121+
@test num_ambiguities == 0
122+
end
97123
end
124+
98125
end
99126

100127
function _find_ambiguities(
101128
packages::Vector{PkgId};
102129
color::Union{Bool,Nothing} = nothing,
103130
exclude::AbstractVector = [],
131+
extensions::AbstractVector = [],
104132
# Options to be passed to `Test.detect_ambiguities`:
105133
detect_ambiguities_options...,
106134
)
135+
packages = copy(packages)
136+
extdeppackages = PkgId[]
137+
@static if JULIA_HAS_EXTENSIONS
138+
extensions = String.(extensions)
139+
for ext in extensions
140+
found = false
141+
for pkg in setdiff(packages, [PkgId(Base), PkgId(Core)])
142+
exts, weakdeps, deps = get_extension_data_from_toml(pkg)
143+
if haskey(exts, ext)
144+
found = true
145+
extdeps = exts[ext] isa String ? [exts[ext]] : exts[ext]
146+
for extdepname in extdeps
147+
if haskey(deps, extdepname)
148+
push!(extdeppackages, deps[extdepname])
149+
elseif haskey(weakdeps, extdepname)
150+
push!(extdeppackages, weakdeps[extdepname])
151+
else
152+
error(
153+
"Extension $ext depends on $extdepname, but it is not found.",
154+
)
155+
end
156+
end
157+
push!(packages, PkgId(Base.uuid5(pkg.uuid, ext), ext))
158+
break
159+
end
160+
end
161+
found && continue
162+
error("Extension $ext is not found.")
163+
end
164+
end
165+
107166
packages_repr = reprpkgids(collect(packages))
167+
extdeppackages_repr = reprpkgids(collect(extdeppackages))
108168
options_repr = checked_repr((; recursive = true, detect_ambiguities_options...))
109169
exclude_repr = reprexclude(normalize_and_check_exclude(exclude))
110170

@@ -115,6 +175,7 @@ function _find_ambiguities(
115175
using Aqua
116176
Aqua.test_ambiguities_impl(
117177
$packages_repr,
178+
$extdeppackages_repr,
118179
$options_repr,
119180
$exclude_repr,
120181
) || exit(1)
@@ -143,7 +204,7 @@ end
143204

144205
function reprpkgids(packages::Vector{PkgId})
145206
packages_repr = sprint() do io
146-
println(io, '[')
207+
println(io, "Base.PkgId[")
147208
for pkg in packages
148209
println(io, reprpkgid(pkg))
149210
end
@@ -200,9 +261,11 @@ end
200261

201262
function test_ambiguities_impl(
202263
packages::Vector{PkgId},
264+
extdeppackages::Vector{PkgId},
203265
options::NamedTuple,
204266
exspecs::Vector{ExcludeSpec},
205267
)
268+
deps = map(Base.require, extdeppackages)
206269
modules = map(Base.require, packages)
207270
@debug "Testing method ambiguities" modules
208271
ambiguities = detect_ambiguities(modules...; options...)

src/utils.jl

+17
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ catch
9696
end
9797
end
9898

99+
function get_extension_data_from_toml(pkg::PkgId)
100+
root_project_path = root_project_or_failed_lazytest(pkg)
101+
root_project_path isa LazyTestResult &&
102+
return Dict{String,Any}(), Dict{String,Any}(), Dict{String,Any}()
103+
104+
@debug "Parsing `$root_project_path`"
105+
prj = TOML.parsefile(root_project_path)
106+
raw_exts = get(prj, "extensions", Dict{String,Any}())
107+
108+
raw_weakdeps = get(prj, "weakdeps", Dict{String,Any}())
109+
weakdeps = Dict(name => PkgId(UUID(uuid), name) for (name, uuid) in raw_weakdeps)
110+
111+
raw_deps = get(prj, "deps", Dict{String,Any}())
112+
deps = Dict(name => PkgId(UUID(uuid), name) for (name, uuid) in raw_deps)
113+
return raw_exts, weakdeps, deps
114+
end
115+
99116
const _project_key_order = [
100117
"name",
101118
"uuid",

0 commit comments

Comments
 (0)