From 8ee997de8e0de08dbfb1a017432606ff17ce6dfb Mon Sep 17 00:00:00 2001 From: munja Date: Sun, 6 Feb 2022 16:11:18 +0100 Subject: [PATCH] fix: updating mf_abort param in mf_verifymacvars, also fixing return code as per documentation, adding a test, and updating the header info --- all.sas | 19 +++++++++++----- base/mf_verifymacvars.sas | 19 +++++++++++----- tests/crossplatform/mf_verifymacvars.test.sas | 22 +++++++++++++++++++ 3 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 tests/crossplatform/mf_verifymacvars.test.sas diff --git a/all.sas b/all.sas index 0f36f30..580cdeb 100644 --- a/all.sas +++ b/all.sas @@ -1807,7 +1807,7 @@ Usage: %mend mf_uid;/** @file - @brief Checks if a set of macro variables exist / contain values. + @brief Checks if a set of macro variables exist AND contain values. @details Writes ERROR to log if abortType is SOFT, else will call %mf_abort. Usage: @@ -1821,10 +1821,11 @@ Usage:

SAS Macros

@li mf_abort.sas - @param verifyvars space separated list of macro variable names - @param makeupcase= set to YES to convert all variable VALUES to + @param [in] verifyvars Space separated list of macro variable names + @param [in] makeupcase= (NO) Set to YES to convert all variable VALUES to uppercase. - @param mAbort= Abort Type. Default is SOFT (writes err to log). + @param [in] mAbort= (SOFT) Abort Type. When SOFT, simply writes an err + message to the log. Set to any other value to call mf_abort (which can be configured to abort in various fashions according to context). @@ -1865,9 +1866,15 @@ Usage: %goto exit_success; %exit_err: - %if &mAbort=SOFT %then %put %str(ERR)OR: &abortmsg; - %else %mf_abort(mac=mf_verifymacvars,type=&mabort,msg=&abortmsg); + %put %str(ERR)OR: &abortmsg; + %mf_abort(iftrue=(&mabort ne SOFT), + mac=mf_verifymacvars, + msg=%str(&abortmsg) + ) + 0 + %return; %exit_success: + 1 %mend mf_verifymacvars; /** diff --git a/base/mf_verifymacvars.sas b/base/mf_verifymacvars.sas index aaddc6b..ccab333 100755 --- a/base/mf_verifymacvars.sas +++ b/base/mf_verifymacvars.sas @@ -1,6 +1,6 @@ /** @file - @brief Checks if a set of macro variables exist / contain values. + @brief Checks if a set of macro variables exist AND contain values. @details Writes ERROR to log if abortType is SOFT, else will call %mf_abort. Usage: @@ -14,10 +14,11 @@

SAS Macros

@li mf_abort.sas - @param verifyvars space separated list of macro variable names - @param makeupcase= set to YES to convert all variable VALUES to + @param [in] verifyvars Space separated list of macro variable names + @param [in] makeupcase= (NO) Set to YES to convert all variable VALUES to uppercase. - @param mAbort= Abort Type. Default is SOFT (writes err to log). + @param [in] mAbort= (SOFT) Abort Type. When SOFT, simply writes an err + message to the log. Set to any other value to call mf_abort (which can be configured to abort in various fashions according to context). @@ -58,8 +59,14 @@ %goto exit_success; %exit_err: - %if &mAbort=SOFT %then %put %str(ERR)OR: &abortmsg; - %else %mf_abort(mac=mf_verifymacvars,type=&mabort,msg=&abortmsg); + %put %str(ERR)OR: &abortmsg; + %mf_abort(iftrue=(&mabort ne SOFT), + mac=mf_verifymacvars, + msg=%str(&abortmsg) + ) + 0 + %return; %exit_success: + 1 %mend mf_verifymacvars; diff --git a/tests/crossplatform/mf_verifymacvars.test.sas b/tests/crossplatform/mf_verifymacvars.test.sas new file mode 100644 index 0000000..60a1bf0 --- /dev/null +++ b/tests/crossplatform/mf_verifymacvars.test.sas @@ -0,0 +1,22 @@ +/** + @file + @brief Testing mf_verifymacvars macro + +

SAS Macros

+ @li mf_verifymacvars.sas + @li mp_assert.sas + @li mp_assertscope.sas + +**/ + +%let var1=x; +%let var2=y; + +%mp_assertscope(SNAPSHOT) +%mp_assert( + iftrue=(%mf_verifymacvars(var1 var2)=1), + desc=Checking macvars exist, + outds=work.test_results +) +%mp_assertscope(COMPARE) +