Test of the _executeCmdFile macro

This code is also available in: Français Deutsch Español
Difficulty Level
Beginner
Published on :
This script aims to verify the correct functioning of the _executeCmdFile macro. It proceeds by dynamically creating a system script (.cmd file) in the temporary WORK directory which contains an instruction to create a 'TestFolder' directory. The macro is then called to execute this script. The test concludes with an assertion verifying that the folder has indeed been created.
Data Analysis

Type : INTERNAL_CREATION


The script generates its own test files (.cmd file) directly in the code via a Data Step.

1 Code Block
MACRO
Explanation :
Initialization of the SASUnit test scenario.
Copied!
1%initScenario (i_desc=Test of _executeCmdFile.sas)
2 Code Block
DATA STEP Data
Explanation :
Retrieval of the WORK directory path and creation of a system command file (.cmd) containing the instruction to create a folder named 'TestFolder'.
Copied!
1%let path = %sysfunc (pathname(WORK));
2DATA _null_;
3 file "&path./createfolder.cmd";
4 put "&g_makedir. ""&path./TestFolder""";
5RUN;
3 Code Block
MACRO
Explanation :
Initialization of the test case and execution of the _executeCmdFile macro pointing to the previously created command file.
Copied!
1%initTestcase(i_object=_executeCmdFile.sas, i_desc=check call of program)
2 
3%_executeCmdFile(&path./createfolder.cmd);
4 
5%endTestCall;
4 Code Block
MACRO
Explanation :
Verification of results: ensuring that the 'TestFolder' directory exists (expected value 1) and validating the logs before closing the test case and the scenario.
Copied!
1%assertEquals(i_expected=1, i_actual=%_existdir(&path./TestFolder), i_desc=Folder should exist)
2%assertLog()
3%endTestcase()
4 
5%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


Related Documentation

Aucune documentation spécifique pour cette catégorie.