Published on :
Macro CREATION_INTERNE

Verification of Macro Calling Sequence

This code is also available in: Français Deutsch Español
This internal macro, `_checkCallingSequence`, is a component of the SASUnit framework. Its role is to validate the execution order of specific macro calls. It receives an `i_callerType` parameter which indicates the type of the caller ('scenario' or 'assert').
If `i_callerType` is 'scenario', the macro ensures that 'initScenario' is not called twice consecutively or within an already active 'testCall' or 'testCase' context. This guarantees the integrity of the test environment.
If `i_callerType` is 'assert', it verifies that the 'Assert' function is called only after a scenario ('initScenario') and a test case ('initTestCase') have been initialized.
If an incorrect calling sequence is detected, the macro emits an error message via `%_issueErrorMessage` and returns the value 1, signaling a failure. If the sequence is correct, it returns 0. A return of -1 indicates an unrecognized caller type.
Data Analysis

Type : CREATION_INTERNE


The script only manipulates internal global macro variables within the SASUnit framework (like `g_inScenario`, `g_inTestCase`, `g_inTestCall`, `g_currentLogger`). It neither reads nor writes data from traditional SAS datasets, external databases, or files.

1 Code Block
MACRO DEFINITION
Explanation :
This block defines the `_checkCallingSequence` macro. It initializes the global macro variables `g_inScenario`, `g_inTestCase`, and `g_inTestCall` (if not already defined) to track the test context state. It converts `i_callerType` to lowercase for case-insensitive comparison. Conditional structures `%if/%then/%do` are used to evaluate `l_callerType`.

- If `l_callerType` is 'scenario', the macro checks that scenario initialization is not performed twice, or within an already active `TestCall` or `TestCase` context. If these conditions are violated, an error message is generated and the macro returns 1.
- If `l_callerType` is 'assert', the macro ensures that the assertion call is made within an active scenario (`g_inScenario = 1`) and test case (`g_inTestCase = 1`). If not respected, an error message is issued and the macro returns 1.

In both cases, if the sequence is correct, the macro returns 0. A return of -1 is used for an unhandled `i_callerType`. The `_issueErrorMessage` macro (not defined here but assumed to exist within the framework) is used for error handling.
Copied!
1/**
2 \file
3 \ingroup SASUNIT_UTIL
4 
5 \brief check for correct calling sequence
6 
7 \version \$Revision$
8 \author \$Author$
9 \date \$Date$
10
11 \sa For further information please refer to https://github.com/HMS-Analytical-Software/SASUnit/wiki/User%27s%20Guide/
12 Here you can find the SASUnit documentation, release notes and license information.
13 \sa \$HeadURL$
14 \copyright Copyright 2010-2023 HMS Analytical Software GmbH, http://www.analytical-software.de
15 This file is part of SASUnit, the Unit testing framework for SAS(R) programs.
16 For copyright information and terms of usage under the GNU Lesser General Public License see included file README.md
17 or https://github.com/HMS-Analytical-Software/SASUnit/wiki/readme/.
18
19 \param i_callerType Type of macro calling (scenario, asssert)
20 
21*/
22/** \cond */
23%MACRO _checkCallingSequence(i_callerType =);
24 
25 %global g_inScenario g_inTestCase g_inTestCall;
26
27 %let l_callerType = %lowcase (&i_callerType.);
28 
29 %IF (&l_callertype.=scenario) %THEN %DO;
30 %IF (&g_inScenario. = 1) %THEN %DO;
31 %_issueErrorMessage(&g_currentLogger.,_checkCallingSequence: initScenario must not be called twice!)
32 1
33 %RETURN;
34 %END;
35 %IF (&g_inTestCall. = 1) %THEN %DO;
36 %_issueErrorMessage(&g_currentLogger.,_checkCallingSequence: initScenario must not be called within a test call!)
37 1
38 %RETURN;
39 %END;
40 %IF (&g_inTestcase. = 1) %THEN %DO;
41 %_issueErrorMessage(&g_currentLogger.,_checkCallingSequence: initScenario must not be called within a test case!)
42 1
43 %RETURN;
44 %END;
45 0
46 %RETURN;
47 %END;
48 %IF (&l_callertype.=assert) %THEN %DO;
49 %IF (&g_inScenario. = 0) %THEN %DO;
50 %_issueErrorMessage(&g_currentLogger.,_checkCallingSequence: Assert must be called after initScenario!)
51 1
52 %RETURN;
53 %END;
54 %IF (&g_inTestcase. = 0) %THEN %DO;
55 %_issueErrorMessage(&g_currentLogger.,_checkCallingSequence: Assert must be called after initTestCase!)
56 1
57 %RETURN;
58 %END;
59 0
60 %RETURN;
61 %END;
62 -1
63%MEND _checkCallingSequence;
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.
Copyright Info : Copyright 2010-2023 HMS Analytical Software GmbH, http://www.analytical-software.de. This file is part of SASUnit, the Unit testing framework for SAS(R) programs.