Published on :
Test CREATION_INTERNE

Test of the _createScnLogConfigTemplate macro

This code is also available in: Français Deutsch Español
Awaiting validation
This SAS© script is a unit test that uses the SASUnit framework. It initializes a test scenario, then executes a specific test case. The test case calls the macro `_createScnLogConfigTemplate` with defined parameters to create a log configuration template file in the WORK library. It then performs assertions to verify that the file has been created (existence and content) and that it contains no errors or warnings in the SAS© log. Finally, it cleans up the created file after the test.
Data Analysis

Type : CREATION_INTERNE


The script does not consume unmanaged external data. It creates a log configuration template file in the temporary 'WORK' library and uses a reference path (g_refdata) which is a SASUnit macro variable supposed to point to test data managed by the framework.

1 Code Block
SASUnit Macro
Explanation :
Initializes the global test scenario and defines the 'testcase' macro that encapsulates the unit test logic. The 'i_desc' parameter provides a description of the scenario, identifying the objective of the test.
Copied!
1%initScenario (i_desc=Test of _createScnLogConfigTemplate.sas);
2%macro testcase(i_object=_createScnLogConfigTemplate.sas, i_desc=%str(Correct call));
3 
2 Code Block
_createScnLogConfigTemplate Macro Data
Explanation :
This block initializes the specific test case and calls the `_createScnLogConfigTemplate` macro. This macro is tested to ensure it correctly generates a SASUnit log configuration file. The file is created in the SAS working folder (`WORK`) with the name `sasunit.scnlogconfig.xx.template.xml`. Log folder paths and language are specified, with 'XX' being a placeholder for the test.
Copied!
1 /* start testcase */
2 %initTestcase(i_object=&i_object., i_desc=&i_desc.);
3 
4 /* call */
5 %_createScnLogConfigTemplate(i_projectBinFolder =%sysfunc(pathname(WORK))
6 ,i_sasunitLogFolder =./logs
7 ,i_sasunitScnLogFolder =./scnLogs
8 ,i_sasunitLanguage =XX
9 );
10 
11 %endTestcall()
3 Code Block
SASUnit Macro
Explanation :
This block contains the assertions that verify the success of the test. `%assertLog` ensures that no warnings or errors were issued in the SAS log. `%assertEquals` verifies that the template file was indeed created using the `fileexist` function. `%assertText` compares the content of the generated file with a reference file specified by the `g_refdata` macro variable to validate its conformity.
Copied!
1 /* assert */
2 %assertLog(i_errors=0, i_warnings=0);
3 %assertEquals (i_actual =%sysfunc(fileexist(%sysfunc(pathname(WORK))/sasunit.scnlogconfig.xx.template.xml))
4 ,i_expected=1
5 ,i_desc =New scn log config template xml file must exist
6 );
7 
8 %assertText (i_expected = &g_refdata./sasunit.scnlogconfig.xx.template.xml
9 ,i_actual = %sysfunc(pathname(WORK))/sasunit.scnlogconfig.xx.template.xml
10 ,i_desc = Scn-Log config template created correctly
11 );
12
13 /* end testcase */
14 %endTestcase()
4 Code Block
SYSCALL Function / Cleanup
Explanation :
This block handles cleanup after the test. It defines a fileref `fdel` pointing to the created template file, then uses `%sysfunc(fdelete(fdel))` to delete this file. `filename fdel clear;` releases the fileref. The final lines (`%mend testcase; %testcase; %endScenario();`) mark the end of the test macro and the global SASUnit scenario.
Copied!
1 filename fdel "%sysfunc(pathname(WORK))/sasunit.scnlogconfig.xx.template.xml";
2 %put %sysfunc(fdelete(fdel));
3 filename fdel clear;
4%mend testcase; %testcase;
5 
6%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/.