Skip to content

Commit 6a2286f

Browse files
committed
Add nowarn=:all option
1 parent c236177 commit 6a2286f

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

src/check.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,25 @@ macro should_not_warn(expr)
1616
end
1717

1818
"""
19-
check(f::Function)
19+
check(f::Function; nowarn=[], kwargs...)
2020
2121
Run Traceur on `f`, and throw an error if any warnings occur inside functions
22-
tagged with `@should_not_warn`.
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`.
2324
"""
2425
function check(f; nowarn=Any[], kwargs...)
26+
if nowarn isa Symbol
27+
_nowarn = Any[]
28+
_nowarn_all = nowarn == :all
29+
else
30+
_nowarn = nowarn
31+
_nowarn_all = false
32+
end
2533
failed = false
2634
wp = warning_printer()
2735
result = trace(f; kwargs...) do warning
2836
ix = findfirst(warning.stack) do call
29-
call.f in should_not_warn || call.f in nowarn
37+
_nowarn_all || call.f in should_not_warn || call.f in _nowarn
3038
end
3139
if ix != nothing
3240
tagged_function = warning.stack[ix].f
@@ -36,15 +44,16 @@ function check(f; nowarn=Any[], kwargs...)
3644
failed = true
3745
end
3846
end
39-
@assert !failed "One or more warnings occured inside functions tagged with `@should_not_warn`"
47+
@assert !failed "One or more warnings occured inside functions tagged with `@should_not_warn or specified with `nowarn`"
4048
result
4149
end
4250

4351
"""
4452
@check fun(args...) nowarn=[] maxdepth=typemax(Int)
4553
4654
Run Traceur on `fun`, and throw an error if any warnings occur inside functions
47-
tagged with `@should_not_warn` or specified in `nowarn`.
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`.
4857
"""
4958
macro check(expr, args...)
5059
quote

test/runtests.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function naive_sum(xs)
1717
return s
1818
end
1919

20-
f(x) = x+y
20+
foo(x) = x+y
2121

2222
function f2(x)
2323
foo = y
@@ -63,7 +63,7 @@ my_stable_add_undecorated(y) = my_add(y)
6363
ws = Traceur.warnings(() -> naive_sum([1.0]))
6464
@test warns_for(ws, "assigned", "returns")
6565

66-
ws = Traceur.warnings(() -> f(1))
66+
ws = Traceur.warnings(() -> foo(1))
6767
@test warns_for(ws, "global", "dispatch", "returns")
6868

6969
ws = Traceur.warnings(() -> f2(1))
@@ -100,5 +100,23 @@ my_stable_add_undecorated(y) = my_add(y)
100100
@test_nowarn @check my_add(1)
101101
@test_throws AssertionError @check my_stable_add(1)
102102
@test_throws AssertionError @check my_stable_add_undecorated(1) nowarn=[my_stable_add_undecorated]
103+
@test_throws AssertionError @check my_stable_add_undecorated(1) nowarn=:all
104+
function bar(x)
105+
x > 0 ? 1.0 : 1
106+
end
107+
@test @check(bar(2)) == 1.0
108+
@test @check(bar(2), maxdepth=100) == 1.0
109+
@test @check(bar(2), nowarn=:none) == 1.0
110+
@test @check(bar(2), nowarn=:none, maxdepth=100) == 1.0
111+
@test @check(bar(2), nowarn=[]) == 1.0
112+
@test @check(bar(2), nowarn=[], maxdepth=100) == 1.0
113+
@test @check(bar(2), nowarn=Any[]) == 1.0
114+
@test @check(bar(2), nowarn=Any[], maxdepth=100) == 1.0
115+
@test_throws AssertionError @check(bar(2), nowarn=[bar])
116+
@test_throws AssertionError @check(bar(2), nowarn=[bar], maxdepth=100)
117+
@test_throws AssertionError @check(bar(2), nowarn=Any[bar])
118+
@test_throws AssertionError @check(bar(2), nowarn=Any[bar], maxdepth=100)
119+
@test_throws AssertionError @check(bar(2), nowarn=:all)
120+
@test_throws AssertionError @check(bar(2), nowarn=:all, maxdepth=100)
103121
end
104122
end

0 commit comments

Comments
 (0)