Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_binarycopy.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_binarycopy.sas macro
4
5 <h4> SAS Macros </h4>
6 @li mp_binarycopy.sas
7 @li mp_assert.sas
8
9**/
10
11
12/* TEST 1 - regular file copy */
13%let string1=test1;
14filename tmp temp;
15filename myref temp;
16data _null_;
17 file tmp;
18 put "&string1";
19run;
20%mp_binarycopy(inref=tmp, outref=myref)
21data _null_;
22 infile myref;
23 input;
24 put _infile_;
25 call symputx('string1_check',_infile_);
26 stop;
27run;
28%mp_assert(
29 iftrue=("&string1"="&string1_check"),
30 desc=Basic String Compare,
31 outds=work.test_results
32)
33
34
35/* TEST 2 - File append */
36%let string2=test2;
37%let path2=%sysfunc(pathname(work))/somefile.txt;
38data _null_;
39 file "&path2";
40 put "&string2";
41run;
42%mp_binarycopy(inloc="&path2", outref=myref, mode=APPEND)
43data _null_;
44 infile myref;
45 input;
46 put _infile_;
47 if _n_=2 then call symputx('string2_check',_infile_);
48run;
49%mp_assert(
50 iftrue=("&string2"="&string2_check"),
51 desc=Append Check (file to ref),
52 outds=work.test_results
53)
54
55/* TEST 3 - File create (ref to existing file) */
56%let string3=test3;
57%let path3=%sysfunc(pathname(work))/somefile3.txt;
58filename tmp3 temp;
59data _null_;
60 file tmp3;
61 put "&string3";
62run;
63data _null_;
64 file "&path3";
65 put "this should not be returned";
66run;
67%mp_binarycopy(inref=tmp3, outloc="&path3")
68data _null_;
69 infile "&path3";
70 input;
71 put _infile_;
72 if _n_=1 then call symputx('string3_check',_infile_);
73run;
74%mp_assert(
75 iftrue=("&string3"="&string3_check"),
76 desc=Append Check (ref to existing file),
77 outds=work.test_results
78)
79
80/* TEST 4 - File append (ref to file) */
81%let string4=test4;
82%let string4_check=;
83filename tmp4 temp;
84data _null_;
85 file tmp4;
86 put "&string4";
87run;
88%mp_binarycopy(inref=tmp4, outloc="&path3",mode=APPEND)
89data _null_;
90 infile "&path3";
91 input;
92 put _infile_;
93 if _n_=2 then call symputx('string4_check',_infile_);
94run;
95%mp_assert(
96 iftrue=("&string4"="&string4_check"),
97 desc=Append Check (ref to file),
98 outds=work.test_results
99)