Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_zip.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_zip macro
4
5 <h4> SAS Macros </h4>
6 @li mf_mkdir.sas
7 @li mp_assert.sas
8 @li mp_zip.sas
9 @li mp_unzip.sas
10
11**/
12
13%let work=%sysfunc(pathname(work));
14%let root=&work/zipme;
15
16/* sentinels, so a file that never arrives fails the assertion instead of
17 leaving an unresolved macro variable inside the comparison */
18%let content1=FAIL;
19%let content2=FAIL;
20%let content3a=FAIL;
21%let content3b=FAIL;
22
23/* TEST 1 - zip a file */
24%mf_mkdir(&root)
25
26data _null_;
27 file "&root/test.txt";
28 put "houston, this is a test";
29run;
30
31%mp_zip(in=&root/test.txt
32 ,type=FILE
33 ,outpath=&work
34 ,outname=myFile
35)
36
37%mp_unzip(ziploc="&work/myFile.zip",outdir=&work)
38
39data _null_;
40 infile "&work/test.txt";
41 input;
42 call symputx('content1',_infile_);
43 putlog _infile_;
44run;
45
46%mp_assert(
47 iftrue=(
48 %str(&content1)=%str(houston, this is a test)
49 ),
50 desc=Checking if file zip / unzip works,
51 outds=work.test_results
52)
53
54/* TEST 2 - zip a dataset of files */
55data _null_;
56 file "&root/test2.txt";
57 put "houston, this is test2";
58run;
59libname tmp "&root";
60data tmp.test;
61 filepath="&root/test2.txt";
62run;
63
64%mp_zip(in=tmp.test
65 ,incol=filepath
66 ,type=DATASET
67 ,outpath=&work
68 ,outname=myFile2
69)
70
71%mp_unzip(ziploc="&work/myFile2.zip",outdir=&work)
72
73data _null_;
74 infile "&work/test2.txt";
75 input;
76 call symputx('content2',_infile_);
77 putlog _infile_;
78run;
79
80%mp_assert(
81 iftrue=(
82 %str(&content2)=%str(houston, this is test2)
83 ),
84 desc=Checking if file zip / unzip from a dataset works,
85 outds=work.test_results
86)
87
88/* TEST 3 - zip a dataset of files */
89%mf_mkdir(&work/out3)
90
91%mp_zip(in=&root
92 ,type=DIRECTORY
93 ,outpath=&work
94 ,outname=myFile3
95)
96
97%mp_unzip(ziploc="&work/myFile3.zip",outdir=&work/out3)
98
99data _null_;
100 infile "&work/out3/test.txt";
101 input;
102 call symputx('content3a',_infile_);
103 putlog _infile_;
104run;
105data _null_;
106 infile "&work/out3/test2.txt";
107 input;
108 call symputx('content3b',_infile_);
109 putlog _infile_;
110run;
111
112%mp_assert(
113 iftrue=(
114 %str(&content3a)=%str(houston, this is a test)
115 and
116 %str(&content3b)=%str(houston, this is test2)
117 ),
118 desc=Checking if file zip / unzip from a directory works,
119 outds=work.test_results
120)
121
122