diff --git a/test/pkgs/PkgWithAmbiguities.jl b/test/pkgs/PkgWithAmbiguities.jl index 7dbf1755..64ac9fd3 100644 --- a/test/pkgs/PkgWithAmbiguities.jl +++ b/test/pkgs/PkgWithAmbiguities.jl @@ -3,6 +3,15 @@ module PkgWithAmbiguities # 1 ambiguity f(::Any, ::Int) = 1 f(::Int, ::Any) = 2 +const num_ambs_f = 1 + +# 2 ambiguities: +# 1 for g +# 1 for Core.kwfunc(g) if VERSION >= 1.4 +# 2 for Core.kwfunc(g) if VERSION < 1.4 +g(::Any, ::Int; kw) = 1 +g(::Int, ::Any; kw) = 2 +const num_ambs_g = VERSION >= v"1.4-" ? 2 : 3 abstract type AbstractType end struct SingletonType <: AbstractType end @@ -20,6 +29,8 @@ SingletonType(::Int, ::Any, ::Any) = 3 (::SingletonType)(::Any, ::Float64) = 1 (::SingletonType)(::Float64, ::Any) = 2 +const num_ambs_SingletonType = 3 + # 3 ambiguities ConcreteType(::Any, ::Any, ::Int) = 1 ConcreteType(::Any, ::Int, ::Any) = 2 @@ -29,12 +40,17 @@ ConcreteType(::Int, ::Any, ::Any) = 3 (::ConcreteType)(::Any, ::Float64) = 1 (::ConcreteType)(::Float64, ::Any) = 2 +const num_ambs_ConcreteType = 4 + @static if VERSION >= v"1.3-" + # 1 ambiguity if VERSION >= 1.3 abstract type AbstractParameterizedType{T} end struct ConcreteParameterizedType{T} <: AbstractParameterizedType{T} end (::AbstractParameterizedType{T})(::Tuple{Tuple{Int}}) where {T} = 1 (::ConcreteParameterizedType)(::Tuple) = 2 + + const num_ambs_ParameterizedType = 1 end end # module diff --git a/test/test_ambiguities.jl b/test/test_ambiguities.jl index ad2d8557..5b7845d4 100644 --- a/test/test_ambiguities.jl +++ b/test/test_ambiguities.jl @@ -2,9 +2,28 @@ module TestAmbiguities include("preamble.jl") -using PkgWithAmbiguities - @testset begin + using PkgWithAmbiguities + + @static if VERSION >= v"1.3-" + using PkgWithAmbiguities: + num_ambs_f, + num_ambs_g, + num_ambs_SingletonType, + num_ambs_ConcreteType, + num_ambs_ParameterizedType + total = + num_ambs_f + + num_ambs_g + + num_ambs_SingletonType + + num_ambs_ConcreteType + + num_ambs_ParameterizedType + else + using PkgWithAmbiguities: + num_ambs_f, num_ambs_g, num_ambs_SingletonType, num_ambs_ConcreteType + total = num_ambs_f + num_ambs_g + num_ambs_SingletonType + num_ambs_ConcreteType + end + 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) @@ -16,51 +35,58 @@ using PkgWithAmbiguities @test isempty(strerr) end - @static if VERSION >= v"1.3-" - total = 9 - else - total = 8 - end - check_testcase([], total) # exclude just anything irrelevant, see #49 check_testcase([convert], total) # exclude function - check_testcase([PkgWithAmbiguities.f], total - 1) + check_testcase([PkgWithAmbiguities.f], total - num_ambs_f) + + # exclude function and kwsorter + check_testcase([PkgWithAmbiguities.g], total - num_ambs_g; broken = true) # exclude callables and constructors - check_testcase([PkgWithAmbiguities.SingletonType], total - 2 - 1) - check_testcase([PkgWithAmbiguities.ConcreteType], total - 3 - 1) + check_testcase([PkgWithAmbiguities.SingletonType], total - num_ambs_SingletonType) + check_testcase([PkgWithAmbiguities.ConcreteType], total - num_ambs_ConcreteType) # exclude abstract supertype without callables and constructors check_testcase([PkgWithAmbiguities.AbstractType], total) @static if VERSION >= v"1.3-" # for ambiguities between abstract and concrete type callables, only one needs to be excluded - check_testcase([PkgWithAmbiguities.AbstractParameterizedType], total - 1) - check_testcase([PkgWithAmbiguities.ConcreteParameterizedType], total - 1) + check_testcase( + [PkgWithAmbiguities.AbstractParameterizedType], + total - num_ambs_ParameterizedType, + ) + check_testcase( + [PkgWithAmbiguities.ConcreteParameterizedType], + total - num_ambs_ParameterizedType, + ) # exclude everything check_testcase( [ PkgWithAmbiguities.f, + PkgWithAmbiguities.g, PkgWithAmbiguities.SingletonType, PkgWithAmbiguities.ConcreteType, PkgWithAmbiguities.ConcreteParameterizedType, ], - 0, + 0; + broken = true, ) else # exclude everything check_testcase( [ PkgWithAmbiguities.f, + PkgWithAmbiguities.g, PkgWithAmbiguities.SingletonType, PkgWithAmbiguities.ConcreteType, ], - 0, + 0; + broken = true, ) end