SASUnit Examples  Version 1.3.0
_checkscenario.sas
Go to the documentation of this file.
1 
39 %MACRO _checkScenario(i_scnfile =
40  ,i_changed =
41  ,i_dir =
42  ,r_scnid = l_scnid
43  ,r_run = l_run
44  );
45 
46  %local d_pgm l_scnfile ll_scnid l_lastrun l_pgmcount i l_pgmchanged;
47 
48  %_tempFileName(d_pgm)
49 
50  /*-- set default return value ------------------------------------------------*/
51  %let &r_scnid=;
52  %let &r_run=0;
53 
54  /*-- standardize absolute path -----------------------------------------------*/
55  %let l_scnfile = %_stdPath (&g_root, &i_scnfile);
56 
57  /*-- determine time of last execution of test scenario -----------------------*/
58  %let l_lastrun=0;
59  %let ll_scnid=0;
60  proc sql noprint;
61  select scn_id, compress(put(scn_start,best32.)) into :ll_scnid, :l_lastrun
62  from target.scn
63  where upcase(scn_path) = "%upcase(&l_scnfile)";
64  quit;
65 
66  /*-- execute, if scenario not found or found and changed ---------------------*/
67  %if &l_lastrun<&i_changed %then %do;
68  %put &g_note.(SASUNIT): _checkScenario <1>;
69  %let &r_scnid = &ll_scnid;
70  %let &r_run = 1;
71  %goto exit;
72  %end;
73 
74  /*-- determine units under test in autocall libraries and their change dtime -*/
75  %let l_pgmcount=0;
76  proc sql noprint;
77  select count(*) into :l_pgmcount
78  from target.cas
79  left join &i_dir dir
80  on upcase(cas.cas_pgm) = upcase(scan(dir.filename,-1,'/'))
81  and cas.cas_auton = dir.auton
82  where cas.cas_scnid = &ll_scnid
83  and (&l_lastrun<dir.changed or dir.changed=.)
84  and cas.cas_auton ne .
85  ;
86  quit;
87 
88  /*-- execute, if at least one unit under test is newer or is missing ---------*/
89  %if &l_pgmcount %then %do;
90  %put &g_note.(SASUNIT): _checkScenario <2>;
91  %let &r_scnid = &ll_scnid;
92  %let &r_run = 1;
93  %goto exit;
94  %end;
95 
96  /*-- look for units under test not in autocall libraries ---------------------*/
97  proc sql noprint;
98  create table &d_pgm as
99  select cas.cas_pgm
100  from target.cas
101  where cas.cas_scnid = &ll_scnid
102  and cas.cas_auton=.
103  ;
104  quit;
105 
106  /*-- do not execute if none found --------------------------------------------*/
107  %if %_nobs(&d_pgm) = 0 %then %do;
108  %put &g_note.(SASUNIT): _checkScenario <3>;
109  %let &r_scnid = &ll_scnid;
110  %let &r_run = 0;
111  %goto exit;
112  %end;
113 
114  /*-- determine last modification dtime for those units under test ------------*/
115  %do i=1 %to %_nobs(&d_pgm);
116  %local l_pgm&i;
117  %end;
118  data _null_;
119  set &d_pgm;
120  call symput ('l_pgm' !! compress(put(_n_,8.)), trim(cas_pgm));
121  call symput ('l_pgmcount', compress(put(_n_,8.)));
122  run;
123 
124  %do i=1 %to &l_pgmcount;
125  %let l_pgm&i = %_absPath(&g_root,&&l_pgm&i);
126  %_dir(i_path=&&l_pgm&i, o_out=&d_pgm)
127 
128  %let l_pgmchanged=0;
129  proc sql noprint;
130  select compress(put(changed,best32.)) into :l_pgmchanged
131  from &d_pgm
132  ;
133  quit;
134 
135  /*-- execute scenario, if unit under test newer or not found --------------*/
136  %if &l_lastrun < &l_pgmchanged or &l_pgmchanged=0 %then %do;
137  %put &g_note.(SASUNIT): _checkScenario <4>;
138  %let &r_scnid = &ll_scnid;
139  %let &r_run = 1;
140  %goto exit;
141  %end;
142 
143  %end;
144 
145  /*-- do not execute scenario -------------------------------------------------*/
146  %put &g_note.(SASUNIT): _checkScenario <5>;
147  %let &r_scnid = &ll_scnid;
148  %let &r_run = 0;
149 
150 %exit:
151  /*-- tidy up -----------------------------------------------------------------*/
152  proc datasets nolist nowarn;
153  delete %scan(&d_pgm,2,.);
154  quit;
155 
156 %MEND _checkScenario;