Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_unbound_args: add a functionality to ignore specific methods #316

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
10 changes: 9 additions & 1 deletion src/unbound_args.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ of the method.
# Keyword Arguments
- `broken::Bool = false`: If true, it uses `@test_broken` instead of
`@test` and shortens the error message.
- `exclude::AbstractVector = []`: A vector of signatures of methods to exclude
from testing. A signature is usually of the form `Tuple{typeof(f), T1, T2, ...}`.
where `f` is the function and `T1, T2, ...` the type parameters. For example, the
signature of `f(x::Float64, y)` is `Tuple{typeof(f), Float64, Any}`.
"""
function test_unbound_args(m::Module; broken::Bool = false)
function test_unbound_args(m::Module; broken::Bool = false, exclude = [])
unbounds = detect_unbound_args_recursively(m)
for signature in exclude
filter!(method -> (method.sig != signature), unbounds)
end

if broken
if !isempty(unbounds)
printstyled(
Expand Down
14 changes: 14 additions & 0 deletions test/pkgs/PkgUnboundArgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ 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

module ExcludeCallableObject
struct Callable{U}
s::U
end

(::Callable{U})(::NTuple{N,T}) where {N,T,U} = (N, T, U)
(::Callable{U})(::Tuple{}) where {U} = (0, Any, U)
end
end # module
14 changes: 14 additions & 0 deletions test/test_unbound_args.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ using PkgUnboundArgs
@test length(results) == 1
@test results[1] isa Test.Fail

Aqua.test_unbound_args(
PkgUnboundArgs,
exclude = [
Tuple{
typeof(PkgUnboundArgs.M25341._totuple),
Type{Tuple{Vararg{E}}} where E,
Any,
Vararg{Any},
},
Tuple{typeof(PkgUnboundArgs.Issue86.f),NTuple},
Tuple{PkgUnboundArgs.ExcludeCallableObject.Callable,NTuple},
],
)

# It works with other tests:
Aqua.test_ambiguities(PkgUnboundArgs)
Aqua.test_undefined_exports(PkgUnboundArgs)
Expand Down
Loading