From 2a194c80fb8f84fd7e05c308336b9078cd31167b Mon Sep 17 00:00:00 2001 From: zachmatson Date: Tue, 2 Jun 2020 12:28:48 -0400 Subject: [PATCH] Prevent argtest from failing nothing values to simplify testing for optional arguments --- src/macros.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/macros.jl b/src/macros.jl index 3218b50..e038a0b 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -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 @@ -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