Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mv_createfile.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mv_createfile macro
4
5 <h4> SAS Macros </h4>
6 @li mf_uid.sas
7 @li mfv_existfile.sas
8 @li mp_assert.sas
9 @li mp_assertscope.sas
10 @li mv_createfile.sas
11
12**/
13
14options mprint;
15
16%let file=%mf_uid();
17
18%put TEST 1 - basic file upload ;
19filename somefile temp;
20data _null_;
21 file somefile;
22 put 'hello testings';
23run;
24%mp_assertscope(SNAPSHOT)
25%mv_createfile(path=&mcTestAppLoc, name=&file..txt,inref=somefile,mdebug=1)
26%mp_assertscope(COMPARE
27 ,ignorelist=MCLIB0_JADP1LEN MCLIB0_JADP2LEN MCLIB0_JADPNUM
28 MCLIB0_JADVLEN MCLIB2_JADP1LEN
29 _SASJS_PROCESSMODE _SASJS_WEBOUT_HEADERS
30 MCLIB2_JADP2LEN MCLIB2_JADPNUM MCLIB2_JADVLEN
31)
32
33%mp_assert(
34 iftrue=(%mfv_existfile(&mcTestAppLoc/&file..txt)=1),
35 desc=Check if created file exists
36)
37
38%put TEST 2 - html file;
39filename f2 temp;
40data _null_;
41 file f2;
42 put '<html><body><p>Hello world</p></body></html>';
43run;
44%mv_createfile(path=&mcTestAppLoc, name=test.html,inref=f2,mdebug=1)
45
46%mp_assert(
47 iftrue=(%mfv_existfile(&mcTestAppLoc/test.html)=1),
48 desc=Check if created file exists
49)
50
51%put TEST 3 - dataset upload ;
52data temp;
53x=1;
54run;
55filename ds "%sysfunc(pathname(work))/temp.sas7bdat";
56
57%mv_createfile(path=&mcTestAppLoc, name=&file..sas7bdat,inref=ds,mdebug=1)
58
59%mp_assert(
60 iftrue=(%mfv_existfile(&mcTestAppLoc/&file..sas7bdat)=1),
61 desc=Check if created dataset exists
62)
63
64%put TEST 4 - create a .sas file;
65filename f4 temp;
66data _null_;
67 file f4;
68 put '%put hello FromSASStudioBailey; ';
69run;
70%mv_createfile(path=&mcTestAppLoc, name=test4.sas,inref=f4,mdebug=1)
71
72%mp_assert(
73 iftrue=(%mfv_existfile(&mcTestAppLoc/test4.sas)=1),
74 desc=Check if created sas program exists
75)
76
77%put TEST 5 - reading from files service and writing back;
78filename sendfrom filesrvc folderpath="&mcTestAppLoc" filename='test4.sas';
79
80OPTIONS SYMBOLGEN MLOGIC MPRINT MERROR;
81
82%mv_createfile(path=&mcTestAppLoc,name=test5.sas,inref=sendfrom,mdebug=1) ;
83
84%put TEST 6 - try the find and replace;
85filename f6 temp;
86data _null_;
87 file f6;
88 put '//Hello world!';
89 put 'let var=/some/path/name;';
90run;
91%let in=/some/path/name;
92%let out=/final/destination;
93%mv_createfile(path=&mcTestAppLoc, name=test6.js,inref=f6,mdebug=1,swap=in out)
94
95filename getback filesrvc folderpath="&mcTestAppLoc" filename='test6.js';
96
97%let test6=0;
98data _null_;
99 infile getback;
100 input;
101 if _infile_="let var=&out;" then call symputx('test6',1);
102 putlog _infile_;
103run;
104
105%mp_assert(
106 iftrue=(&test6=1),
107 desc=Check if find & replace worked
108)