21%let root=%sysfunc(pathname(work))/top;
28libname test
"&root/a/e/f";
33%mddl_dirlist(work.dirlist_schema)
35%let dirlist_userref=%mf_getuniquefileref();
36%let dirlist_userpath=%sysfunc(pathname(&dirlist_userref));
38%macro dirlist_snapshot();
40 create table work.dirlist_refs_before as
41 select distinct fileref from dictionary.extfiles
42 where substr(fileref,1,1)=
'_' and lengthn(fileref)=8
43 and verify(substr(fileref,2),
'0123456789')=0;
45%mend dirlist_snapshot;
46%macro dirlist_checkrefs(desc);
48 select count(distinct fileref) into :dirlist_newrefs trimmed
49 from dictionary.extfiles
50 where substr(fileref,1,1)=
'_' and lengthn(fileref)=8
51 and verify(substr(fileref,2),
'0123456789')=0
52 and fileref not in (select fileref from work.dirlist_refs_before);
54 %mp_assert(iftrue=(&dirlist_newrefs=0),desc=&desc)
55%mend dirlist_checkrefs;
58%mp_assertscope(SNAPSHOT)
59%mp_dirlist(path=&root, outds=myTable, maxdepth=MAX)
60%mp_assertscope(COMPARE,
61 desc=Test 1: mp_dirlist does not leak scope,
62 outds=work.test_results
64%dirlist_checkrefs(Directory listing releases its temporary filerefs)
66%mp_assertmodel(work.mytable,base=work.dirlist_schema,
67 desc=Populated output matches directory model)
70 iftrue=(%mf_nobs(work.mytable)=6),
71 desc=All levels returned,
72 outds=work.test_results
75%mp_dirlist(path=&root, outds=myTable2, maxdepth=2)
78 iftrue=(%mf_nobs(work.mytable2)=5),
79 desc=Top two levels returned,
80 outds=work.test_results
83%mp_dirlist(path=&root, outds=work.myTable3, maxdepth=0)
86 iftrue=(%mf_nobs(work.mytable3)=2),
87 desc=Top level returned,
88 outds=work.test_results
92%mp_dirlist(path=&root/b, outds=work.myTable4)
93%dirlist_checkrefs(Empty directory releases its temporary filerefs)
94%mp_assertmodel(work.mytable4,base=work.dirlist_schema,
95 desc=Empty output matches directory model)
97 iftrue=(%mf_nobs(work.mytable4)=0),
98 desc=Empty table
for empty directory,
99 outds=work.test_results
103%mp_dirlist(path=&root/notexisting, outds=work.myTable5)
104%dirlist_checkrefs(Missing directory releases its temporary filerefs)
106 iftrue=(%mf_nobs(work.mytable5)=0),
107 desc=Empty table
for non-existing directory,
108 outds=work.test_results
114%mp_dirlist(path=&root, outds=work.myTable6, maxdepth=MAX, maxobs=3)
116 iftrue=(%mf_nobs(work.mytable6)=3),
117 desc=Rows are capped by maxobs,
118 outds=work.test_results
121%mp_dirlist(path=&root, outds=work.myTable7, maxdepth=MAX, maxobs=100)
123 iftrue=(%mf_nobs(work.mytable7)=6),
124 desc=A maxobs above the tree size returns everything,
125 outds=work.test_results
131%mp_dirlist(path=&root, outds=work.myTable8, maxdepth=0, showparent=YES)
133 iftrue=(%mf_nobs(work.mytable8)=3),
134 desc=Showparent adds one row
for the parent,
135 outds=work.test_results
142 set work.mytable end=eof;
144 if level>maxlevel then maxlevel=level;
145 if eof then call symputx('maxlevel',maxlevel,
'l');
148 iftrue=(&maxlevel=3),
149 desc=Deepest entry is three levels below the parent,
150 outds=work.test_results
158 if filename=
'a' then call symputx('type_a',file_or_folder,
'l');
159 if filename='ds1.sas7bdat' then call symputx('type_ds1',file_or_folder,
'l');
162 iftrue=(
"%upcase(&type_a)"=
"FOLDER"),
163 desc=A directory entry is classified as a folder,
164 outds=work.test_results
167 iftrue=(
"%upcase(&type_ds1)"=
"FILE"),
168 desc=A dataset file is classified as a file,
169 outds=work.test_results
177%mp_dirlist(path=, outds=work.myTable9)
178%dirlist_checkrefs(Root listing releases its temporary filerefs)
180 ref=symget('dirlist_userref');
181 preserved=(fileref(ref)<=0 and pathname(ref)=symget('dirlist_userpath'));
182 call symputx('dirlist_preserved',preserved);
184%mp_assert(iftrue=(&dirlist_preserved=1),
185 desc=Listing preserves caller-owned fileref)
186%let dirlist_rc=%sysfunc(filename(dirlist_userref));
188 iftrue=(%mf_nobs(work.mytable9)>=1),
189 desc=A blank path returns the platform roots,
190 outds=work.test_results
193 set work.mytable9(obs=1);
194 call symputx('rootpath',filepath,
'l');
197 iftrue=(%length(&rootpath)>=1),
198 desc=The root entry carries a path,
199 outds=work.test_results
208 file
"&root/plain.txt";
211%mp_dirlist(path=&root, outds=work.myTable10)
213 set work.mytable10(where=(filename='plain.txt'));
214 call symputx('type_txt',file_or_folder,
'l');
215 call symputx('msg_txt',msg,
'l');
218 iftrue=(
"%upcase(&type_txt)"=
"FILE"),
219 desc=A text file is classified as a file,
220 outds=work.test_results
227 set work.test_results;
228 putlog 'TEST_RESULT_LINE: ' test_result ' - ' test_description;