Skip to content

@constinferred doesn't work from within a function #10

@lkdvos

Description

@lkdvos

One thing which I have found missing is the ability to define a function that tests a bunch of functionality and adds this to the current test set. I.e., something like:

function test_myfunction(inputs)
    outputs = myfunction(inputs)
    @test some_properties(outputs)
    @constinferred myfunction(inputs)
end

This is especially useful when testing the same function on a bunch of different input types, but unfortunately this currently doesn't work:

julia> function test_myfunction(inputs)
           outputs = myfunction(inputs)
           @test some_properties(outputs)
           @constinferred myfunction(inputs)
       end
ERROR: syntax: World age increment not at top level

In all honesty, I've looked a bit at the code and I can't say I can come up with a solution strategy.
From what I can tell, defining the function that captures the "const" arguments in a non-toplevel scope is the hard part, which I'm actually okay with skipping for now. In this specific context, I actually would really want @inferred that uses @test instead of throwing an error.
One solution strategy might be to just define an @test_inferred in this package which is more or less a copy from the Test version and replaces the error with a test?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions