1
0
mirror of https://github.com/sasjs/core.git synced 2026-06-08 20:10:20 +00:00

feat: adding tests, adding param to mfv_existsashdat, updating README

This commit is contained in:
4gl
2026-04-27 17:29:07 +01:00
parent 08f2d0d53f
commit d0a5780cd1
6 changed files with 127 additions and 13 deletions
+99
View File
@@ -0,0 +1,99 @@
/**
@file
@brief Testing mfv_existsashdat macro function
<h4> SAS Macros </h4>
@li mf_uid.sas
@li mfv_existsashdat.sas
@li mp_assert.sas
@li mp_assertscope.sas
**/
options mprint;
/* ------------------------------------------------------------------------ */
/* Setup: start a CAS session and stage a sashdat file in the Public caslib */
/* ------------------------------------------------------------------------ */
cas mysess;
caslib _all_ assign;
%let testcaslib = Public; /* change this if Public isn't available */
proc cas;
table.caslibInfo result=r / ;
found = 0;
do row over r.CASLibInfo;
if upcase(row.Name) = upcase("&testcaslib") then found = 1;
end;
if found = 0 then do;
print "ERROR: caslib &testcaslib not available";
exit;
end;
quit;
%put NOTE: Using testcaslib=&testcaslib;
%let tab1=T%mf_uid();
proc casutil;
load data=sashelp.baseball outcaslib="&testcaslib" casout="&tab1" replace;
save casdata="&tab1" incaslib="&testcaslib"
casout="&tab1..sashdat" outcaslib="&testcaslib" replace;
droptable casdata="&tab1" incaslib="&testcaslib" quiet;
quit;
/* ------------------------------------------------------------------------ */
%put TEST 1 - returns 1 when the sashdat file exists in the caslib;
/* ------------------------------------------------------------------------ */
%mp_assert(
iftrue=(%mfv_existsashdat(&testcaslib..&tab1)=1),
desc=Test 1 - Check returns 1 for a sashdat that exists
)
/* ------------------------------------------------------------------------ */
%put TEST 2 - returns 0 when the file does not exist in the caslib;
/* ------------------------------------------------------------------------ */
%mp_assertscope(SNAPSHOT)
%mp_assert(
iftrue=(%mfv_existsashdat(&testcaslib..DOESNOTEXIST_%mf_uid())=0),
desc=Check returns 0 for a sashdat that does not exist
)
%mp_assertscope(COMPARE,
desc=Check mfv_existsashdat does not leak macro variables into GLOBAL scope
)
/* ------------------------------------------------------------------------ */
%put TEST 3 - usecache= controls whether the cached dataset is reused;
/* ------------------------------------------------------------------------ */
/* First call: populates the cache dataset work.testcache_&testcaslib */
%let _rc=%mfv_existsashdat(&testcaslib..&tab1,outprefix=work.testcache);
/* Delete the sashdat from the caslib so a fresh scan would return 0 */
proc casutil;
deletesource casdata="&tab1..sashdat" incaslib="&testcaslib" quiet;
quit;
/* usecache=1 (default): must return 1 from the cached dataset */
%mp_assert(
iftrue=(%mfv_existsashdat(&testcaslib..&tab1,outprefix=work.testcache)=1),
desc=Check returns 1 from cache even after source file is deleted
)
/* usecache=0: forces rescan and reflects the deletion */
%mp_assert(
iftrue=(
%mfv_existsashdat(&testcaslib..&tab1,usecache=0,outprefix=work.testcache)=0
),
desc=Check returns 0 when usecache=0 forces a rescan after source file deleted
)
%let syscc=0;
/* ------------------------------------------------------------------------ */
/* Teardown: terminate CAS session (sashdat already removed in TEST 4) */
/* ------------------------------------------------------------------------ */
cas mysess terminate;
%let syscc=0;
+1 -1
View File
@@ -69,7 +69,7 @@ quit;
/* ------------------------------------------------------------------------ */
%put TEST 2 - load a table that does not yet exist (default srcfile=table.hdat);
%put TEST 2 - load a table that does not yet exist (default srcfile=table.sashdat);
/* ------------------------------------------------------------------------ */
%mv_castabload(caslib=&testcaslib,table=&tab1,mdebug=1)