diff --git a/src/ambiguities.jl b/src/ambiguities.jl index 4491a49b..c5b7330e 100644 --- a/src/ambiguities.jl +++ b/src/ambiguities.jl @@ -25,31 +25,29 @@ false-positive. - Other keyword arguments such as `imported` and `ambiguous_bottom` are passed to `Test.detect_ambiguities` as-is. """ -test_ambiguities(packages; kwargs...) = _test_ambiguities(aspkgids(packages); kwargs...) +test_ambiguities(packages; kwargs...) = test_ambiguities(aspkgids(packages); kwargs...) -const ExcludeSpec = Pair{Base.PkgId,String} +function test_ambiguities(packages::Vector{PkgId}; broken::Bool = false, kwargs...) + num_ambiguities, strout, strerr = Ambiguities.find_ambiguities(packages; kwargs...) -aspkgids(pkg::Union{Module,PkgId}) = aspkgids([pkg]) -aspkgids(packages) = mapfoldl(aspkgid, push!, packages, init = PkgId[]) + println(stderr, strerr) + println(stdout, strout) -aspkgid(pkg::PkgId) = pkg -function aspkgid(m::Module) - if !ispackage(m) - error("Non-package (non-toplevel) module is not supported. Got: $m") + if broken + @test_broken num_ambiguities == 0 + else + @test num_ambiguities == 0 end - return PkgId(m) -end -function aspkgid(name::Symbol) - # Maybe `Base.depwarn()` - return Base.identify_package(String(name))::PkgId end -ispackage(m::Module) = - if m in (Base, Core) - true - else - parentmodule(m) == m - end +module Ambiguities + +using Base: PkgId +using Test: detect_ambiguities + +using ..Aqua: checked_repr, reprpkgid + +const ExcludeSpec = Pair{Base.PkgId,String} strnameof(x) = string(x) strnameof(x::Type) = string(nameof(x)) @@ -81,23 +79,10 @@ function reprexclude(exspecs::Vector{ExcludeSpec}) itemreprs = map(exspecs) do (pkgid, name) string("(", reprpkgid(pkgid), " => ", repr(name), ")") end - return string("Aqua.ExcludeSpec[", join(itemreprs, ", "), "]") + return string("Aqua.Ambiguities.ExcludeSpec[", join(itemreprs, ", "), "]") end -function _test_ambiguities(packages::Vector{PkgId}; broken::Bool = false, kwargs...) - num_ambiguities, strout, strerr = _find_ambiguities(packages; kwargs...) - - println(stderr, strerr) - println(stdout, strout) - - if broken - @test_broken num_ambiguities == 0 - else - @test num_ambiguities == 0 - end -end - -function _find_ambiguities( +function find_ambiguities( packages::Vector{PkgId}; color::Union{Bool,Nothing} = nothing, exclude::AbstractVector = [], @@ -113,7 +98,7 @@ function _find_ambiguities( code = """ $(Base.load_path_setup_code()) using Aqua - Aqua.test_ambiguities_impl( + Aqua.Ambiguities.test_ambiguities_impl( $packages_repr, $options_repr, $exclude_repr, @@ -153,15 +138,6 @@ function reprpkgids(packages::Vector{PkgId}) return packages_repr end -function reprpkgid(pkg::PkgId) - name = pkg.name - if pkg.uuid === nothing - return "Base.PkgId($(repr(name)))" - end - uuid = pkg.uuid.value - return "Base.PkgId(Base.UUID($(repr(uuid))), $(repr(name)))" -end - struct _NoValue end function getobj(m::Method) @@ -252,3 +228,5 @@ function ambiguity_hint(m1::Method, m2::Method) end end end + +end # module diff --git a/src/utils.jl b/src/utils.jl index 0179714e..33ab30ca 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -12,6 +12,33 @@ function askwargs(flag::Bool) return NamedTuple() end +aspkgids(pkg::Union{Module,PkgId}) = aspkgids([pkg]) +aspkgids(packages) = map(aspkgid, packages) + +aspkgid(pkg::PkgId) = pkg +function aspkgid(m::Module) + if !ispackage(m) + error("Non-package (non-toplevel) module is not supported. Got: $m") + end + return PkgId(m) +end + +ispackage(m::Module) = + if m in (Base, Core) + true + else + parentmodule(m) == m + end + +function reprpkgid(pkg::PkgId) + name = pkg.name + if pkg.uuid === nothing + return "Base.PkgId($(repr(name)))" + end + uuid = pkg.uuid.value + return "Base.PkgId(Base.UUID($(repr(uuid))), $(repr(name)))" +end + struct LazyTestResult label::String message::String diff --git a/test/test_ambiguities.jl b/test/test_ambiguities.jl index ad2d8557..33a7051c 100644 --- a/test/test_ambiguities.jl +++ b/test/test_ambiguities.jl @@ -2,12 +2,15 @@ module TestAmbiguities include("preamble.jl") +using Aqua: Ambiguities + using PkgWithAmbiguities @testset begin function check_testcase(exclude, num_ambiguities::Int; broken::Bool = false) pkgids = Aqua.aspkgids([PkgWithAmbiguities, Core]) # include Core to find constructor ambiguities - num_ambiguities_, strout, strerr = Aqua._find_ambiguities(pkgids; exclude = exclude) + num_ambiguities_, strout, strerr = + Ambiguities.find_ambiguities(pkgids; exclude = exclude) if broken @test_broken num_ambiguities_ == num_ambiguities else diff --git a/test/test_exclude.jl b/test/test_exclude.jl index 6eca9659..4f15c2a7 100644 --- a/test/test_exclude.jl +++ b/test/test_exclude.jl @@ -1,8 +1,11 @@ module TestExclude include("preamble.jl") + using Base: PkgId -using Aqua: getobj, normalize_exclude, normalize_and_check_exclude, rootmodule, reprexclude + +using Aqua.Ambiguities: + getobj, normalize_exclude, normalize_and_check_exclude, rootmodule, reprexclude @assert parentmodule(Tuple) === Core @assert parentmodule(foldl) === Base diff --git a/test/test_getobj.jl b/test/test_getobj.jl index 48acc11c..01096c18 100644 --- a/test/test_getobj.jl +++ b/test/test_getobj.jl @@ -1,6 +1,6 @@ module TestGetObj -using Aqua: getobj +using Aqua.Ambiguities: getobj using Test module ModuleA