Published on :
Test CREATION_INTERNE

Test of the _existDir.sas macro

This code is also available in: Français Deutsch Español
This script uses the SASUnit framework to test the `_existDir.sas©` macro. It evaluates its ability to correctly detect the existence of directories for different scenarios: an existing directory (via SAS© `WORK`), an existing directory with a trailing slash, and a deliberately non-existent directory. The `%assertEquals` assertions are used to validate the macro's results.
Data Analysis

Type : CREATION_INTERNE


The script does not process business data. It defines local variables to store directory paths (existing and non-existing) and uses the 'WORK' system library for a path internal to the SAS session.

1 Code Block
SASUNIT Macro Calls
Explanation :
Initializes the SASUnit test scenario and defines three macro variables: `existing` for an existing directory path (the SAS work directory), `existing2` for the same path with a trailing slash, and `not_existing` for a deliberately non-existent directory path.
Copied!
1%initScenario (i_desc=Test of _existDir.sas);
2 
3%let existing = %sysfunc(pathname(work));
4%let existing2 = %sysfunc(pathname(work))/;
5%let not_existing = y:\ljfds\jdsa\jdsal\urewqio;
2 Code Block
SASUNIT Macro Calls
Explanation :
First test case: checks if the `_existdir` macro returns 1 (true) for an existing directory (`&existing`). It uses `%assertEquals` to confirm that the result is indeed 1.
Copied!
1%initTestcase(i_object=_existDir.sas, i_desc=existing folder)
2%LET exists = %_existdir(&existing);
3%endTestcall;
4%assertEquals(i_expected=1, i_actual=&exists, i_desc=folder exists)
5%endTestcase;
3 Code Block
SASUNIT Macro Calls
Explanation :
Second test case: checks if the `_existdir` macro returns 1 (true) for an existing directory with a trailing slash (`&existing2`). `%assertEquals` is used to validate that the result is 1.
Copied!
1%initTestcase(i_object=_existDir.sas, i_desc=existing folder with terminating /)
2%LET exists = %_existdir(&existing2);
3%endTestcall;
4%assertEquals(i_expected=1, i_actual=&exists, i_desc=folder exists)
5%endTestcase;
4 Code Block
SASUNIT Macro Calls
Explanation :
Third test case: checks if the `_existdir` macro returns 0 (false) for a non-existent directory (`&not_existing`). `%assertEquals` confirms that the result is 0.
Copied!
1%initTestcase(i_object=_existDir.sas, i_desc=not existing folder)
2%LET exists = %_existdir(¬_existing);
3%endTestcall;
4%assertEquals(i_expected=0, i_actual=&exists, i_desc=folder does not exists)
5%endTestcase;
5 Code Block
SASUNIT Macro Calls
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 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/.