SASUnit Examples  Version 1.5.0
assertlogmsg.sas
Go to the documentation of this file.
1 
32 %MACRO assertLogMsg (i_logmsg =
33  ,i_desc = Scan for log messages
34  ,i_not = 0
35  );
36 
37  /*-- verify correct sequence of calls-----------------------------------------*/
38  %GLOBAL g_inTestcase;
39  %IF &g_inTestcase EQ 1 %THEN %DO;
40  %endTestcall;
41  %END;
42  %ELSE %IF &g_inTestcase NE 2 %THEN %DO;
43  %PUT &g_error.(SASUNIT): assert must be called after initTestcase;
44  %RETURN;
45  %END;
46 
47  %LOCAL l_casid l_msg_found l_actual l_expected l_assert_failed;
48  PROC SQL NOPRINT;
49  /* determine number of the current test case */
50  SELECT max(cas_id) INTO :l_casid FROM target.cas WHERE cas_scnid = &g_scnid;
51  QUIT;
52 
53  %IF &l_casid = . OR &l_casid = %THEN %DO;
54  %PUT &g_error.(SASUNIT): assert must not be called before initTestcase;
55  %RETURN;
56  %END;
57 
58  /* scanne den Log */
59  %LET l_msg_found=0;
60  DATA _null_;
61  RETAIN pattern_id;
62  IF _n_=1 THEN DO;
63  pattern_id = prxparse("/%upcase(&i_logmsg)/");
64  END;
65  INFILE "&g_log/%sysfunc(putn(&g_scnid,z3.))_%sysfunc(putn(&l_casid,z3.)).log" END=eof TRUNCOVER;
66  INPUT logrec $char256.;
67  logrec = upcase(logrec);
68  IF prxmatch (pattern_id, logrec) THEN DO;
69  call symput ('l_msg_found', '1');
70  END;
71  RUN;
72 
73  %IF &l_msg_found %THEN %DO;
74  %LET l_actual = 1; /* message found */
75  %END;
76  %ELSE %DO;
77  %LET l_actual = 2; /* message not found */
78  %END;
79 
80  %IF &i_not %THEN %DO;
81  %LET l_expected = 2&i_logmsg; /* message not present */
82  %LET l_assert_failed = %eval (&l_msg_found.*2);
83  %END;
84  %ELSE %DO;
85  %LET l_expected = 1&i_logmsg; /* message present */
86  %LET l_assert_failed = %eval((NOT &l_msg_found)*2);
87  %END;
88 
89  %_asserts(i_type = assertLogMsg
90  ,i_expected = %str(&l_expected)
91  ,i_actual = %str(&l_actual)
92  ,i_desc = &i_desc
93  ,i_result = &l_assert_failed
94  )
95 
96 %MEND assertLogMsg;