SASUnit Examples  Version 1.5.0
reportsasunit.sas
Go to the documentation of this file.
1 
29 %MACRO reportSASUnit (i_language = EN
30  ,o_html = 1
31  ,o_junit = 0
32  ,o_force = 0
33  ,o_output =
34  );
35 
36  %LOCAL l_macname;
37  %LET l_macname=&sysmacroname;
38 
39  /*-- check parameters --------------------------------------------------------*/
40  %IF "&o_html" NE "1" %THEN %LET o_html=0;
41 
42  %IF "&o_force" NE "1" %THEN %LET o_force=0;
43 
44  %IF "&o_junit" NE "1" %THEN %LET o_junit=0;
45 
46  %IF ("&o_html" NE "1" AND "&o_junit" NE "1") %THEN %DO;
47  %GOTO exit;
48  %END;
49 
50  %_nls (i_language=&i_language)
51 
52  /*-- check if target folder exists -------------------------------------------*/
53  %LOCAL l_output;
54  %IF %length(&o_output) %THEN %LET l_output=&o_output;
55  %ELSE %LET l_output =&g_target/rep;
56  %LET l_output=%_abspath(&g_root,&l_output);
57 
58  %IF %_handleError(&l_macname.
59  ,InvalidOutputDir
60  ,NOT %_existDir(&l_output)
61  ,Error in parameter o_output: target folder does not exist
62  ,i_verbose=&g_verbose.
63  )
64  %THEN %GOTO errexit;
65 
66  /*-- check if test database can be accessed ----------------------------------*/
67  %IF %_handleError(&l_macname.
68  ,NoTestDB
69  ,NOT %sysfunc(exist(target.tsu)) OR NOT %symexist(g_project)
70  ,%nrstr(Test database cannot be accessed, call initSASUnit before reportSASUnit)
71  ,i_verbose=&g_verbose.
72  )
73  %THEN %GOTO errexit;
74 
75  /*-- generate temporary datasets ---------------------------------------------*/
76  %LOCAL
77  d_rep
78  d_scn
79  d_cas01
80  d_auton
81  d_pgm
82  d_pcs
83  d_emptyscn
84  d_cas
85  d_tst
86  ;
87  %_tempFilename(d_rep)
88  %_tempFilename(d_scn)
89  %_tempFilename(d_cas01)
90  %_tempFilename(d_auton)
91  %_tempFilename(d_pgm)
92  %_tempFilename(d_pcs)
93  %_tempFilename(d_emptyscn)
94  %_tempFilename(d_cas)
95  %_tempFilename(d_tst)
96 
97 
98  /*-- check for empty scenarios and generate entries in temporary copies of cas and tst datasets,
99  in order to make scenario appear in report with a dummy test case --------------------------- */
100  %LOCAL
101  l_sEmptyScnDummyCasDesc
102  ;
103  %LET l_sEmptyScnDummyCasDesc = %STR(no valid test case found - must be red!);
104 
105  PROC SQL NOPRINT;
106  CREATE TABLE &d_emptyscn. AS
107  SELECT
108  t1.scn_id
109  FROM target.scn t1
110  WHERE t1.scn_id NOT IN
111  (
112  SELECT
113  Distinct cas_scnid
114  FROM target.cas
115  )
116  ;
117  QUIT;
118 
119 
120  PROC SQL NOPRINT;
121  CREATE TABLE &d_cas. AS
122  SELECT
123  t1.*
124  FROM target.cas t1
125  ;
126  INSERT INTO &d_cas.
127  (
128  cas_scnid
129  ,cas_id
130  ,cas_auton
131  ,cas_pgm
132  ,cas_desc
133  ,cas_spec
134  ,cas_start
135  ,cas_end
136  ,cas_res
137  )
138  (
139  SELECT
140  scn_id
141  ,1
142  ,.
143  ,'^_'
144  ,"&l_sEmptyScnDummyCasDesc."
145  ,'^_'
146  ,.
147  ,.
148  ,2
149  FROM &d_emptyscn.
150  )
151  ;
152  QUIT;
153 
154  PROC SQL NOPRINT;
155  CREATE TABLE &d_tst. AS
156  SELECT
157  t1.*
158  FROM target.tst t1
159  ;
160  INSERT INTO &d_tst.
161  (
162  tst_scnid
163  ,tst_casid
164  ,tst_id
165  ,tst_type
166  ,tst_desc
167  ,tst_exp
168  ,tst_act
169  ,tst_res
170  ,tst_errmsg
171  )
172  (
173  SELECT
174  scn_id
175  ,1
176  ,0
177  ,'^_'
178  ,'^_'
179  ,'^_'
180  ,'^_'
181  ,2
182  ,''
183  FROM &d_emptyscn.
184  )
185  ;
186  QUIT;
187 
188  /*-- generate a last-flag for treeview ---------------------------------------*/
189  PROC SORT DATA=target.scn OUT=&d_scn;
190  BY scn_id;
191  RUN;
192  DATA &d_scn;
193  SET &d_scn END=eof;
194  scn_last = eof;
195  RUN;
196 
197  PROC SORT DATA=&d_cas OUT=&d_cas01;
198  BY cas_scnid cas_id;
199  RUN;
200  DATA &d_cas01;
201  SET &d_cas01;
202  BY cas_scnid;
203  cas_last = last.cas_scnid;
204  cas_pgmucase = upcase(cas_pgm);
205  RUN;
206 
207  PROC SORT DATA=&d_cas (KEEP=cas_auton RENAME=(cas_auton=auton_id))
208  OUT=&d_auton NODUPKEY;
209  BY auton_id;
210  RUN;
211  DATA &d_auton;
212  SET &d_auton END=eof;
213  auton_last = eof;
214  RUN;
215 
216  DATA &d_pgm;
217  SET &d_cas (KEEP=cas_auton cas_pgm RENAME=(cas_auton=pgm_auton cas_pgm=pgm_ucase));
218  pgm_ucase = upcase(pgm_ucase);
219  RUN;
220  PROC SORT DATA=&d_pgm NODUPKEY;
221  BY pgm_auton pgm_ucase;
222  RUN;
223  DATA &d_pgm._;
224  SET &d_pgm.;
225  BY pgm_auton;
226  IF first.pgm_auton THEN pgm_id=0;
227  pgm_id+1;
228  pgm_last = last.pgm_auton;
229  RUN;
230  PROC SQL NOPRINT;
231  create table work.pgm_res as
232  select upcase (cas_pgm) as pgm_ucase
233  ,max (cas_res) as pgm_res
234  from &d_cas.
235  group by cas_pgm;
236  create table &d_pgm. as
237  select a.*
238  ,b.pgm_res
239  from &d_pgm._ a left join work.pgm_res b
240  on a.pgm_ucase = b.pgm_ucase;
241  quit;
242 
243  DATA &d_pcs;
244  SET &d_cas (KEEP=cas_auton cas_pgm cas_scnid cas_id RENAME=(cas_auton=pcs_auton cas_pgm=pcs_ucase cas_scnid=pcs_scnid cas_id=pcs_casid));
245  pcs_ucase = upcase(pcs_ucase);
246  RUN;
247  PROC SORT DATA=&d_pcs OUT=&d_pcs NODUPKEY;
248  BY pcs_auton pcs_ucase pcs_scnid pcs_casid;
249  RUN;
250  DATA &d_pcs.;
251  SET &d_pcs.;
252  BY pcs_auton pcs_ucase;
253  pcs_last = last.pcs_ucase;
254  RUN;
255 
256  /*-- create reporting dataset ------------------------------------------------*/
257  %LOCAL i;
258 
259  PROC SQL NOPRINT;
260  CREATE TABLE &d_rep (COMPRESS=YES) AS
261  SELECT
262  tsu_project
263  ,tsu_root
264  ,tsu_target
265  ,tsu_sasunit
266  ,tsu_sasunit_os
267  ,tsu_sasautos
268  %DO i=1 %TO 9;
269  ,tsu_sasautos&i
270  %END;
271  ,tsu_autoexec
272  ,tsu_sascfg
273  ,tsu_sasuser
274  ,tsu_testdata
275  ,tsu_refdata
276  ,tsu_doc
277  ,tsu_lastinit
278  ,tsu_lastrep
279  ,tsu_dbversion
280  ,scn_id
281  ,scn_path
282  ,scn_desc
283  ,scn_start
284  ,scn_end
285  ,scn_rc
286  ,scn_res
287  ,scn_errorcount
288  ,scn_warningcount
289  ,scn_last
290  ,cas_id
291  ,cas_auton
292  ,auton_last
293  ,cas_pgm
294  ,pgm_id
295  ,pgm_last
296  ,pcs_last
297  ,pgm_res
298  ,cas_desc
299  ,cas_spec
300  ,cas_start
301  ,cas_end
302  ,cas_res
303  ,cas_last
304  ,tst_id
305  ,tst_type
306  ,tst_desc
307  ,tst_exp
308  ,tst_act
309  ,tst_res
310  ,tst_errmsg
311  FROM
312  target.tsu
313  ,&d_scn
314  ,&d_cas01.
315  ,&d_tst
316  ,&d_auton
317  ,&d_pgm
318  ,&d_pcs
319  WHERE
320  scn_id = cas_scnid AND
321  cas_scnid = tst_scnid AND
322  cas_id = tst_casid AND
323  cas_auton = auton_id AND
324  cas_auton = pgm_auton AND
325  cas_pgmucase = pgm_ucase AND
326  cas_auton = pcs_auton AND
327  cas_pgmucase = pcs_ucase AND
328  cas_scnid = pcs_scnid AND
329  cas_id = pcs_casid
330  order by scn_id, cas_id, tst_id;
331  CREATE UNIQUE INDEX idx1 ON &d_rep. (scn_id, cas_id, tst_id);
332  CREATE UNIQUE INDEX idx2 ON &d_rep. (cas_auton, pgm_id, scn_id, cas_id, tst_id);
333  QUIT;
334 
335  %IF %_handleError(&l_macname.
336  ,ErrorTestDB
337  ,&syserr. NE 0
338  ,%nrstr(Fehler beim Zugriff auf die Testdatenbank)
339  ,i_verbose=&g_verbose.
340  )
341  %THEN %GOTO errexit;
342 
343  /*-- determine last run ------------------------------------------------------*/
344  %LOCAL
345  l_lastrun
346  l_bOnlyInexistingScnFound
347  ;
348  PROC SQL NOPRINT;
349  SELECT coalesce(max(scn_start),0) FORMAT=12.0 INTO :l_lastrun FROM target.scn;
350  QUIT;
351 
352  /*-- determine whether only invalid scenarios are present (were not run, but shall be reported) ---*/
353  %LET l_bOnlyInexistingScnFound = 1;
354  DATA _NULL_;
355  SET target.scn ( KEEP = scn_start );
356  IF scn_start > 0 THEN DO;
357  /* 'real' scenario found */
358  Call Symputx ('l_bOnlyInexistingScnFound', '0');
359  STOP;
360  END;
361  RUN;
362 
363  /*-- report generator --------------------------------------------------------*/
364  FILENAME repgen temp;
365 
366  *** Create formats used in reports ***;
367  proc format lib=work;
368  value PictName 0 = "&g_sasunitroot./resources/html/ok.png"
369  1 = "&g_sasunitroot./resources/html/manual.png"
370  2 = "&g_sasunitroot./resources/html/error.png"
371  OTHER="?????";
372  value PictNameHTML 0 = "ok.png"
373  1 = "manual.png"
374  2 = "error.png"
375  OTHER="?????";
376  value PictDesc 0 = "OK"
377  1 = "&g_nls_reportDetail_026"
378  2 = "&g_nls_reportDetail_025"
379  OTHER = "&g_nls_reportDetail_027";
380  run;
381 
382  *** set options for ODS ****;
383  ods escapechar="^";
384 
385  *** create style ****;
386  %local l_rc;
387  %let l_rc = %_delfile(&g_sasunitroot./resources/style/template.sas7bitm);
388 
389  libname _style "&g_sasunitroot./resources/style";
390 
391  ods path reset;
392  ods path (PREPEND) _style.template(UPDATE);
393  %_reportCreateStyle;
394  %_reportCreateTagset;
395 
396  ods path reset;
397  ods path (PREPEND) _style.template(READ);
398  ods path (PREPEND) WORK.template(UPDATE);
399 
400  %IF (&o_html.=1) %THEN %DO;
401  %_openDummyHtmlPage;
402  DATA _null_;
403  SET &d_rep;
404  BY scn_id cas_id;
405  FILE repgen;
406 
407  IF _n_=1 THEN DO;
408  /*-- only if testreport is generated competely anew --------------------*/
409  IF tsu_lastrep=0 OR &o_force THEN DO;
410  /*-- copy static files - images, css etc. ---------------------------*/
411  PUT '%_copydir(' /
412  " &g_sasunitroot./resources" '/html/%str(*)' /
413  " ,&l_output" /
414  ")";
415  /*-- create frame HTML page -----------------------------------------*/
416  PUT '%_reportFrameHTML(' /
417  " i_repdata = &d_rep" /
418  " ,o_html = &l_output/index.html" /
419  ")";
420  END;
421  /*-- only if testsuite has been initialized anew after last report -----*/
422  IF tsu_lastinit > tsu_lastrep OR &o_force THEN DO;
423  /*-- convert SAS-log from initSASUnit -------------------------------*/
424  PUT '%_reportLogHTML(' /
425  " i_log = &g_log/000.log" /
426  " ,i_title = &g_nls_reportSASUnit_001" /
427  " ,o_html = &l_output/000_log.html" /
428  ")";
429  /*-- create overview page -------------------------------------------*/
430  PUT '%_reportHomeHTML(' /
431  " i_repdata = &d_rep" /
432  " ,o_html = &o_html." /
433  " ,o_path = &l_output." /
434  " ,o_file = overview" /
435  ")";
436  END;
437  /*-- only if a test scenario has been run since last report ------------*/
438  IF &l_lastrun > tsu_lastrep OR &l_bOnlyInexistingScnFound. OR &o_force. THEN DO;
439  /*-- create table of contents ---------------------------------------*/
440  PUT '%_reportTreeHTML(' /
441  " i_repdata = &d_rep" /
442  " ,o_html = &l_output/tree.html" /
443  ")";
444  /*-- create list of test scenarios ----------------------------------*/
445  PUT '%_reportScnHTML(' /
446  " i_repdata = &d_rep." /
447  " ,o_html = &o_html." /
448  " ,o_path = &l_output." /
449  " ,o_file = scn_overview" /
450  ")";
451  /*-- create list of test cases --------------------------------------*/
452  PUT '%_reportCasHTML(' /
453  " i_repdata = &d_rep" /
454  " ,o_html = &o_html." /
455  " ,o_path = &l_output." /
456  " ,o_file = cas_overview" /
457  ")";
458  /*-- create list of units under test --------------------------------*/
459  PUT '%_reportAutonHTML(' /
460  " i_repdata = &d_rep" /
461  " ,o_html = &o_html." /
462  " ,o_path = &l_output." /
463  " ,o_file = auton_overview" /
464  ")";
465  /*
466  PUT '%_reportpgmdoc(' /
467  " i_language = &i_language." /
468  ")";
469  /**/
470  END;
471  END;
472 
473  /*-- per scenario ---------------------------------------------------------*/
474  IF first.scn_id AND scn_id NE . THEN DO;
475  /*-- only if scenario has been run since report ------------------------*/
476  IF scn_start > tsu_lastrep OR &o_force THEN DO;
477  /*-- convert logfile of scenario ------------------------------------*/
478  PUT '%_reportLogHTML(' /
479  " i_log = &g_log/" scn_id z3. ".log" /
480  " ,i_title = &g_nls_reportSASUnit_002 " scn_id z3. " (" cas_pgm +(-1) ")" /
481  " ,o_html = &l_output/" scn_id z3. "_log.html" /
482  ")";
483  /*-- compile detail information for test case -----------------------*/
484  PUT '%_reportDetailHTML(' /
485  " i_repdata = &d_rep" /
486  " ,i_scnid = " scn_id z3. /
487  " ,o_html = &o_html." /
488  " ,o_path = &l_output." /
489  " ,o_file = cas_" scn_id z3. /
490  ")";
491  END;
492  END;
493 
494  /*-- only if test case has been run since last report ---------------------*/
495  IF cas_start > tsu_lastrep OR &o_force THEN DO;
496 
497  /*-- per test case -----------------------------------------------------*/
498  IF first.cas_id AND scn_id NE . AND cas_id NE . THEN DO;
499  /*-- convert logfile of test case -----------------------------------*/
500  PUT '%_reportLogHTML(' /
501  " i_log = &g_log/" scn_id z3. "_" cas_id z3. ".log" /
502  " ,i_title = &g_nls_reportSASUnit_003 " cas_id z3. " &g_nls_reportSASUnit_004 " scn_id z3. " (" cas_pgm +(-1) ")" /
503  " ,o_html = &l_output/" scn_id z3. "_" cas_id z3. "_log.html" /
504  ")";
505  END;
506 
507  END; /* if test case has been run since last report */
508 
509  RUN;
510 
511  /*-- create report -----------------------------------------------------------*/
512  ODS HTML CLOSE;
513  ODS LISTING CLOSE;
514  %INCLUDE repgen / source2;
515  FILENAME repgen;
516  %END;
517  %IF (&o_junit.=1) %THEN %DO;
518  %_reportJUnitXML(o_file=&l_output./junit.xml)
519  %END;
520 
521  /*-- save last report date ---------------------------------------------------*/
522  PROC SQL NOPRINT;
523  UPDATE target.tsu
524  SET tsu_lastrep = %sysfunc(datetime())
525  ;
526  QUIT;
527 
528  %GOTO exit;
529 %errexit:
530  %PUT;
531  %PUT ======================== Error! reportSASUnit aborted! ==========================================;
532  %PUT;
533  %PUT;
534 %exit:
535  PROC DATASETS NOWARN NOLIST LIB=work;
536  DELETE %scan(&d_rep,2,.) %scan(&d_scn,2,.) %scan(&d_cas01.,2,.) %scan(&d_cas.,2,.) %scan(&d_auton,2,.)
537  %scan(&d_pgm,2,.) %scan(&d_pcs,2,.) %scan(&d_emptyscn.,2,.);
538  QUIT;
539 %MEND reportSASUnit;