SASUnit Examples  Version 1.2.1
_sasunit_reportautonhtml.sas
Go to the documentation of this file.
1 
20 /* change history
21  14.02.2013 PW/KL Modified for LINUX
22  08.02.2013 PW implementation of test coverage assessment
23  02.01.2013 KL Added new column "Assertions" and corrected the number in column "Test Cases".
24  program library (none) is now supported under different languages.
25  12.08.2008 AM Mehrsprachigkeit
26  29.12.2007 AM Neuererstellung
27 */
28 
29 %MACRO _sasunit_reportAutonHTML (
30  i_repdata =
31  ,o_html =
32 );
33 
34 /*-- determine number of scenarios
35  and number of test cases per unit under test ----------------------------*/
36 %LOCAL d_rep1 d_rep2 l_tcg_res;
37 %_sasunit_tempFileName(d_rep1)
38 %_sasunit_tempFileName(d_rep2)
39 
40 
41 PROC MEANS NOPRINT NWAY DATA=&i_repdata(KEEP=cas_auton pgm_id scn_id cas_res);
42  BY cas_auton pgm_id scn_id;
43  CLASS cas_res;
44  OUTPUT OUT=&d_rep1 (drop=_type_);
45 RUN;
46 
47 PROC TRANSPOSE DATA=&d_rep1 OUT=&d_rep1 (DROP=_name_) PREFIX=res;
48  BY cas_auton pgm_id scn_id;
49  VAR _freq_;
50  ID cas_res;
51 RUN;
52 
53 PROC MEANS NOPRINT NWAY DATA=&d_rep1(KEEP=cas_auton pgm_id);
54  BY cas_auton pgm_id;
55  OUTPUT OUT=&d_rep2 (DROP=_type_ RENAME=(_freq_=scn_count));
56 RUN;
57 
58 DATA &d_rep1 (COMPRESS=YES);
59  MERGE &i_repdata (KEEP=cas_auton pgm_id scn_id cas_pgm tsu_sasautos tsu_sasautos1-tsu_sasautos9) &d_rep1;
60  BY cas_auton pgm_id scn_id;
61  IF res0=. THEN res0=0;
62  IF res1=. THEN res1=0;
63  IF res2=. THEN res2=0;
64 RUN;
65 
66 DATA &d_rep1 (COMPRESS=YES);
67  MERGE &d_rep1 &d_rep2;
68  BY cas_auton pgm_id;
69 RUN;
70 
71 PROC MEANS NOPRINT NWAY missing DATA=&i_repdata(KEEP=cas_auton pgm_id scn_id cas_id);
72  class cas_auton pgm_id scn_id cas_id;
73  OUTPUT OUT=&d_rep2;
74 RUN;
75 
76 PROC MEANS NOPRINT NWAY missing DATA=&d_rep2(KEEP=cas_auton pgm_id scn_id cas_id);
77  class cas_auton pgm_id scn_id;
78  OUTPUT OUT=&d_rep2 (drop=_type_ cas_id rename=(_freq_=scn_cas)) N=;
79 RUN;
80 
81 DATA &d_rep1 (COMPRESS=YES);
82  MERGE &d_rep1 &d_rep2;
83  BY cas_auton pgm_id scn_id;
84 RUN;
85 
86 %IF &g_testcoverage. EQ 1 %THEN %DO;
87  /*-- in the log subdir: append all *.tcg files to one file named 000.tcg
88  This is done in order to get one file containing coverage data
89  of all calls to the macros under test -----------------------------------*/
90 
91  %let l_rc =%_sasunit_delFile("&g_log/000.tcg");
92 
93  FILENAME allfiles "&g_log/*.tcg";
94  DATA _null_;
95  INFILE allfiles end=done dlm=',';
96  FILE "&g_log/000.tcg";
97  INPUT row :$256.;
98  PUT row;
99  RUN;
100 
101  /*-- for every unit under test (see ‘targetÂ’ database ):
102  call new macro _sasunit_reporttcghtml.sas once in order to get a html
103  file showing test coverage for the given unit under test. For every call,
104  use the 000.tcg file as coverage analysis text file ---------------------*/
105 
106  PROC SQL NOPRINT;
107  SELECT DISTINCT cas_pgm
108  INTO:l_unitUnderTestList SEPARATED BY '*'
109  FROM &d_rep1;
110  QUIT;
111  /* Add col tcg_pct to data set &d_rep1 to store coverage percentage for report generation*/
112  DATA &d_rep1 (COMPRESS=YES);
113  LENGTH tcg_pct 8;
114  SET &d_rep1;
115  tcg_pct = .;
116  RUN;
117 
118  %LET l_listCount=%sysfunc(countw(&l_unitUnderTestList.,'*'));
119  %do i = 1 %to &l_listCount;
120  %LET l_currentUnit=%lowcase(%scan(&l_unitUnderTestList,&i,*));
121  %IF "%sysfunc(compress(&l_currentUnit.))" EQ "" %THEN %DO;
122  %LET l_tcg_res = .;
123  %END;
124  %ELSE %DO;
125  /*determine where macro source file is located*/
126  %let l_currentUnitLocation=;
127  %let l_currentUnitFileName=;
128  %IF (%SYSFUNC(FILEEXIST(&l_currentUnit.))) %THEN %DO; /*full absolute path given*/
129  %_sasunit_getAbsPathComponents(
130  i_absPath = &l_currentUnit
131  , o_fileName = l_currentUnitFileName
132  , o_pathWithoutName = l_currentUnitLocation
133  )
134  %END;
135  %ELSE %DO; /*relative path given*/
136  %IF (%SYSFUNC(FILEEXIST(&g_root./&l_currentUnit.))) %THEN %DO; /*relative path in root dir */
137  %_sasunit_getAbsPathComponents(
138  i_absPath = &g_root./&l_currentUnit.
139  , o_fileName = l_currentUnitFileName
140  , o_pathWithoutName = l_currentUnitLocation
141  )
142  %END;
143  %ELSE %DO; /*relative path in one of the sasautos dirs*/
144  %IF (%SYSFUNC(FILEEXIST(&g_sasautos./&l_currentUnit.))) %THEN %DO;
145  %_sasunit_getAbsPathComponents(
146  i_absPath = &g_sasautos./&l_currentUnit.
147  , o_fileName = l_currentUnitFileName
148  , o_pathWithoutName = l_currentUnitLocation
149  )
150  %END;
151  %ELSE %DO;
152  %LET j = 1;
153  %DO %UNTIL ("&l_currentUnitLocation." NE "" OR &j. EQ 10);
154  %IF (%SYSFUNC(FILEEXIST(&&g_sasautos&j/&l_currentUnit.))) %THEN %DO;
155  %_sasunit_getAbsPathComponents(
156  i_absPath = &&g_sasautos&j/&l_currentUnit.
157  , o_fileName = l_currentUnitFileName
158  , o_pathWithoutName = l_currentUnitLocation
159  )
160  %END;
161  %LET j = %EVAL(&j + 1);
162  %END;
163  %END;
164  %END;
165  %END;
166  %let l_tcg_res=.;
167 
168  %IF ("&l_currentUnitFileName." NE "" AND "&l_currentUnitLocation." NE ""
169  AND %SYSFUNC(FILEEXIST(&l_currentUnitLocation./&l_currentUnitFileName.))
170  AND %SYSFUNC(FILEEXIST(&g_log./000.tcg)) ) %THEN %DO;
171  %_sasunit_reporttcghtml(
172  i_macroName = &l_currentUnitFileName.
173  ,i_macroLocation = &l_currentUnitLocation.
174  ,i_mCoverageName = 000.tcg
175  ,i_mCoverageLocation = &g_log
176  ,o_outputFile = tcg_%SCAN(&l_currentUnitFileName.,1,.).html
177  ,o_outputPath = &g_target/rep
178  ,o_resVarName = l_tcg_res
179  );
180  %END;
181  %END; /*%ELSE %DO;*/
182  /*store coverage percentage for report generation*/
183  PROC SQL NOPRINT;
184  UPDATE &d_rep1
185  SET tcg_pct=&l_tcg_res.
186  WHERE upcase(cas_pgm) EQ "%upcase(&l_currentUnit.)";
187  QUIT;
188  %end; /*do i = 1 to &l_listCount*/
189 
190 %END;
191 
192 DATA _null_;
193  SET &d_rep1 END=eof;
194  BY cas_auton pgm_id scn_id;
195 
196  FILE "&o_html";
197 
198  IF _n_=1 THEN DO;
199  %_sasunit_reportPageTopHTML(
200  i_title = %str(&g_nls_reportAuton_001 | &g_project - SASUnit &g_nls_reportAuton_002)
201  ,i_current = 4
202  )
203  END;
204 
205  LENGTH hlp1 hlp2 hlp3 hlpp $256;
206  RETAIN hlp3;
207 
208  IF first.cas_auton THEN DO;
209  IF _n_>1 THEN DO;
210  PUT '<hr size="1">';
211  END;
212  IF cas_auton NE . THEN hlp3 = 'auton' !! put (cas_auton, z3.);
213  ELSE hlp3 = 'auton';
214  PUT '<table id="' hlp3 +(-1) '"><tr>';
215  PUT " <td>&g_nls_reportAuton_003</td>";
216  IF cas_auton>=0 THEN DO;
217  ARRAY sa(0:9) tsu_sasautos tsu_sasautos1-tsu_sasautos9;
218  hlp1 = sa(cas_auton);
219  IF cas_auton=0 THEN hlp2 = symget('g_sasautos');
220  ELSE hlp2 = symget ('g_sasautos' !! compress(put(cas_auton,8.)));
221  PUT ' <td><a class="lightlink" title="' "&g_nls_reportAuton_004 " '&#x0D;' hlp2 +(-1) '" href="file://' hlp2 +(-1) '">' hlp1 +(-1) '</a></td>';
222  END;
223  ELSE DO;
224  PUT " <td>&g_nls_reportAuton_015</td>";
225  END;
226  PUT '</tr></table>';
227 
228  PUT '<table>';
229  PUT '<tr>';
230  PUT ' <td class="tabheader">' "&g_nls_reportAuton_005" '</td>';
231  PUT ' <td class="tabheader">' "&g_nls_reportAuton_006" '</td>';
232  PUT ' <td class="tabheader">' "&g_nls_reportAuton_007" '</td>';
233  PUT ' <td class="tabheader">' "&g_nls_reportAuton_014" '</td>';
234  %IF &g_testcoverage. EQ 1 %THEN %DO;
235  PUT ' <td class="tabheader">' "&g_nls_reportAuton_016" ' [%]' '</td>';
236  %END;
237  PUT ' <td class="tabheader">' "&g_nls_reportAuton_008" '</td>';
238  PUT '</tr>';
239  END;
240 
241  IF first.scn_id THEN DO;
242  PUT '<tr>';
243  END;
244 
245  IF first.pgm_id THEN DO;
246  IF cas_auton = . THEN DO;
247  hlp2 = resolve ('%_sasunit_abspath(&g_root,' !! trim(cas_pgm) !! ')');
248  END;
249  ELSE DO;
250  IF cas_auton = 0 THEN hlp1 = '&g_sasautos';
251  ELSE hlp1 = '&g_sasautos' !! compress (put (cas_auton,8.));
252  hlp2 = resolve ('%_sasunit_abspath(' !! trim(hlp1) !! ',' !! trim(cas_pgm) !! ')');
253  END;
254  PUT ' <td id="' hlp3 +(-1) '_' pgm_id z3. '" rowspan="' scn_count +(-1) '" class="datacolumn"><a class="lightlink" title="' "&g_nls_reportAuton_009 " '&#x0D;' hlp2 +(-1) '" href="' hlp2 +(-1) '">' cas_pgm +(-1) '</a></td>';
255  END;
256 
257  IF first.scn_id THEN DO;
258  PUT ' <td class="datacolumn"><a class="lightlink" title="' "&g_nls_reportAuton_010 " scn_id z3. '" href="cas_overview.html#scn' scn_id z3. '">' scn_id z3. '</a></td>';
259  hlp1 = left (put (scn_cas, 8.));
260  PUT ' <td class="datacolumn">' hlp1 +(-1) '</td>';
261  hlp1 = left (put (sum (res0, res1, res2), 8.));
262  PUT ' <td class="datacolumn">' hlp1 +(-1) '</td>';
263  %IF &g_testcoverage. EQ 1 %THEN %DO;
264  if compress(cas_pgm) ne '' then do;
265  if index(cas_pgm,'/') GT 0 then do;
266  hlpp = 'tcg_'||compress(trim(left(scan(substr(cas_pgm, findw(cas_pgm, scan(cas_pgm, countw(cas_pgm,'/'),'/'))),1,.) !! ".html")));
267  end;
268  else do;
269  hlpp = 'tcg_'||compress(trim(left(scan(cas_pgm,1,.) !! ".html")));
270  end;
271  end;
272  if tcg_pct eq . then do;
273  PUT ' <td class="datacolumn">&nbsp;</td>';
274  end;
275  else do;
276  PUT ' <td class="datacolumn"><a class="lightlink" title="' "&g_nls_reportAuton_017. " cas_pgm +(-1) '" href="' hlpp '">' tcg_pct +(-1) '</a></td>';
277  end;
278  %END;
279  PUT ' <td class="iconcolumn"><img src=' @;
280  IF res1>0 THEN PUT '"error.png" alt="' "&g_nls_reportAuton_011" '"' @;
281  ELSE IF res2>0 THEN PUT '"manual.png" alt="' "&g_nls_reportAuton_012" '"' @;
282  ELSE IF res0>0 THEN PUT '"ok.png" alt="OK"' @;
283  ELSE PUT '"?????" alt="' "&g_nls_reportAuton_013" '"' @;
284  PUT '></img></td>';
285  PUT '</tr>';
286  END;
287 
288  IF last.cas_auton THEN DO;
289  PUT '</table>';
290  END;
291 
292  IF eof THEN DO;
293  %_sasunit_reportFooterHTML()
294  END;
295 
296 RUN;
297 
298 PROC DATASETS NOWARN NOLIST LIB=work;
299  DELETE %scan(&d_rep1,2,.) %scan(&d_rep2,2,.);
300 QUIT;
301 
302 %MEND _sasunit_reportAutonHTML;