Published on :
Macro CREATION_INTERNE

Test of the _mkDir macro-program

This code is also available in: Français Deutsch Español
Attention : This code requires administrator privileges.
The script validates the functionality of the _mkDir.sas© macro-program using the SASUnit test framework. It contains three distinct test cases: the first tests the simple creation of a directory, the second checks error handling when a parent path does not exist, and the third tests the recursive creation of a directory tree with the `makeCompletePath=1` option. Assertions verify the existence of the directories and the presence of expected error messages in the SAS© log.
Data Analysis

Type : CREATION_INTERNE


The script does not read any data. It interacts with the file system to create test directories in the WORK library path. The existence of these directories is then verified by test macros.

1 Code Block
Macro
Explanation :
Initializes a test scenario for _mkDir.sas. This first test case creates a simple directory named 'folder' in the WORK library. It calls the %_mkdir macro and then verifies with %assertEquals and %_existDir that the directory has been successfully created.
Copied!
1%initScenario (i_desc=Test of _mkDir.sas);
2 
3%initTestcase(i_object=_mkDir.sas, i_desc=Test with correct call)
4%let newdir=%sysfunc(pathname(work))/folder;
5%_mkdir(&newdir.);
6%endTestcall;
7 
8%assertEquals(i_expected=1, i_actual=%_existDir(&newdir.), i_desc=check on file existence)
9%endTestcase;
2 Code Block
Macro
Explanation :
This test case attempts to create a sub-directory ('subfolder') without the parent directory ('folder1') existing. The operation is expected to fail. The %assertLog and %assertLogMsg macros verify that a specific error is written to the log. Finally, %assertEquals confirms that the final directory was not created.
Copied!
1%initTestcase(i_object=_mkDir.sas, i_desc=Test with folder and subfolder to be created. No creation but message)
2%let newdir=%sysfunc(pathname(work))/folder1/subfolder;
3%_mkdir(&newdir.);
4%endTestcall;
5 
6%assertLog(i_errors=1, i_warnings=0)
7%assertLogMsg(i_logMsg=ERROR: _mkdir: Parentfolder .+folder1 does not exist)
8%assertEquals(i_expected=0, i_actual=%_existDir(&newdir.), i_desc=check on file existence)
9%endTestcase;
3 Code Block
Macro
Explanation :
This last test case demonstrates recursive creation. It uses the `makeCompletePath=1` option for %_mkdir to create both the parent directory 'folder1' and the sub-directory 'subfolder'. The %assertEquals assertion verifies that the complete path structure has been successfully created.
Copied!
1%initTestcase(i_object=_mkDir.sas, i_desc=Test with folder and subfolder to be created.)
2%let newdir=%sysfunc(pathname(work))/folder1/subfolder;
3%_mkdir(&newdir., makeCompletePath=1);
4%endTestcall;
5 
6%assertEquals(i_expected=1, i_actual=%_existDir(&newdir.), i_desc=check on file existence)
7%endTestcase;
4 Code Block
Macro
Explanation :
Ends the SASUnit test scenario.
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