Skip to content

Commit bb2d463

Browse files
committed
Improve testing of not supported cases
1 parent 4188659 commit bb2d463

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

test/rule_definition_tools.jl

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
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
@@ -51,14 +75,14 @@
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
6488
end

0 commit comments

Comments
 (0)