SASUnit Examples  Version 1.5.0
_reportdetailhtml.sas
Go to the documentation of this file.
1 
25 %MACRO _reportDetailHTML (i_repdata =
26  ,i_scnid =
27  ,i_casid =
28  ,o_html = 0
29  ,o_path =
30  ,o_file =
31  );
32 
33  %LOCAL
34  l_nls_reportdetail_errors
35  _numCases
36  _numAsserts
37  l_NumAssert
38  l_NumTests
39  l_TestAssert
40  l_cTestAssert
41  l_Tests
42  l_c_casid
43  i_cas
44  l_casid
45  l_casids
46  ;
47  %LET l_nls_reportdetail_errors = %STR(error(s));
48 
49  proc sql noprint;
50  select count (distinct tst_type) into :_numAsserts from &i_repdata. where scn_id = &i_scnid AND tst_type ne '^_'; * AND cas_id = &i_casid;
51  select count (distinct cas_id) into :_numCases from &i_repdata. where scn_id = &i_scnid AND tst_type ne '^_'; * AND cas_id = &i_casid;
52  quit;
53 
54  %if (&_numAsserts. > 0) %then %do;
55  %do l_NumAssert=1 %to &_numAsserts.;
56  %local assertType&l_NumAssert.
57  ;
58  %end;
59 
60  proc sql noprint;
61  select distinct tst_type into :assertType1-:assertType%cmpres(&_numAsserts.) from &i_repdata. where scn_id = &i_scnid AND tst_type ne '^_'; * AND cas_id = &i_casid;
62  quit;
63 
64  DATA work._test_report;
65  SET &i_repdata. END=eof;
66  WHERE scn_id = &i_scnid;
67 
68  LENGTH
69  scn_abs_path cas_abs_path $256
70  hlp hlp2 $200
71  errcountmsg $50
72  LinkTitle1
73  LinkTitle2
74  LinkTitle3
75  href
76  href_act
77  href_exp
78  href_rep
79  LinkColumn1
80  LinkColumn2
81  LinkColumn3 $200
82  idColumn $80
83  scnDescriptionColumn casDescriptionColumn descriptionColumn $1000
84  scnProgramColumn casProgramColumn $1000
85  scnLast_runColumn casLast_runColumn $1000
86  scnDurationColumn $1000
87  assertTypeColumn $200
88  expectedColumn $1000
89  actualColumn $1000
90  resultColumn $1000;
91  ;
92  label
93  scnDescriptionColumn="&g_nls_reportDetail_029."
94  scnProgramColumn ="&g_nls_reportDetail_030."
95  scnLast_runColumn ="&g_nls_reportDetail_031."
96  scnDurationColumn ="&g_nls_reportDetail_032."
97  casDescriptionColumn="&g_nls_reportDetail_034."
98  casProgramColumn ="&g_nls_reportDetail_035."
99  casLast_runColumn ="&g_nls_reportDetail_031."
100  idColumn ="&g_nls_reportDetail_009."
101  assertTypeColumn ="&g_nls_reportDetail_010."
102  descriptionColumn ="&g_nls_reportDetail_011."
103  expectedColumn ="&g_nls_reportDetail_012."
104  actualColumn ="&g_nls_reportDetail_013."
105  resultColumn ="&g_nls_reportDetail_014."
106  ;
107 
108  *** initalizing variables that MAY be used in a specific assert ***;
109  if (_N_=1) then do;
110  hlp="";
111  hlp2="";
112  errcountmsg="";
113  href="";
114  href_act="";
115  href_exp="";
116  href_rep="";
117  end;
118 
119  if tst_act="" then tst_act='^_';
120  if tst_exp="" then tst_exp='^_';
121 
122  *** Columns for scenario overview ***;
123  scn_abs_path = resolve ('%_abspath(&g_root,' !! trim(scn_path) !! ')');
124  scn_pgm = resolve ('%_stdpath(&g_root./saspgm/test,' !! trim(scn_abs_path) !! ')');
125  scn_duration = put (scn_end - scn_start, ??&g_nls_reportScn_013.) !! " s";
126  c_scnid = put (scn_id, z3.);
127  c_casid = put (cas_id, z3.);
128  if (cas_auton = 0) then do;
129  cas_abs_path = resolve ('%_abspath(&g_sasunit,' !! trim(cas_pgm) !! ')');
130  end;
131  else if (cas_auton = 1) then do;
132  cas_abs_path = resolve ('%_abspath(&g_sasunit_os,' !! trim(cas_pgm) !! ')');
133  end;
134  else do;
135  cas_abs_path = resolve ('%_abspath(&g_sasautos' !! put (cas_auton-2,1.) !! ',' !! trim(cas_pgm) !! ')');
136  end;
137  cas_pgm = resolve ('%_stdpath(&g_root./saspgm/,' !! trim(cas_abs_path) !! ')');
138 
139  %_render_DataColumn (i_sourceColumn=scn_duration
140  ,o_targetColumn=scnDurationColumn
141  );
142  %_render_DataColumn (i_sourceColumn=cas_desc
143  ,o_targetColumn=casDescriptionColumn
144  );
145  %_render_DataColumn (i_sourceColumn=tst_desc
146  ,o_targetColumn=descriptionColumn
147  );
148  %_render_DataColumn (i_sourceColumn=tst_type
149  ,o_targetColumn=assertTypeColumn
150  );
151  %_render_IconColumn (i_sourceColumn=tst_res
152  ,o_html=&o_html.
153  ,o_targetColumn=resultColumn
154  );
155 
156  *** Any destination that renders links shares this if ***;
157  %if (&o_html.) %then %do;
158  LinkTitle1 = trim ("&g_nls_reportDetail_003") !!" " !! c_scnid;
159  LinkTitle2 = "&g_nls_reportDetail_004" !! byte(13) !! scn_abs_path;
160  LinkTitle3 = "&g_nls_reportDetail_005";
161  LinkTitle4 = "&g_nls_reportDetail_006" !! byte(13) !! cas_abs_path;
162  LinkTitle5 = "&g_nls_reportDetail_007";
163  *** HTML-links are destinations specific ***;
164  %if (&o_html.) %then %do;
165  LinkColumn1 = catt("cas_overview.html#SCN", c_scnid, "_");
166  LinkColumn2 = "pgm_" !! tranwrd (scn_pgm, ".sas", ".html");
167  LinkColumn3 = c_scnid !! "_log.html";
168  LinkColumn4 = "pgm_" !! tranwrd (cas_pgm, ".sas", ".html");
169  LinkColumn5 = c_scnid !! "_" !! c_casid !! "_log.html";
170  %end;
171  %_render_DataColumn (i_sourceColumn=scn_desc
172  ,o_targetColumn=scnDescriptionColumn
173  ,i_linkColumn=LinkColumn1
174  ,i_linkTitle=LinkTitle1
175  );
176  %_render_DataColumn (i_sourceColumn=scn_path
177  ,i_linkColumn=scn_abs_path
178  ,i_linkTitle=LinkTitle2
179  ,o_targetColumn=scnProgramColumn
180  );
181  %_render_DataColumn (i_sourceColumn=scn_start
182  ,i_format=&g_nls_reportDetail_050.
183  ,i_linkColumn=LinkColumn3
184  ,i_linkTitle=LinkTitle3
185  ,o_targetColumn=scnLast_runColumn
186  );
187  %_render_DataColumn (i_sourceColumn=cas_pgm
188  ,i_linkColumn=cas_abs_path
189  ,i_linkTitle=LinkTitle4
190  ,o_targetColumn=casProgramColumn
191  );
192  %_render_DataColumn (i_sourceColumn=cas_start
193  ,i_format=&g_nls_reportDetail_050.
194  ,i_linkColumn=LinkColumn5
195  ,i_linkTitle=LinkTitle5
196  ,o_targetColumn=casLast_runColumn
197  );
198  idColumn ="^{style [PRETEXT=""<a name='TST" !! put (tst_id, z3.) !! "'></a>""]" !! put (tst_id, z3.) !! "}";
199  %end;
200 
201  %do l_NumAssert=1 %to &_numAsserts;
202  if (upcase(tst_type)="%upcase(&&asserttype&l_NumAssert.)") then do;
203  %let l_NumAssertSubstr = &&asserttype&l_NumAssert.;
204  %if (%length(&l_NumAssertSubstr.) > 21) %then %do;
205  %let l_NumAssertSubstr = %substr(&l_NumAssertSubstr.,1,21);
206  %end;
207  %_render_&l_NumAssertSubstr.Exp (i_sourceColumn=tst_exp
208  ,o_html=&o_html.
209  ,o_targetColumn=expectedColumn
210  );
211  %_render_&l_NumAssertSubstr.Act (i_sourceColumn=tst_act
212  ,o_html=&o_html.
213  ,o_targetColumn=actualColumn
214  );
215  end;
216  %end;
217  run;
218 
219  %*** Reset title and footnotes ***;
220  title;
221  footnote;
222 
223  %do i_cas=1 %to &_numCases.;
224  %let l_title=%str(&g_nls_reportCas_001. | &g_project - &g_nls_reportCas_002.);
225  title j=c "&l_title.";
226  %if (&o_html.) %then %do;
227  ods html4 file="&o_path./&o_file._%sysfunc (putn (&i_cas., z3.)).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 = 0
235  )
236  %end;
237  %LET l_c_scnid = %substr(00&i_cas.,%length(&i_cas));
238 
239  *** Reset title and footnotes for each Testcase ***;
240  *** First print should contain title but no footnotes ***;
241  footnote;
242  options nocenter;
243 
244  data work._test_overview;
245  set work._test_report (where=(tst_id=1 AND cas_id=&i_cas.));
246  length Name $20 Value $1000;
247  Name="&g_nls_reportDetail_028."; Value=c_scnid;output;
248  Name="&g_nls_reportDetail_029."; Value=scnDescriptionColumn;output;
249  Name="&g_nls_reportDetail_030."; Value=scnProgramColumn;output;
250  Name="&g_nls_reportDetail_031."; Value=scnLast_runColumn;output;
251  Name="&g_nls_reportDetail_032."; Value=scnDurationColumn;output;
252  Name="&g_nls_reportDetail_033."; Value=c_casid;output;
253  Name="&g_nls_reportDetail_034."; Value=casDescriptionColumn;output;
254  Name="&g_nls_reportDetail_035."; Value=casProgramColumn;output;
255  Name="&g_nls_reportDetail_031."; Value=casLast_runColumn;output;
256  keep Name Value;
257  run;
258 
259  proc print data=work._test_overview noobs label
260  style(report)=blindTable [borderwidth=0]
261  style(column)=blindData
262  style(header)=blindHeader;
263  run;
264 
265  *** Second print should contain no title but footnotes ***;
266  title;
267  %_reportFooter(o_html=&o_html.);
268 
269  proc report data=work._test_report (where=(cas_id=&i_cas.)) nowd missing
270  style(lines)=blindData
271  ;
272 
273  columns idColumn assertTypeColumn descriptionColumn expectedColumn actualColumn resultColumn;
274 
275  define idColumn / order style(Column)=rowheader;
276  define resultColumn / display style(Column)=[background=white];
277 
278  compute before _page_;
279  line @1 "&g_nls_reportDetail_008.";
280  endcomp;
281  run;
282  %end;
283 
284  %if (&o_html.) %then %do;
285  %_closeHtmlPage;
286  %end;
287 
288  %*** Reset title and footnotes ***;
289  title;
290  footnote;
291 
292  options center;
293 
294  %do l_NumAssert=1 %to &_numAsserts;
295  *** Call all associated submacros for rendering specific assert reports ***;
296  %let l_NumAssertSubstr = %lowcase(&&asserttype&l_NumAssert.);
297  %if (%length(&l_NumAssertSubstr.) > 21) %then %do;
298  %let l_NumAssertSubstr = %substr(&l_NumAssertSubstr.,1,21);
299  %end;
300  %if (%sysfunc (fileexist(&g_sasunit./_render_&l_NumAssertSubstr.rep.sas))) %then %do;
301  proc sql noprint;
302  select count(distinct cas_id) into :_numCases from work._test_report where tst_type = "&&asserttype&l_NumAssert.";
303  select distinct cas_id into :l_casids separated by "§" from work._test_report where tst_type = "&&asserttype&l_NumAssert.";
304  quit;
305  %do i_cas=1 %to &_numCases.;
306  %LET l_casid = %scan (&l_casids., &i_cas., §);
307  %LET l_c_casid = %substr(00&l_casid.,%length(&l_casid));
308  proc sql noprint;
309  select count(*) into :l_NumTests from work._test_report where tst_type = "&&asserttype&l_NumAssert." AND cas_id=&l_casid.;
310  select tst_id into :l_Tests separated by "§" from work._test_report where tst_type = "&&asserttype&l_NumAssert." AND cas_id=&l_casid.;
311  quit;
312  %do l_TestAssert=1 %to &l_NumTests.;
313  %LET l_cTestAssert = %scan(&l_Tests.,&l_TestAssert.,§);
314  %_render_&l_NumAssertSubstr.rep(i_assertype=&&asserttype&l_NumAssert.,i_repdata=&i_repdata.,i_scnid=&i_scnid.,i_casid=&l_c_casid.,i_tstid=&l_cTestAssert.,o_html=&o_html.,o_path=&o_path.);
315  %end;
316  %end;
317  %end;
318  %end;
319 
320  proc datasets lib=work nolist memtype=(view data);
321  delete _test_overview _test_report;
322  run;
323  %end;
324 %MEND _reportDetailHTML;