Skip to content

Commit 1124b5e

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

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-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/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)