Published on :
Macro CREATION_INTERNE

Unit test of the _getAbsPathComponents macro

This code is also available in: Français Deutsch Español
This script uses the SASUnit framework to test the '_getAbsPathComponents' macro. It defines test cases to verify the macro's behavior when faced with a complete absolute path and when faced with a simple filename. The results (filename and path) are stored in macro variables and compared to expected values via %assertEquals.
Data Analysis

Type : CREATION_INTERNE


Data consists of static character strings provided as arguments to macros. No external tables are used.

1 Code Block
MACRO CALL
Explanation :
Initialization of the SASUnit test scenario with a description.
Copied!
1%initScenario (i_desc=Test of _getAbsPathComponents.sas);
2 
2 Code Block
MACRO CALL
Explanation :
Test Case 1: Tests splitting a full path (C:/temp/test.sas). The macro should return 'C:/temp' in the r_pathWithoutName variable and 'test.sas' in r_fileName.
Copied!
1%initTestcase(i_object=_getAbsPathComponents.sas
2 , i_desc=%str(absolute path is splitted))
3%LET r_fileName=;
4%LET r_pathWithoutName=;
5%_getAbsPathComponents(
6 i_absPath = C:/temp/test.sas
7 , o_fileName = r_fileName
8 , o_pathWithoutName = r_pathWithoutName
9 )
10 
11%assertLog()
12%assertEquals(i_expected=C:/temp , i_actual=&r_pathWithoutName, i_desc=pathWithoutName)
13%assertEquals(i_expected=test.sas, i_actual=&r_fileName , i_desc=fileName)
14%endTestcase()
3 Code Block
MACRO CALL
Explanation :
Test Case 2: Tests the case where only the filename is provided (test.sas). The macro should return an empty string for the path and 'test.sas' for the filename.
Copied!
1%initTestcase(i_object=_getAbsPathComponents.sas
2 , i_desc=%str(only file name is given))
3%LET r_fileName=;
4%LET r_pathWithoutName=;
5%_getAbsPathComponents(
6 i_absPath = test.sas
7 , o_fileName = r_fileName
8 , o_pathWithoutName = r_pathWithoutName
9 )
10 
11%assertLog()
12%assertEquals(i_expected= , i_actual=&r_pathWithoutName, i_desc=pathWithoutName)
13%assertEquals(i_expected=test.sas, i_actual=&r_fileName , i_desc=fileName)
14%endTestcase()
4 Code Block
MACRO CALL
Explanation :
Termination of the 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