Skip to content

Commit

Permalink
Prevent argtest from failing nothing values to simplify testing for o…
Browse files Browse the repository at this point in the history
…ptional arguments
  • Loading branch information
zachmatson committed Jun 2, 2020
1 parent 85754fa commit 2a194c8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ end
@argtest argname func [desc]
Apply `func` to the value stored in `argname`, printing an error message (optionally
specified by `desc`) and the program if `func` returns `false`.
specified by `desc`) and the program if `func` returns `false`.
Test skipped if `argname` has value `nothing` (only possible for optional arguments).
This macro must be used AFTER declaring the arugment with another macro.
Must be used in `@beginarguments begin ... end` block
Expand All @@ -292,7 +293,7 @@ end
macro argtest(argname::Symbol, func::Union{Symbol, Expr}, desc::Union{String, Nothing}=nothing)
errstr::String = something(desc, "Tests for argument $argname failed.")
return quote
if !$(esc(esc(func)))($(esc(esc(argname))))
if !(isnothing($(esc(esc(argname)))) || $(esc(esc(func)))($(esc(esc(argname)))))
_quit_try_help($errstr)
end
end
Expand Down

0 comments on commit 2a194c8

Please sign in to comment.