Consider a macro that throws an exception:
macro aaa(); throw(ArgumentError("invalid")); end
Calling this macro in Julia 0.6 results in
julia> @aaa
ERROR: ArgumentError: invalid
while in 0.7/1.0 it has changed to (with no mention in NEWS.md)
julia> @aaa
ERROR: LoadError: ArgumentError: invalid
Stacktrace:
[1] @aaa(::LineNumberNode, ::Module) at ./REPL[2]:1
in expression starting at REPL[3]:1
This poses a problem when testing whether the correct type of exception is thrown by the macro. AFAIK testing for exceptions in macros needs an eval
, so this works in 0.6:
julia> using Base.Test
julia> @test_throws ArgumentError eval(:(@aaa))
Test Passed
Thrown: ArgumentError
but in 0.7/1.0 it fails:
julia> using Test
julia> @test_throws ArgumentError eval(:(@aaa))
Test Failed at REPL[5]:1
Expression: eval($(Expr(:quote, :(#= REPL[5]:1 =# @aaa))))
Expected: ArgumentError
Thrown: LoadError
ERROR: There was an error during testing
i.e. I can now only test for LoadError
but cannot distinguish different types of exceptions any more. Is there any recommended way for testing the exception type thrown by macros in 0.7/1.0?
BTW, according to the help text, a LoadError
should be thrown if
An error occurred while includeing, requireing, or using a file […]
I’m not sure whether macro evaluation belongs to that category, maybe the help text could be updated.