@@ -16,25 +16,40 @@ macro should_not_warn(expr)
16
16
end
17
17
18
18
"""
19
- check(f::Function; nowarn=[], kwargs...)
19
+ check(f::Function; nowarn=[], except=[], kwargs...)
20
20
21
21
Run Traceur on `f`, and throw an error if any warnings occur inside functions
22
- tagged with `@should_not_warn` or specified in `nowarn`. To throw an error
23
- if any warnings occur inside any functions, set `nowarn=:all`.
22
+ tagged with `@should_not_warn` or specified in `nowarn`.
23
+
24
+ To throw an error if any warnings occur inside any functions, set
25
+ `nowarn=:all`.
26
+
27
+ To throw an error if any warnings occur inside any functions EXCEPT for a
28
+ certain set of functions, set `nowarn=:allexcept` and list the exceptions in
29
+ the `except` variable, i.e. set `except=[f, g, h, ...]`
24
30
"""
25
- function check (f; nowarn= Any[], kwargs... )
31
+ function check (f; nowarn= Any[], except = Any[], kwargs... )
26
32
if nowarn isa Symbol
27
33
_nowarn = Any[]
28
- _nowarn_all = nowarn == :all
34
+ if nowarn == :all
35
+ _nowarn_all = true
36
+ _nowarn_allexcept = false
37
+ elseif nowarn == :allexcept
38
+ _nowarn_all = false
39
+ _nowarn_allexcept = true
40
+ else
41
+ throw (ArgumentError (" :$(nowarn) is not a valid value for nowarn" ))
42
+ end
29
43
else
30
44
_nowarn = nowarn
31
45
_nowarn_all = false
46
+ _nowarn_allexcept = false
32
47
end
33
48
failed = false
34
49
wp = warning_printer ()
35
50
result = trace (f; kwargs... ) do warning
36
51
ix = findfirst (warning. stack) do call
37
- _nowarn_all || call. f in should_not_warn || call. f in _nowarn
52
+ _nowarn_all || call. f in should_not_warn || call. f in _nowarn || (_nowarn_allexcept && ! (call . f in except))
38
53
end
39
54
if ix != nothing
40
55
tagged_function = warning. stack[ix]. f
@@ -49,11 +64,17 @@ function check(f; nowarn=Any[], kwargs...)
49
64
end
50
65
51
66
"""
52
- @check fun(args...) nowarn=[] maxdepth=typemax(Int)
67
+ @check fun(args...) nowarn=[] except=[] maxdepth=typemax(Int)
53
68
54
69
Run Traceur on `fun`, and throw an error if any warnings occur inside functions
55
- tagged with `@should_not_warn` or specified in `nowarn`. To throw an error
56
- if any warnings occur inside any functions, set `nowarn=:all`.
70
+ tagged with `@should_not_warn` or specified in `nowarn`.
71
+
72
+ To throw an error if any warnings occur inside any functions, set
73
+ `nowarn=:all`.
74
+
75
+ To throw an error if any warnings occur inside any functions EXCEPT for a
76
+ certain set of functions, set `nowarn=:allexcept` and list the exceptions in
77
+ the `except` variable, i.e. set `except=[f, g, h, ...]`
57
78
"""
58
79
macro check (expr, args... )
59
80
quote
0 commit comments