Published on :
Test INTERNAL_CREATION

Test of the _checkRunEnvironment.sas macro

This code is also available in: Français Deutsch Español
This SAS© script is designed to test the `_checkRunEnvironment.sas©` macro from the SASUnit library. It initializes a test scenario and a single test case titled 'Successful call'. Before calling the macro to be tested, the script saves the current state of the MPRINT and MLOGIC system options, then activates them to allow detailed debugging of the macro's execution. After the `_checkRunEnvironment.sas©` call, the MPRINT and MLOGIC options are restored to their initial state. The script then uses the assertion macros `%assertEquals` to verify that the tested macro returns a success value (0) and `%assertLogMsg` to confirm that certain messages related to operating systems (Windows, Linux) or SAS© versions (9.4) are not present in the log, which indicates that the test environment is correctly identified or that these specific conditions are not met. The scenario and test case are then closed.
Data Analysis

Type : INTERNAL_CREATION


The script does not manipulate persistent external data. It interacts with the SAS environment via system options (`MPRINT`, `MLOGIC`) and macro variables (`g_cre_result`, `l_mprint`, `l_mlogic`) created and managed dynamically during test execution. The primary goal is not data transformation but the validation of a system macro's behavior.

1 Code Block
Test scenario initialization
Explanation :
This block initializes the test scenario with a clear description of its objective. It also declares the global macro variable `g_cre_result` and initializes it to -1. This variable will be used to capture the return code of the `_checkRunEnvironment.sas` macro being tested.
Copied!
1%initScenario(i_desc=Test of _checkRunEnvironment.sas);
2 
3%global g_cre_result;
4%let g_cre_result=-1;
2 Code Block
Test case execution and validation
Explanation :
This block defines a test case for a successful call to `_checkRunEnvironment.sas`. It first saves the current states of the `MPRINT` and `MLOGIC` system options, then activates them for diagnosis. The `_checkRunEnvironment` macro is then called, and its result is stored in `g_cre_result`. The `MPRINT` and `MLOGIC` options are restored to their initial state. Finally, assertions are used: `%assertEquals` verifies that the macro's result is 0 (indicating success), and `%assertLogMsg` confirms the absence of specific messages in the log, ensuring that the environment is correctly evaluated.
Copied!
1%initTestcase(i_object = _checkRunEnvironment.sas, i_desc = Successful call)
2 
3%let l_mprint = %sysfunc(getoption(MPRINT));
4%let l_mlogic = %sysfunc(getoption(MLOGIC));
5 
6options mprint mlogic;
7 
8%let g_cre_result=%_checkRunEnvironment;
9 
10options &l_mprint. &l_mlogic.;
11 
12%endTestcall();
13 
14%assertEquals(i_actual =&g_cre_result.
15 ,i_expected =0
16 ,i_desc =OS and SAS Version are valid
17 );
18%assertLogMsg (i_logmsg=NE WIN);
19%assertLogMsg (i_logmsg=NE LINUX);
20%assertLogMsg (i_logmsg=NE 9.4);
21 
22%endTestcase();
3 Code Block
Test scenario finalization
Explanation :
This block marks the formal end of the test scenario, closing all ongoing test operations and consolidating the results.
Copied!
1%endScenario();
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. For copyright information and terms of usage under the GNU Lesser General Public License see included file README.md or https://github.com/HMS-Analytical-Software/SASUnit/wiki/readme/.