SASUnit Examples  Version 1.5.0
assertlog.sas
Go to the documentation of this file.
1 
28 %MACRO assertLog (i_errors = 0
29  ,i_warnings = 0
30  ,i_desc = Scan log for errors
31  );
32 
33  /*-- verify correct sequence of calls-----------------------------------------*/
34  %GLOBAL g_inTestcase;
35  %IF &g_inTestcase EQ 1 %THEN %DO;
36  %endTestcall;
37  %END;
38  %ELSE %IF &g_inTestcase NE 2 %THEN %DO;
39  %PUT &g_error.(SASUNIT): assert must be called after initTestcase;
40  %RETURN;
41  %END;
42 
43  %LOCAL l_casid l_error_count l_warning_count l_result l_errMsg;
44  %LET l_errMsg=;
45 
46  PROC SQL NOPRINT;
47  /* determine number of the current test case */
48  SELECT max(cas_id) INTO :l_casid FROM target.cas WHERE cas_scnid = &g_scnid;
49  QUIT;
50 
51  %IF &l_casid = . OR &l_casid = %THEN %DO;
52  %PUT &g_error.(SASUNIT): assert must not be called before initTestcase;
53  %RETURN;
54  %END;
55 
56  /* Scan Log */
57  %_checklog (
58  i_logfile = &g_log/%sysfunc(putn(&g_scnid,z3.))_%sysfunc(putn(&l_casid,z3.)).log
59  ,i_error = &g_error
60  ,i_warning = &g_warning
61  ,r_errors = l_error_count
62  ,r_warnings= l_warning_count
63  )
64 
65  %LET l_result = %eval ((
66  &l_error_count NE &i_errors
67  OR &l_warning_count NE &i_warnings
68  )*2);
69 
70  %IF (&l_result. EQ 2) %THEN %DO;
71  %LET l_errmsg=%bquote(expected &i_errors. error(s) and &i_warnings. warning(s), but actually there are &l_error_count. error(s) and &l_warning_count warning(s));
72  %END;
73 
74  %_asserts(i_type = assertLog
75  ,i_expected = %str(&i_errors#&i_warnings)
76  ,i_actual = %str(&l_error_count#&l_warning_count)
77  ,i_desc = &i_desc
78  ,i_result = &l_result
79  ,i_errMsg = &l_errMsg
80  )
81 
82 %MEND assertLog;