SASUnit Examples  Version 1.2
assertlogmsg.sas
Go to the documentation of this file.
1 
30 /* change log
31  29.01.2013 KL changed link from _sasunit_doc.sas to Sourceforge SASUnit User's Guide
32  26.09.2008 AM bug fixing NLS: standard description text
33  21.08.2008 AM moved language dependent text to reportDetailHTML
34  30.06.2008 AM kleine Dokumentationsänderung
35  07.02.2008 AM doppelte Hochkammata wieder entfernt, Quoting wird jetzt in
36  %_sasunit_asserts erledigt, Doku zu Sonderzeichen in Strings ergänzt
37  15.12.2007 AM doppelte Hochkommata in l_expected ergänzt.
38 */
39 
40 %MACRO assertLogMsg (
41  i_logmsg =
42  ,i_desc =
43  ,i_not = 0
44 );
45 
46 %GLOBAL g_inTestcase;
47 %IF &g_inTestcase EQ 1 %THEN %DO;
48  %endTestcall;
49 %END;
50 %ELSE %IF &g_inTestcase NE 2 %THEN %DO;
51  %PUT &g_error: assert must be called after initTestcase;
52  %RETURN;
53 %END;
54 
55 PROC SQL NOPRINT;
56 %LOCAL l_casid;
57 /* determine number of the current test case */
58  SELECT max(cas_id) INTO :l_casid FROM target.cas WHERE cas_scnid = &g_scnid;
59 QUIT;
60 
61 %IF &l_casid = . OR &l_casid = %THEN %DO;
62  %PUT &g_error: assert must not be called before initTestcase;
63  %RETURN;
64 %END;
65 
66 /* scanne den Log */
67 %LOCAL l_msg_found; %LET l_msg_found=0;
68 DATA _null_;
69  RETAIN pattern_id;
70  IF _n_=1 THEN DO;
71  pattern_id = prxparse("/%upcase(&i_logmsg)/");
72  END;
73  INFILE "&g_log/%sysfunc(putn(&g_scnid,z3.))_%sysfunc(putn(&l_casid,z3.)).log" END=eof TRUNCOVER;
74  INPUT logrec $char256.;
75  logrec = upcase(logrec);
76  IF prxmatch (pattern_id, logrec) THEN DO;
77  call symput ('l_msg_found', '1');
78  END;
79 RUN;
80 
81 %LOCAL l_actual;
82 %IF &l_msg_found %THEN %DO;
83  %LET l_actual = 1; /* message found */
84 %END;
85 %ELSE %DO;
86  %LET l_actual = 2; /* message not found */
87 %END;
88 
89 %LOCAL l_expected l_assert_failed;
90 %IF &i_not %THEN %DO;
91  %LET l_expected = 2&i_logmsg; /* message not present */
92  %LET l_assert_failed = &l_msg_found;
93 %END;
94 %ELSE %DO;
95  %LET l_expected = 1&i_logmsg; /* message present */
96  %LET l_assert_failed = %eval(NOT &l_msg_found);
97 %END;
98 
99 %_sasunit_asserts(
100  i_type = assertLogMsg
101  ,i_expected = %str(&l_expected)
102  ,i_actual = %str(&l_actual)
103  ,i_desc = &i_desc
104  ,i_result = &l_assert_failed
105 )
106 
107 %MEND assertLogMsg;