mirror of
https://github.com/sasjs/core.git
synced 2026-06-08 20:10:20 +00:00
100 lines
3.2 KiB
SAS
100 lines
3.2 KiB
SAS
/**
|
|
@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;
|