Skip to content

Commit 32046cf

Browse files
committed
better assert
1 parent a9290dc commit 32046cf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/wrapper.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ const SCIP_ = LibSCIP.SCIP
55
const TRUE = LibSCIP.TRUE
66
const FALSE = LibSCIP.FALSE
77

8-
# SCIP_CALL: macro to check return codes, inspired by @assert
8+
# SCIP_CALL: macro to check return codes
99
macro SCIP_CALL(ex)
10-
return :(@assert $(esc(ex)) == SCIP_OKAY)
10+
quote
11+
v = $(esc(ex))
12+
if v != SCIP_OKAY
13+
s = $(string(ex))
14+
error("$s yielded SCIP code $v")
15+
end
16+
end
1117
end
1218

1319
const SCIP_STATISTICS_FUNCS = [

test/runtests.jl

+12
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ end
8080
end
8181

8282
include("MOI_conshdlr.jl")
83+
84+
using Test
85+
using SCIP
86+
87+
@testset "SCIP_CALL printing" begin
88+
f() = SCIP.SCIP_OKAY
89+
g(args...) = SCIP.SCIP_ERROR
90+
SCIP.@SCIP_CALL f()
91+
h() = SCIP.@SCIP_CALL(g(1, 2))
92+
@test_throws ErrorException("g() yielded SCIP code SCIP_ERROR") SCIP.@SCIP_CALL g()
93+
@test_throws ErrorException("g(1, 2) yielded SCIP code SCIP_ERROR") h()
94+
end

0 commit comments

Comments
 (0)