Skip to content

Commit 184ab91

Browse files
committed
disable assert macro unless running in debug mode
1 parent 6fbe948 commit 184ab91

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

base/error.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,17 @@ windowserror(p, b::Bool; extrainfo=nothing) = b ? windowserror(p, extrainfo=extr
183183
windowserror(p, code::UInt32=Libc.GetLastError(); extrainfo=nothing) = throw(Main.Base.SystemError(string(p), 0, WindowsErrorInfo(code, extrainfo)))
184184

185185

186-
## assertion macro ##
186+
## assertion and ifdebug macros ##
187+
188+
"""
189+
@ifdebug expr
190+
191+
Equivalent to `@static if isdebug()`
192+
"""
193+
macro ifdebug(expr)
194+
isdefined(@__MODULE__, :isdebug) && !(isdebug()) && return nothing
195+
return :(esc(expr))
196+
end
187197

188198

189199
"""

test/exceptions.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ end
369369
end
370370

371371
# issue #36527
372+
s = raw"""
373+
using Test
372374
function f36527()
373375
caught = false
374376
🏡 = Core.eval(Main, :(module asdf36527 end))
@@ -383,6 +385,8 @@ function f36527()
383385
end
384386
385387
@test f36527()
388+
"""
389+
@test success(`$(Base.julia_cmd()) -g2 -e $s`)
386390

387391
# accessing an undefined var in tail position in a catch block
388392
function undef_var_in_catch()

test/misc.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,19 +714,19 @@ end
714714

715715
@kwdef struct TestInnerConstructor
716716
a = 1
717-
TestInnerConstructor(a::Int) = (@assert a>0; new(a))
717+
TestInnerConstructor(a::Int) = (a>0 || error(); new(a))
718718
function TestInnerConstructor(a::String)
719-
@assert length(a) > 0
719+
length(a) > 0 || error()
720720
new(a)
721721
end
722722
end
723723

724724
@testset "@kwdef inner constructor" begin
725725
@test TestInnerConstructor() == TestInnerConstructor(1)
726726
@test TestInnerConstructor(a=2) == TestInnerConstructor(2)
727-
@test_throws AssertionError TestInnerConstructor(a=0)
727+
@test_throws ErrorException TestInnerConstructor(a=0)
728728
@test TestInnerConstructor(a="2") == TestInnerConstructor("2")
729-
@test_throws AssertionError TestInnerConstructor(a="")
729+
@test_throws ErrorException TestInnerConstructor(a="")
730730
end
731731

732732
const outsidevar = 7
@@ -763,7 +763,7 @@ end
763763

764764
@testset "Pointer to unsigned/signed integer" begin
765765
# assuming UInt and Ptr have the same size
766-
@assert sizeof(UInt) == sizeof(Ptr{Nothing})
766+
@test sizeof(UInt) == sizeof(Ptr{Nothing})
767767
uint = UInt(0x12345678)
768768
sint = signed(uint)
769769
ptr = reinterpret(Ptr{Nothing}, uint)

0 commit comments

Comments
 (0)