Skip to content

Commit b2578f3

Browse files
authored
add single_arg test_objects (#50)
1 parent e0243ed commit b2578f3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/implements.jl

+27
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@ function implements end
1818
implements(T::Type{<:Interface}, obj) = implements(T, typeof(obj))
1919
implements(::Type{<:Interface}, obj::Type) = false
2020

21+
function test_objects(::Type{T}) where T<:Interface
22+
methodlist = methods(Interfaces.test_objects, Tuple{Type{T},Any})
23+
objects = Dict{Type,Any}()
24+
# Check that all found methods are either unrequired, or pass their tests
25+
for m in (methodlist)
26+
(m.module == Interfaces) && continue
27+
# We define this signature in the @interface macro so we know it is this consistent.
28+
# There may be some methods to help with these things?
29+
30+
# Handle either Type or UnionAll for the method signature parameters
31+
b = m.sig isa UnionAll ? m.sig.body : m.sig
32+
33+
# Skip the fallback methods
34+
b.parameters[2] == Type{<:Interface} && continue
35+
36+
# Skip the Type versions of implements and keep the UnionAll
37+
t = b.parameters[2].var.ub
38+
t isa UnionAll || return nothing, true
39+
40+
interface = t.body.name.wrapper
41+
implementation = b.parameters[3].var.ub
42+
implementation == Any && return continue
43+
objects[implementation] = test_objects(interface, implementation)
44+
end
45+
return objects
46+
end
47+
2148
"""
2249
@implements(interface, objtype, test_objects)
2350

test/basic.jl

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ using Test #src
105105
@test Interfaces.test(Animals.AnimalInterface) == true # Test all implemented types for AnimalInterface
106106
# TODO wrap errors somehow, or just let Invariants.jl handle that. #src
107107
@test_throws Interfaces.InterfaceError Interfaces.test(Animals.AnimalInterface{:dig}, Duck) #src
108+
@test Interfaces.test_objects(Animals.AnimalInterface) == Dict(Duck => ducks)
108109
end #src
109110

110111
@testset "Chicken" begin #src

0 commit comments

Comments
 (0)