Skip to content

Defining testsets inside a function not supported? #44

Open
@fingolfin

Description

@fingolfin

For OSCAR, we use "testset templates" to provide generic conformance for various "interfaces" based on Test.
These currently come in the form of a function that takes an object to be tested, and which then internally produces a @testset carrying out the test. The idea is that other packages then can use these conformance tests on their own implementations of those interfaces/protocols.

Here is a severely stripped down example:

function test_Ring_interface(R::AbstractAlgebra.Ring)

   T = elem_type(R)

   @testset "Ring interface for $(R) of type $(typeof(R))" begin

      @test T <: RingElement

      # ... more tests come here

   end
end

Unfortunately, with ReTest, this doesn't seem to be supported? Trying to use ReTest with the above resulted in this:

...
    nested task error: TaskFailedException

        nested task error: UndefVarError: R not defined
        Stacktrace:
          [1] macro expansion
            @ ~/.julia/packages/ReTest/WnRIG/src/testset.jl:505 [inlined]
          [2] macro expansion
            @ ~/Projekte/OSCAR/AbstractAlgebra.jl/test/Rings-conformance-tests.jl:205 [inlined]
          [3] top-level scope
            @ ~/.julia/packages/ReTest/WnRIG/src/ReTest.jl:517
          [4] eval
            @ ./boot.jl:360 [inlined]
...

I.e. it isn't capturing the surrounding context.

Is there any chance this could be fixed? If so, how complicated do you think it would be / where would one have to start?

I am also open to alternative suggestions for implementing such conformance tests; but the current approach is quite nice in that it is easy to grok what it does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions