Skip to content

Commit 2a194c8

Browse files
committed
Prevent argtest from failing nothing values to simplify testing for optional arguments
1 parent 85754fa commit 2a194c8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/macros.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ end
274274
@argtest argname func [desc]
275275
276276
Apply `func` to the value stored in `argname`, printing an error message (optionally
277-
specified by `desc`) and the program if `func` returns `false`.
277+
specified by `desc`) and the program if `func` returns `false`.
278+
Test skipped if `argname` has value `nothing` (only possible for optional arguments).
278279
This macro must be used AFTER declaring the arugment with another macro.
279280
280281
Must be used in `@beginarguments begin ... end` block
@@ -292,7 +293,7 @@ end
292293
macro argtest(argname::Symbol, func::Union{Symbol, Expr}, desc::Union{String, Nothing}=nothing)
293294
errstr::String = something(desc, "Tests for argument $argname failed.")
294295
return quote
295-
if !$(esc(esc(func)))($(esc(esc(argname))))
296+
if !(isnothing($(esc(esc(argname)))) || $(esc(esc(func)))($(esc(esc(argname)))))
296297
_quit_try_help($errstr)
297298
end
298299
end

0 commit comments

Comments
 (0)