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