This macro, 'assertTrue', is part of the SASUNIT framework and is designed to check if a given condition evaluates to 'true'. For numeric types, a value of 0 is considered false, while any other value is true. For character types, an empty string or one composed only of spaces, as well as the word 'false' (case-insensitive), are considered false. All other strings are true. The macro initializes local variables, checks the call sequence via %_checkCallingSequence, then proceeds to evaluate the i_cond parameter according to its type (numeric or character). Finally, it calls the internal macro %_asserts to record the assertion result.
Data Analysis
Type : CREATION_INTERNE
The code evaluates the input variable 'i_cond', which is a condition passed as a parameter. It does not directly read data from external files or databases, but processes a value or an expression internal to the script.
1 Code Block
Macro SAS
Explanation : This block defines the 'assertTrue' macro with two parameters: 'i_cond' (the condition to evaluate) and 'i_desc' (a description of the assertion). It declares the global variable 'g_inTestCase' and calls '%endTestCall' for message handling. The macro then performs a call sequence check via '%_checkCallingSequence' to ensure it is used correctly in an assertion context. Local variables are declared to store intermediate evaluation results.
%IF %_checkCallingSequence(i_callerType=assert) NE 0 %THEN %DO;
9
%RETURN;
10
%END;
11
12
%LOCAL l_result l_expected l_actual;
2 Code Block
Macro SAS (Conditional Logic)
Explanation : This block evaluates the 'i_cond' condition if it is of character type, determined by the '%datatyp' macro. It sets 'l_expected' to 'true'. If the string is empty, 'l_result' is set to 2 (false). Otherwise, the string is converted to lowercase. If it is 'true', 'l_result' is 0 (true); if it is 'false', 'l_result' is 2 (false). If the string is neither 'true' nor 'false', it is trimmed of spaces with '%sysfunc(strip())', and 'l_result' is set based on its length after trimming: 0 if not empty (true), 2 if empty (false).
Explanation : This block evaluates the 'i_cond' condition if it is of numeric type. It sets 'l_expected' to 1. The value of 'i_cond' is stored in 'l_actual'. If 'i_cond' is equal to 0, 'l_result' is set to 2 (false). In all other cases (non-zero numeric value), 'l_result' is set to 0 (true).
Explanation : This final block calls the internal macro '%_asserts'. This is the core of assertion logging. It passes the assertion type ('assertTrue'), the expected value ('l_expected'), the actual value ('l_actual'), the assertion description ('i_desc'), and the evaluation result ('l_result') to it. This '%_asserts' macro is responsible for managing test results and reporting them.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.