crs*_*nbr 10
没有内置选项/命令行标志来@assert
全局禁用s,但(!)。
现在,您可以定义一个@myassert
宏,根据全局开关,它是无操作或常规的@assert
:
asserting() = false # when set to true, this will enable all `@myassert`s
macro mayassert(test)
esc(:(if $(@__MODULE__).asserting()
@assert($test)
end))
end
f(x) = @mayassert x < 2
Run Code Online (Sandbox Code Playgroud)
(摘自https://discourse.julialang.org/t/assert-alternatives/24775/14)