Skip to content

Commit

Permalink
add ignore keyword for specific methods in test_unbound_args
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-ma committed Jan 8, 2025
1 parent 1fca5d9 commit a9f275a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/unbound_args.jl
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
5 changes: 5 additions & 0 deletions test/pkgs/PkgUnboundArgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions test/test_unbound_args.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a9f275a

Please sign in to comment.