File tree Expand file tree Collapse file tree 1 file changed +29
-5
lines changed
Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Along same lines as `@test_throws` but to test if a macro throw an exception when it is
3+ expanded.
4+ """
5+ macro test_macro_throws (err_expr, expr)
6+ quote
7+ err = nothing
8+ try
9+ @macroexpand ($ (esc (expr)))
10+ catch load_err
11+ # all errors thrown at macro expansion time are LoadErrors, we need to unwrap
12+ @assert load_err isa LoadError
13+ err = load_err. error
14+ end
15+ # Reuse `@test_throws` logic
16+ if err!= = nothing
17+ @test_throws $ (esc (err_expr)) ($ (Meta. quot (expr)); throw (err))
18+ else
19+ @test_throws $ (esc (err_expr)) $ (Meta. quot (expr))
20+ end
21+ end
22+ end
23+
24+
125@testset " rule_definition_tools.jl" begin
226 @testset " @non_differentiable" begin
327 @testset " two input one output function" begin
5175
5276 @testset " Not supported (Yet)" begin
5377 # Varargs are not supported
54- @test_throws Exception @macroexpand ( @ non_differentiable vararg1 (xs... )) |
55- @test_throws Exception @macroexpand ( @ non_differentiable vararg1 (xs:: Vararg ) )
78+ @test_macro_throws ErrorException @ non_differentiable vararg1 (xs... )
79+ @test_macro_throws ErrorException @ non_differentiable vararg1 (xs:: Vararg )
5680
5781 # Where clauses are not supported.
58- @test_throws Exception @macroexpand (
59- @non_differentiable where_identity (:: Vector{T} ) where T<: AbstractString
82+ @test_macro_throws (
83+ ErrorException,
84+ (@non_differentiable where_identity (:: Vector{T} ) where T<: AbstractString )
6085 )
6186 end
62-
6387 end
6488end
You can’t perform that action at this time.
0 commit comments