Skip to content

Commit

Permalink
disable assert macro unless running in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Oct 8, 2020
1 parent 6fbe948 commit 1124b5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,17 @@ windowserror(p, b::Bool; extrainfo=nothing) = b ? windowserror(p, extrainfo=extr
windowserror(p, code::UInt32=Libc.GetLastError(); extrainfo=nothing) = throw(Main.Base.SystemError(string(p), 0, WindowsErrorInfo(code, extrainfo)))


## assertion macro ##
## assertion and ifdebug macros ##

"""
@ifdebug expr
Equivalent to `@static if isdebug()`
"""
macro ifdebug(expr)
isdefined(@__MODULE__, :isdebug) && !(isdebug()) && return nothing
return :(esc(expr))
end


"""
Expand Down
10 changes: 5 additions & 5 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -714,19 +714,19 @@ end

@kwdef struct TestInnerConstructor
a = 1
TestInnerConstructor(a::Int) = (@assert a>0; new(a))
TestInnerConstructor(a::Int) = (a>0 || error(); new(a))
function TestInnerConstructor(a::String)
@assert length(a) > 0
length(a) > 0 || error()
new(a)
end
end

@testset "@kwdef inner constructor" begin
@test TestInnerConstructor() == TestInnerConstructor(1)
@test TestInnerConstructor(a=2) == TestInnerConstructor(2)
@test_throws AssertionError TestInnerConstructor(a=0)
@test_throws ErrorException TestInnerConstructor(a=0)
@test TestInnerConstructor(a="2") == TestInnerConstructor("2")
@test_throws AssertionError TestInnerConstructor(a="")
@test_throws ErrorException TestInnerConstructor(a="")
end

const outsidevar = 7
Expand Down Expand Up @@ -763,7 +763,7 @@ end

@testset "Pointer to unsigned/signed integer" begin
# assuming UInt and Ptr have the same size
@assert sizeof(UInt) == sizeof(Ptr{Nothing})
@test sizeof(UInt) == sizeof(Ptr{Nothing})
uint = UInt(0x12345678)
sint = signed(uint)
ptr = reinterpret(Ptr{Nothing}, uint)
Expand Down

0 comments on commit 1124b5e

Please sign in to comment.