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