diff --git a/src/unbound_args.jl b/src/unbound_args.jl index a6413f5e..a2c65265 100644 --- a/src/unbound_args.jl +++ b/src/unbound_args.jl @@ -1,17 +1,35 @@ """ test_unbound_args(module::Module) + test_unbound_args(unbounds) Test that all methods in `module` and its submodules do not have unbound type parameters. An unbound type parameter is a type parameter with a `where`, that does not occur in the signature of some dispatch -of the method. +of the method. If unbounds methods are already known, they can be +passed directly to the function instead of the module. # Keyword Arguments - `broken::Bool = false`: If true, it uses `@test_broken` instead of `@test` and shortens the error message. +- `ignore::Vector{Tuple{Function, DataType...}}`: A list of functions and their + signatures to ignore. The signatures are given as tuples, where the + first element is the function and the rest are the types of the + arguments. For example, to ignore `foo(x::Int, y::Float64)`, pass + `(foo, Int, Float64)`. """ -function test_unbound_args(m::Module; broken::Bool = false) +function test_unbound_args(m::Module; broken::Bool = false, ignore = ()) unbounds = detect_unbound_args_recursively(m) + for i in ignore + # i[2:end] is empty if length(i) == 1 + ignore_signature = Tuple{typeof(i[1]),i[2:end]...} + filter!(unbounds) do method + method.sig != ignore_signature + end + end + test_unbound_args(unbounds; broken = broken) +end + +function test_unbound_args(unbounds; broken::Bool = false) if broken if !isempty(unbounds) printstyled( diff --git a/test/pkgs/PkgUnboundArgs.jl b/test/pkgs/PkgUnboundArgs.jl index 4eb5e27b..ee597f0b 100644 --- a/test/pkgs/PkgUnboundArgs.jl +++ b/test/pkgs/PkgUnboundArgs.jl @@ -7,4 +7,9 @@ end # `_totuple` is taken from # https://github.com/JuliaLang/julia/blob/48634f9f8669e1dc1be0a1589cd5be880c04055a/test/ambiguous.jl#L257-L259 +# taken from https://github.com/JuliaTesting/Aqua.jl/issues/86 +module Issue86 +f(::NTuple{N,T}) where {N,T} = (N, T) +f(::Tuple{}) = (0, Any) +end end # module diff --git a/test/test_unbound_args.jl b/test/test_unbound_args.jl index 97206032..6cc113a2 100644 --- a/test/test_unbound_args.jl +++ b/test/test_unbound_args.jl @@ -13,6 +13,14 @@ using PkgUnboundArgs @test length(results) == 1 @test results[1] isa Test.Fail + Aqua.test_unbound_args( + PkgUnboundArgs, + ignore = [ + (PkgUnboundArgs.M25341._totuple, Type{Tuple{Vararg{E}}} where {E}, Any, Vararg), + (PkgUnboundArgs.Issue86.f, NTuple), + ], + ) + # It works with other tests: Aqua.test_ambiguities(PkgUnboundArgs) Aqua.test_undefined_exports(PkgUnboundArgs)