From 7e9e0fac07591f8e66a6fd098a70d259b12195ba Mon Sep 17 00:00:00 2001 From: munja Date: Fri, 11 Mar 2022 11:28:03 +0000 Subject: [PATCH] fix: supporting empty dirs in mp_dirlist. Test updated. --- all.sas | 16 +++++++++------- base/mp_dirlist.sas | 15 ++++++++------- tests/crossplatform/mp_dirlist.test.sas | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/all.sas b/all.sas index f5a7f34..c935ab8 100644 --- a/all.sas +++ b/all.sas @@ -4214,6 +4214,13 @@ data &out_ds(compress=no %end; if rc = 0 then do; did = dopen(fref); + if did=0 then do; + putlog "NOTE: This directory is empty, or does not exist - &path"; + msg=sysmsg(); + put msg; + put _all_; + stop; + end; /* attribute is OS-dependent - could be "Directory" or "Directory Name" */ numopts=doptnum(did); do i=1 to numopts; @@ -4221,12 +4228,6 @@ data &out_ds(compress=no if foption=:'Directory' then i=numopts; end; directory=dinfo(did,foption); - if did=0 then do; - putlog "NOTE: This directory is empty - " directory; - msg=sysmsg(); - put _all_; - stop; - end; rc = filename(fref); end; else do; @@ -4362,7 +4363,8 @@ run; proc sql; drop table &out_ds; -%mend mp_dirlist;/** +%mend mp_dirlist; +/** @file @brief Creates a dataset containing distinct _formatted_ values @details If no format is supplied, then the original value is used instead. diff --git a/base/mp_dirlist.sas b/base/mp_dirlist.sas index a34f193..366ec99 100644 --- a/base/mp_dirlist.sas +++ b/base/mp_dirlist.sas @@ -94,6 +94,13 @@ data &out_ds(compress=no %end; if rc = 0 then do; did = dopen(fref); + if did=0 then do; + putlog "NOTE: This directory is empty, or does not exist - &path"; + msg=sysmsg(); + put msg; + put _all_; + stop; + end; /* attribute is OS-dependent - could be "Directory" or "Directory Name" */ numopts=doptnum(did); do i=1 to numopts; @@ -101,12 +108,6 @@ data &out_ds(compress=no if foption=:'Directory' then i=numopts; end; directory=dinfo(did,foption); - if did=0 then do; - putlog "NOTE: This directory is empty - " directory; - msg=sysmsg(); - put _all_; - stop; - end; rc = filename(fref); end; else do; @@ -242,4 +243,4 @@ run; proc sql; drop table &out_ds; -%mend mp_dirlist; \ No newline at end of file +%mend mp_dirlist; diff --git a/tests/crossplatform/mp_dirlist.test.sas b/tests/crossplatform/mp_dirlist.test.sas index 2bec770..c6cf883 100644 --- a/tests/crossplatform/mp_dirlist.test.sas +++ b/tests/crossplatform/mp_dirlist.test.sas @@ -47,4 +47,18 @@ run; iftrue=(%mf_nobs(work.mytable3)=2), desc=Top level returned, outds=work.test_results -) \ No newline at end of file +) + +%mp_dirlist(path=&root/b, outds=work.myTable4) +%mp_assert( + iftrue=(%mf_nobs(work.mytable4)=0), + desc=Empty table for empty directory, + outds=work.test_results +) + +%mp_dirlist(path=&root/notexisting, outds=work.myTable5) +%mp_assert( + iftrue=(%mf_nobs(work.mytable5)=0), + desc=Empty table for non-existing directory, + outds=work.test_results +)