SASUnit Examples  Version 1.5.0
_reportautonhtml.sas
Go to the documentation of this file.
1 
24 %MACRO _reportAutonHTML (i_repdata =
25  ,o_html = 0
26  ,o_path =
27  ,o_file =
28  );
29 
30  /*-- determine number of scenarios
31  and number of test cases per unit under test ----------------------------*/
32  %LOCAL d_rep1 d_rep2 l_tcg_res l_pgmLibraries l_pgmLib l_title l_logpath l_cAuton;
33 
34  %_tempFileName(d_rep1)
35  %_tempFileName(d_rep2)
36 
37  PROC MEANS NOPRINT NWAY missing DATA=&i_repdata(KEEP=cas_auton pgm_id scn_id cas_id);
38  class cas_auton pgm_id scn_id cas_id;
39  OUTPUT OUT=&d_rep1. (rename=(_FREQ_=scn_tst));
40  RUN;
41 
42  PROC MEANS NOPRINT NWAY missing DATA=&d_rep1.(KEEP=cas_auton pgm_id scn_id scn_tst);
43  class cas_auton pgm_id scn_id;
44  OUTPUT OUT=&d_rep2. (rename=(_FREQ_=scn_cas)) sum(scn_tst)=scn_tst;
45  RUN;
46 
47  PROC SORT DATA=&i_repdata. out=work._auton_report;
48  BY cas_auton pgm_id scn_id;
49  RUN;
50 
51  DATA work._auton_report;
52  SET work._auton_report;
53  BY cas_auton pgm_id scn_id;
54  IF (first.scn_id);
55  RUN;
56 
57  DATA work._auton_report;
58  MERGE work._auton_report &d_rep2.;
59  BY cas_auton pgm_id scn_id;
60  RUN;
61 
62  /* Visualize crossreference data */
63  %IF &g_crossref. EQ 1 %THEN %DO;
64  PROC SQL;
65  create view prepareDependency as
66  select distinct cas_pgm as name
67  from target.cas
68  QUIT;
69 
70  DATA macrolistDependency;
71  SET prepareDependency;
72  /* remove .sas extension */
73  name = substr(name, 1, length(name)-4);
74  /* get program name in case absolute path has been specified */
75  pos = find(name,'/',-999);
76  IF pos GT 0 THEN DO;
77  len = length(trim(name));
78  name = substr(name,pos+1,len-pos);
79  END;
80  RUN;
81 
82  /* Create .json Files for visualisation with D3 */
83  %_dependency(i_dependencies = &d_listcalling.
84  ,i_macroList = macrolistDependency
85  );
86  /* Use Json Files to create JavaScript file containing dependency information */
87  %_dependency_agg(i_path = &g_target/tst/crossreference
88  ,o_file = &l_output/js/data.refs.js
89  );
90  %END;
91 
92  /* Delete data sets after json files have been created */
93  PROC DATASETS NOLIST NOWARN LIB=%scan(&d_listcalling,1,.);
94  DELETE %SCAN(&d_macrolist,2,.);
95  DELETE %SCAN(&d_listcalling,2,.);
96  QUIT;
97 
98  %IF &g_testcoverage. EQ 1 %THEN %DO;
99  /*-- in the log subdir: append all *.tcg files to one file named 000.tcg
100  This is done in order to get one file containing coverage data
101  of all calls to the macros under test -----------------------------------*/
102 
103  %LET l_rc =%_delFile("&g_log/000.tcg");
104 
105  %LET l_logpath=%_escapeBlanks(&g_log.);
106 
107  FILENAME allfiles "&l_logpath./*.tcg";
108  DATA _NULL_;
109  INFILE allfiles end=done dlm=',';
110  FILE "&l_logpath./000.tcg";
111  INPUT row :$256.;
112  PUT row;
113  RUN;
114 
115  /*-- for every unit under test (see ‘target’ database ):
116  call new macro _reporttcghtml.sas once in order to get a html
117  file showing test coverage for the given unit under test. For every call,
118  use the 000.tcg file as coverage analysis text file ---------------------*/
119 
120  PROC SQL NOPRINT;
121  SELECT DISTINCT cas_pgm
122  INTO :l_unitUnderTestList SEPARATED BY '*'
123  FROM work._auton_report;
124  QUIT;
125  /* Add col tcg_pct to data set &d_rep1 to store coverage percentage for report generation*/
126  DATA work._auton_report (COMPRESS=YES);
127  LENGTH tcg_pct 8;
128  SET work._auton_report;
129  tcg_pct = .;
130  RUN;
131 
132  %LET l_listCount=%sysfunc(countw(&l_unitUnderTestList.,'*'));
133  %do i = 1 %to &l_listCount;
134  %LET l_currentUnit=%lowcase(%scan(&l_unitUnderTestList,&i,*));
135  %IF "%sysfunc(compress(&l_currentUnit.))" EQ "" %THEN %DO;
136  %LET l_tcg_res = .;
137  %END;
138  %ELSE %DO;
139  /*determine where macro source file is located*/
140  %let l_currentUnitLocation=;
141  %let l_currentUnitFileName=;
142  %IF (%SYSFUNC(FILEEXIST(&l_currentUnit.))) %THEN %DO; /*full absolute path given*/
143  %_getAbsPathComponents(
144  i_absPath = &l_currentUnit
145  , o_fileName = l_currentUnitFileName
146  , o_pathWithoutName = l_currentUnitLocation
147  )
148  %END;
149  %ELSE %DO; /*relative path given*/
150  %IF (%SYSFUNC(FILEEXIST(&g_root./&l_currentUnit.))) %THEN %DO; /*relative path in root dir */
151  %_getAbsPathComponents(
152  i_absPath = &g_root./&l_currentUnit.
153  , o_fileName = l_currentUnitFileName
154  , o_pathWithoutName = l_currentUnitLocation
155  )
156  %END;
157  %ELSE %DO; /*relative path in one of the sasautos dirs */
158  %IF (%SYSFUNC(FILEEXIST(&g_sasunit./&l_currentUnit.))) %THEN %DO;
159  %_getAbsPathComponents(
160  i_absPath = &g_sasunit./&l_currentUnit.
161  , o_fileName = l_currentUnitFileName
162  , o_pathWithoutName = l_currentUnitLocation
163  )
164  %END;
165  %ELSE %IF (%SYSFUNC(FILEEXIST(&g_sasunit_os./&l_currentUnit.))) %THEN %DO;
166  %_getAbsPathComponents(
167  i_absPath = &g_sasunit_os./&l_currentUnit.
168  , o_fileName = l_currentUnitFileName
169  , o_pathWithoutName = l_currentUnitLocation
170  )
171  %END;
172  %ELSE %DO;
173  %LET j = 0;
174  %DO %UNTIL ("&l_currentUnitLocation." NE "" OR &j. EQ 10);
175  %IF (%SYSFUNC(FILEEXIST(&&g_sasautos&j/&l_currentUnit.))) %THEN %DO;
176  %_getAbsPathComponents(
177  i_absPath = &&g_sasautos&j/&l_currentUnit.
178  , o_fileName = l_currentUnitFileName
179  , o_pathWithoutName = l_currentUnitLocation
180  )
181  %END;
182  %LET j = %EVAL(&j + 1);
183  %END;
184  %END;
185  %END;
186  %END;
187  %let l_tcg_res=.;
188 
189  %IF ("&l_currentUnitFileName." NE "" AND "&l_currentUnitLocation." NE ""
190  AND %SYSFUNC(FILEEXIST(&l_currentUnitLocation./&l_currentUnitFileName.))
191  AND %SYSFUNC(FILEEXIST(&g_log./000.tcg)) ) %THEN %DO;
192  %_reporttcghtml(i_macroName = &l_currentUnitFileName.
193  ,i_macroLocation = &l_currentUnitLocation.
194  ,i_mCoverageName = 000.tcg
195  ,i_mCoverageLocation = &g_log
196  ,o_outputFile = tcg_%SCAN(&l_currentUnitFileName.,1,.)
197  ,o_outputPath = &g_target/rep
198  ,o_resVarName = l_tcg_res
199  ,o_html = &o_html.
200  );
201  %END;
202  %END; /*%ELSE %DO;*/
203  /*store coverage percentage for report generation*/
204  PROC SQL NOPRINT;
205  UPDATE work._auton_report
206  SET tcg_pct=&l_tcg_res.
207  WHERE upcase(cas_pgm) EQ "%upcase(&l_currentUnit.)";
208  QUIT;
209  %end; /*do i = 1 to &l_listCount*/
210 
211  %END;
212 
213  PROC SQL NOPRINT;
214  SELECT DISTINCT cas_auton
215  INTO :l_pgmLibraries SEPARATED BY '§'
216  FROM work._auton_report;
217  QUIT;
218 
219  title;
220  footnote;
221  options nocenter;
222 
223  %let l_title=%str(&g_nls_reportAuton_001 | &g_project - SASUnit &g_nls_reportAuton_002);
224  title j=c "&l_title.";
225 
226  %if (&o_html.) %then %do;
227  ods html4 file="&o_path./&o_file..html"
228  (TITLE="&l_title.")
229  headtext='<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />'
230  metatext="http-equiv=""Content-Style-Type"" content=""text/css"" /><meta http-equiv=""Content-Language"" content=""&i_language."" /"
231  style=styles.SASUnit stylesheet=(URL="css/SAS_SASUnit.css")
232  encoding="&g_rep_encoding.";
233  %_reportPageTopHTML(i_title = &l_title.
234  ,i_current = 4
235  )
236  %end;
237 
238  options missing=" ";
239  %LET l_listCount=%sysfunc(countw(&l_pgmLibraries.,'§'));
240  %do i = 1 %to &l_listCount.;
241  %LET l_pgmLib=%lowcase(%scan(&l_pgmLibraries,&i,§));
242  %LET l_cAuton=;
243  %IF (l_pgmLib ne .) %THEN %DO;
244  %LET l_cAuton=%sysfunc (putn(&l_pgmLib.,z3.))_;
245  %END;
246  data work._current_auton;
247  length pgmColumn scenarioColumn caseColumn assertColumn
248  %IF &g_testcoverage. EQ 1 %THEN %DO;
249  coverageColumn
250  %END;
251  %IF &g_crossref. EQ 1 %THEN %DO;
252  crossrefColumn
253  %END;
254  resultColumn
255  linkTitle0 linkTitle1 LinkTitle2 LinkTitle3 LinkTitle4 LinkTitle5
256  linkColumn0 linkColumn1 LinkColumn2 LinkColumn3 LinkColumn4 LinkColumn5 $1000
257  _autonColumn autonColumn cas_abs_path scn_abs_path $400;
258  set work._auton_report (where=(cas_auton=&l_pgmLib.));
259  ARRAY sa(0:9) tsu_sasautos tsu_sasautos1-tsu_sasautos9;
260  label
261  pgmColumn="&g_nls_reportAuton_005."
262  scenarioColumn="&g_nls_reportAuton_006."
263  caseColumn="&g_nls_reportAuton_007."
264  assertColumn="&g_nls_reportAuton_014."
265  %IF &g_testcoverage. EQ 1 %THEN %DO;
266  coverageColumn="&g_nls_reportAuton_016." [%]
267  %END;
268  %IF &g_crossref. EQ 1 %THEN %DO;
269  crossrefColumn="&g_nls_reportAuton_022."
270  %END;
271  resultColumn="&g_nls_reportAuton_008.";
272 
273  if (cas_pgm="^_") then cas_pgm="";
274  IF cas_auton = . THEN DO;
275  cas_abs_path = resolve ('%_abspath(&g_root,' !! trim(cas_pgm) !! ')');
276  END;
277  ELSE IF cas_auton = 0 THEN DO;
278  cas_abs_path = resolve ('%_abspath(&g_sasunit,' !! trim(cas_pgm) !! ')');
279  END;
280  ELSE IF cas_auton = 1 THEN DO;
281  cas_abs_path = resolve ('%_abspath(&g_sasunit_os,' !! trim(cas_pgm) !! ')');
282  END;
283  ELSE DO;
284  cas_abs_path = resolve ('%_abspath(&g_sasautos' !! put (cas_auton-2,1.) !! ',' !! trim(cas_pgm) !! ')');
285  END;
286  scn_abs_path = resolve ('%_abspath(&g_root,' !! trim(scn_path) !! ')');
287 
288  %_render_dataColumn(i_sourceColumn=scn_cas
289  ,o_targetColumn=caseColumn
290  );
291  %_render_dataColumn(i_sourceColumn=scn_tst
292  ,o_targetColumn=assertColumn
293  );
294  %_render_iconColumn(i_sourceColumn=scn_res
295  ,o_html=&o_html.
296  ,o_targetColumn=resultColumn
297  );
298  if (cas_auton = .) then do;
299  _autonColumn = "&g_nls_reportAuton_015.";
300  end;
301  else do;
302  if (cas_auton = 0) then do;
303  _autonColumn = tsu_sasunit;
304  linkTitle0 = symget("g_sasunit");
305  end;
306  else if (cas_auton = 1) then do;
307  _autonColumn = tsu_sasunit_os;
308  linkTitle0 = symget("g_sasunit_os");
309  end;
310  else do;
311  _autonColumn = sa(cas_auton-2);
312  linkTitle0 = symget("g_sasautos" !! put(cas_auton-2, z1.));
313  end;
314  linkColumn0 = "file:
315  linkTitle0 = "&g_nls_reportAuton_009. " !! linkTitle0;
316  end;
317  %_render_dataColumn(i_sourceColumn=_autonColumn
318  ,i_linkColumn=LinkColumn0
319  ,i_linkTitle=LinkTitle0
320  ,o_targetColumn=autonColumn
321  );
322  autonColumn="&g_nls_reportAuton_003.: " !! trim(autonColumn);
323 
324  *** Any destination that renders links shares this if ***;
325  %if (&o_html.) %then %do;
326  LinkTitle1 = "&g_nls_reportAuton_009." !! byte(13) !! cas_abs_path;
327  LinkTitle2 = "&g_nls_reportAuton_010." !! byte(13) !! scn_abs_path;
328  LinkTitle3 = "&g_nls_reportAuton_017. " !! cas_pgm;
329  LinkTitle4 = trim(cas_pgm) !! " &g_nls_reportAuton_025.";
330  LinkTitle5 = trim(cas_pgm) !! " &g_nls_reportAuton_026.";
331 
332  *** HTML-links are destination specific ***;
333  %if (&o_html.) %then %do;
334  LinkColumn1 = "file:
335  LinkColumn2 = CATT("cas_overview.html#SCN", PUT(scn_id,z3.), "_");
336  IF compress(cas_pgm) ne '' THEN DO;
337  IF index(cas_pgm,'/') GT 0 THEN DO;
338  LinkColumn3 = 'tcg_'||trim(LEFT(SCAN(SUBSTR(cas_pgm, findw(cas_pgm, SCAN(cas_pgm, countw(cas_pgm,'/'),'/'))),1,".") !! ".html"));
339  END;
340  ELSE DO;
341  LinkColumn3 = 'tcg_'||TRIM(LEFT(SCAN(cas_pgm,1,".") !! ".html"));
342  END;
343  END;
344  LinkColumn4 = "&g_nls_reportAuton_023.";
345  LinkColumn5 = "&g_nls_reportAuton_024.";
346  %end;
347 
348  %_render_dataColumn(i_sourceColumn=cas_pgm
349  ,i_linkColumn=LinkColumn1
350  ,i_linkTitle=LinkTitle1
351  ,o_targetColumn=pgmColumn
352  );
353  %_render_dataColumn(i_sourceColumn=scn_id
354  ,i_format=z3.
355  ,i_linkColumn=LinkColumn2
356  ,i_linkTitle=LinkTitle2
357  ,o_targetColumn=scenarioColumn
358  );
359  %IF &g_testcoverage. EQ 1 %THEN %DO;
360  %_render_dataColumn(i_sourceColumn=tcg_pct
361  ,i_format=3.
362  ,i_linkColumn=LinkColumn3
363  ,i_linkTitle=LinkTitle3
364  ,o_targetColumn=coverageColumn
365  );
366  %END;
367  %IF &g_crossref. EQ 1 %THEN %DO;
368  %_render_crossrefColumn (i_sourceColumn = %sysfunc(trim(cas_pgm))
369  ,o_targetColumn = crossrefColumn
370  ,i_linkColumn_caller = LinkColumn4
371  ,i_linkTitle_caller = LinkTitle4
372  ,i_linkColumn_called = LinkColumn5
373  ,i_linkTitle_called = LinkTitle5
374  );
375  %END;
376  %END;
377  RUN;
378 
379  %IF (&i. = &l_listCount.) %THEN %DO;
380  %_reportFooter(o_html=&o_html.);
381  %END;
382 
383  %IF (&o_html.) %THEN %DO;
384  ods html4 anchor="AUTON&l_cAuton.";
385  %END;
386 
387  PROC REPORT DATA=work._current_auton nowd missing spanrows
388  style(lines)=blindData
389  ;
390 
391  columns pgm_id pgmColumn scenarioColumn caseColumn assertColumn
392  %IF &g_testcoverage. EQ 1 %THEN %DO;
393  coverageColumn
394  %END;
395  %IF &g_crossref. EQ 1 %THEN %DO;
396  crossrefColumn
397  %END;
398  resultColumn autonColumn;
399 
400  define autonColumn / noprint;
401  define pgm_id / order noprint;
402  define pgmColumn / order;
403  define scenarioColumn / order style(column)=[just=right];
404  define caseColumn / order style(column)=[just=right];
405  define assertColumn / order style(column)=[just=right];
406  %IF &g_testcoverage. EQ 1 %THEN %DO;
407  define coverageColumn / order style(column)=[just=right];
408  %END;
409  %IF &g_crossref. EQ 1 %THEN %DO;
410  define crossrefColumn / order style(column)=[just=right];
411  %END;
412  define resultColumn / order style(COLUMN)=[background=white];
413 
414  compute before _page_;
415  line @1 autonColumn $;
416  endcomp;
417  RUN;
418 
419  *** Supress title between testcases ***;
420  %IF (&i. = 1) %THEN %DO;
421  title;
422  %END;
423 
424  *** Render separation line between program libraries ***;
425  %IF (&o_html. AND &i. ne &l_listCount.) %THEN %DO;
426  ods html4 text="^{RAW <hr size=""1"">}";
427  %END;
428 
429  PROC DELETE data=work._current_auton;
430  RUN;
431  %END;
432  OPTIONS missing=.;
433 
434 
435  %IF (&o_html.) %THEN %DO;
436  %_closeHtmlPage;
437  %END;
438 
439  TITLE;
440  FOOTNOTE;
441  OPTIONS center;
442 
443 
444  PROC DELETE DATA=work._auton_report;
445  RUN;
446 %MEND _reportAutonHTML;