Skip to content

Bug in @safetestset macro, confusing object name and symbol? #14

@jonalm

Description

@jonalm

This might be a StructTypes issue, but I believe it belongs here. Consider the following module:

module Foo

using StructTypes
using JSON3

export Bar, Baz


struct Baz
    bom::Float64
end

StructTypes.StructType(::Type{Baz}) = StructTypes.Struct()

struct Bar{T}
    type::Symbol
    data::T
end
Bar(x) = Bar{typeof(x)}(Symbol(typeof(x)), x)

StructTypes.StructType(::Type{Bar}) = StructTypes.AbstractType()
StructTypes.StructType(::Type{<:Bar}) = StructTypes.Struct()
StructTypes.subtypes(::Type{Bar}) = (;
    Int64 = Bar{Int64}, 
    Baz = Bar{Baz} # this nt causes problems with the @safetest macro; lookup tries to find Foo.Baz not the symbol :Baz
)
Bar(s::String) = JSON3.read(s, Bar)

end # module Foo

with the corresponding test file

# test.jl
using Test
using Foo
using JSON3

x = Bar(123)
y = Bar(Baz(1.23))
@test x == Bar(JSON3.write(x))
@test y == Bar(JSON3.write(y)) # this line fails when running inside @safetestset macro

This file runs as expected, but running inside @safetestset like below, gives error

using SafeTestsets
@safetestset "test" begin
    include("test.jl")
end

yields

...
test: Error During Test at /Users/jonalmeriksen/dev/Foo/test/test.jl:8
  Test threw exception
  Expression: y == Bar(JSON3.write(y))
  type NamedTuple has no field Foo.Baz
  Stacktrace:
...
Test Summary: | Pass  Error  Total  Time
test          |    1      1      2  1.9s
ERROR: LoadError: Some tests did not pass: 1 passed, 0 failed, 1 errored, 0 broken.
in expression starting at /Users/jonalmeriksen/dev/Foo/test/runtests.jl:3
ERROR: Package Foo errored during testing

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