RelationalAI-oss / XUnit.jl

XUnit.jl is a unit-testing framework for Julia.
MIT License
47 stars 5 forks source link

Method redefinitions in test cases do not work #3

Closed maleadt closed 3 years ago

maleadt commented 3 years ago

The following testcase fails, while it works properly using Test.@testset:

using XUnit

@testset "" begin
@testcase "" begin
    arr = zeros(Int)

    doit(arr) = arr[] = 1

    function kernel(arr)
        doit(arr)
        return
    end

    kernel(arr)
    @test arr[] == 1

    doit(ptr) = ptr[] = 2

    kernel(arr)
    @test arr[] == 2
end
end

In a similar vein, changing the doit method definitions to @eval doit(arr) = ... (which we require for CUDA.jl to avoid boxes), we get a world age error:

  Got exception outside of a @test
  MethodError: no method matching doit(::Array{Int64, 0})
  The applicable method may be too new: running in world age 29599, while current world is 29600.
  Closest candidates are:
    doit(::Any) at /tmp/wip.jl:7 (method too new to be called from this world context.)
maleadt commented 3 years ago

Thinking about it some more: I guess it's hard to really match Test.@testset here, and with invokelatest it's possible to work around it.