Published on :
Unit Test CREATION_INTERNE

Test of the ms_triggerstp macro

This code is also available in: Deutsch Français
Awaiting validation
This script dynamically creates two temporary SAS© files acting as Stored Processes (STP) that write to `_webout`. It then uses the `ms_triggerstp` macro to trigger these STPs and capture the execution results in a work table (`work.mySessions`). The script performs a series of assertions (via `mp_assert`, `mp_assertdsobs`, `mp_assertcols`) to check for the existence of results, the number of observations, the column structure, and the consistency of the returned data. Finally, it cleans up the environment by deleting the created files.
Data Analysis

Type : CREATION_INTERNE


The stored process code is generated on the fly within the script (Data Step _NULL_). The analyzed data are the execution results of these processes.

1 Code Block
DATA STEP
Explanation :
Generation of two temporary files containing the SAS source code for the simulated Stored Processes (STP) for testing.
Copied!
1filename stpcode1 temp;
2DATA _null_;
3 file stpcode1;
4 put '%put hello world;';
5 put '%put _all_;';
6 put 'data _null_; file _webout1; put "triggerstp test 1";run;';
7RUN;
8filename stpcode2 temp;
9/* ... creation stpcode2 ... */
2 Code Block
Macro Call
Explanation :
Obtaining unique file names and physically creating the test .sas files in the `/sasjs/tests/` directory from the previously generated code.
Copied!
1%let fname1=%mf_getuniquename();
2%let fname2=%mf_getuniquename();
3 
4%ms_createfile(/sasjs/tests/&fname1..sas
5 ,inref=stpcode1
6 ,mdebug=1
7)
8%ms_createfile(/sasjs/tests/&fname2..sas
9 ,inref=stpcode2
10)
3 Code Block
Macro Call Data
Explanation :
Execution of Stored Processes via `ms_triggerstp`. Results are consolidated in `work.mySessions`. `mp_assertscope` monitors macro/global environment pollution.
Copied!
1%mp_assertscope(SNAPSHOT)
2 %ms_triggerstp(/sasjs/tests/&fname1
3 ,debug=131
4 ,outds=work.mySessions
5 )
6 %ms_triggerstp(/sasjs/tests/&fname2
7 ,outds=work.mySessions
8 )
9%mp_assertscope(COMPARE...)
4 Code Block
Macro Call
Explanation :
Validation of results: verification that the output table exists, contains exactly 2 observations, and has the `sessionid` column.
Copied!
1%mp_assert(iftrue=%str(%mf_existds(work.mySessions)=1)...)
2%mp_assertdsobs(work.mySessions, test=EQUALS 2...)
3%mp_assertcols(work.mySessions, cols=sessionid...)
5 Code Block
DATA STEP
Explanation :
Analysis of the content of the results table to ensure that `sessionID` is not missing, with the result stored in a macro variable for the final assertion.
Copied!
1DATA _null_;
2 retain contentCheck 1;
3 SET work.mySessions END=last;
4 IF missing(sessionID) THEN contentCheck = 0;
5 IF last THEN DO;
6 call symputx("contentCheck",contentCheck,"l");
7 END;
8RUN;
6 Code Block
Macro Call
Explanation :
Deletion of temporary SAS files created for the test to leave the system clean.
Copied!
1%ms_deletefile(/sasjs/tests/&fname1..sas)
2%ms_deletefile(/sasjs/tests/&fname2..sas)
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.