Loading...
Searching...
No Matches
mpe_assert_abort.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing the mpe_assert_abort macro
4
5 @details The macro decides PASS/FAIL from the child's status row - STATE says
6 whether the child was canceled, ERRMSG holds the reason - so the cases can be
7 built as datasets instead of services: an abort with the expected message, an
8 abort with a different one, a completed call, a status dataset that does not
9 exist, a message past the old 256 character width, quotes, backslashes, and
10 the log extract that mp_abort appends to the message.
11
12 Each case asserts on the PASS/FAIL the macro recorded, so a regression in the
13 comparison fails here rather than silently passing an abort assertion in a
14 service test.
15
16 <h4> SAS Macros </h4>
17 @li mp_assert.sas
18 @li mpe_assert_abort.sas
19
20 @author 4GL Apps Ltd
21 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
22 and may not be re-distributed or re-sold without the express permission of
23 4GL Apps Ltd.
24
25 @sasjslint {"maxLineLength": 83}
26
27**/
28
29/** a status row as %mpe_execute leaves it: the job state and the message */
30%macro mk_status(ds, state, msg);
31/* the values come from the symbol table rather than from quoted text: a
32 message holding double quotes would otherwise end the literal early */
33data &ds;
34 length state $20 uri $256 errmsg $32767 platform $10;
35 state=symget('state');
36 uri='';
37 errmsg=symget('msg');
38 platform='SASJS';
39run;
40%mend mk_status;
41
42/**
43 * Test 1 - an abort whose message matches is a PASS
44 */
45%mk_status(work.st1, canceled, Invalid libds)
46
47%mpe_assert_abort(
48 desc=an abort with the expected MSG,
49 outstatus=work.st1,
50 msg=Invalid libds,
51 outds=work.rc1
52)
53
54/**
55 * Test 2 - an abort for a different reason is a FAIL
56 */
57%mk_status(work.st2, canceled, Invalid libds)
58
59%mpe_assert_abort(
60 desc=an abort with a different MSG,
61 outstatus=work.st2,
62 msg=Invalid filter,
63 outds=work.rc2
64)
65
66/**
67 * Test 3 - a completed call is a FAIL
68 */
69%mk_status(work.st3, completed, )
70
71%mpe_assert_abort(
72 desc=a completed call,
73 outstatus=work.st3,
74 msg=0,
75 outds=work.rc3
76)
77
78/**
79 * Test 4 - a status dataset that does not exist fails the assertion, not the step
80 */
81%mpe_assert_abort(
82 desc=a status dataset that was never written,
83 outstatus=work.doesnotexist,
84 msg=0,
85 outds=work.rc4
86)
87
88/**
89 * Test 5 - a message longer than the old capture width is compared in full
90 *
91 * The status row carries the whole message, so a caller comparing a long one
92 * gets an answer rather than a silent 256 character cut.
93 */
94%let longmsg=;
95data work.st5;
96 length state $20 errmsg $32767;
97 state='canceled';
98 errmsg=repeat('a clause that runs on ',30);
99 call symputx('longmsg',errmsg,'l');
100run;
101
102%mpe_assert_abort(
103 desc=an abort with a message past the old capture width,
104 outstatus=work.st5,
105 msg=%superq(longmsg),
106 outds=work.rc5
107)
108
109/**
110 * Test 6 - quotes in the message survive
111 */
112%mk_status(work.st6, canceled, %str(alpha "quoted" beta))
113
114%mpe_assert_abort(
115 desc=a message holding double quotes,
116 outstatus=work.st6,
117 msg=%str(alpha "quoted" beta),
118 outds=work.rc6
119)
120
121/**
122 * Test 7 - the log extract mp_abort appends is not part of the message
123 */
124data work.st7;
125 length state $20 errmsg $32767;
126 state='canceled';
127 errmsg=cats('Invalid libds','0A0A'x,'Log Extract:','0A0A'x,'NOTE: a log line');
128run;
129
130%mpe_assert_abort(
131 desc=an abort with the appended log extract,
132 outstatus=work.st7,
133 msg=Invalid libds,
134 outds=work.rc7
135)
136
137/**
138 * Test 8 - a message that itself mentions the marker is not cut at it
139 *
140 * Only the two newlines before the marker identify the appended extract; a
141 * message that merely says "Log Extract:" keeps its text.
142 */
143data work.st8;
144 length state $20 errmsg $32767;
145 state='canceled';
146 errmsg='check the hook Log Extract: is mentioned here';
147run;
148
149%mpe_assert_abort(
150 desc=a message containing the extract marker,
151 outstatus=work.st8,
152 msg=%str(check the hook Log Extract: is mentioned here),
153 outds=work.rc8
154)
155
156/**
157 * Test 9 - a canceled call with no message fails a comparison it cannot support
158 *
159 * Core fills errmsg on both platforms now, so a blank one means the reason was
160 * never recorded - an expected message cannot be proved, and the assertion
161 * says so rather than passing on the state alone.
162 */
163%mk_status(work.st9, canceled, )
164
165%mpe_assert_abort(
166 desc=a canceled call whose status row carries no message,
167 outstatus=work.st9,
168 msg=Invalid libds,
169 outds=work.rc9
170)
171
172/**
173 * Test 10 - backslashes in the message compare as they were raised
174 */
175%mk_status(work.st10, canceled, %str(C:\temp\share))
176
177%mpe_assert_abort(
178 desc=a message holding backslashes,
179 outstatus=work.st10,
180 msg=%str(C:\temp\share),
181 outds=work.rc10
182)
183
184/**
185 * Test 11 - the doubled separator the escaping producer writes
186 *
187 * mp_abort doubles backslashes, so the appended extract arrives as a literal
188 * doubled pair rather than as characters.
189 */
190data work.st11;
191 length state $20 errmsg $32767;
192 state='canceled';
193 errmsg=cats('Invalid libds','\\n\\nLog Extract:\\n','NOTE: a log line');
194run;
195
196%mpe_assert_abort(
197 desc=an abort whose extract arrives doubled,
198 outstatus=work.st11,
199 msg=Invalid libds,
200 outds=work.rc11
201)
202
203/**
204 * Test 12 - the recorded results
205 */
206
207%macro getres(ds, var);
208data _null_;
209 set &ds;
210 call symputx("&var",test_result,'g');
211run;
212%mend getres;
213
214%getres(work.rc1, res_any)
215%getres(work.rc2, res_other)
216%getres(work.rc3, res_none)
217%getres(work.rc4, res_noref)
218%getres(work.rc5, res_long)
219%getres(work.rc6, res_quotes)
220%getres(work.rc7, res_logmark)
221%getres(work.rc8, res_marker)
222%getres(work.rc9, res_nomsg)
223%getres(work.rc10, res_bslash)
224%getres(work.rc11, res_doubled)
225
226%mp_assert(
227 iftrue=("&res_any"="PASS"),
228 desc=%str(Checking an abort with the expected MSG passes),
229 outds=work.test_results
230)
231
232%mp_assert(
233 iftrue=("&res_other"="FAIL"),
234 desc=%str(Checking an abort with a different MSG fails),
235 outds=work.test_results
236)
237
238%mp_assert(
239 iftrue=("&res_none"="FAIL"),
240 desc=%str(Checking a completed call fails),
241 outds=work.test_results
242)
243
244%mp_assert(
245 iftrue=("&res_noref"="FAIL"),
246 desc=%str(Checking a missing status dataset fails the assertion, not the step),
247 outds=work.test_results
248)
249
250%mp_assert(
251 iftrue=("&res_long"="PASS"),
252 desc=%str(Checking an abort message past the old capture width matches in full),
253 outds=work.test_results
254)
255
256%mp_assert(
257 iftrue=("&res_quotes"="PASS"),
258 desc=%str(Checking a message holding double quotes compares),
259 outds=work.test_results
260)
261
262%mp_assert(
263 iftrue=("&res_logmark"="PASS"),
264 desc=%str(Checking the appended log extract is stripped),
265 outds=work.test_results
266)
267
268%mp_assert(
269 iftrue=("&res_marker"="PASS"),
270 desc=%str(Checking a message containing the extract marker is not cut at it),
271 outds=work.test_results
272)
273
274%mp_assert(
275 iftrue=("&res_nomsg"="FAIL"),
276 desc=%str(Checking a canceled call with no message fails the comparison),
277 outds=work.test_results
278)
279
280%mp_assert(
281 iftrue=("&res_bslash"="PASS"),
282 desc=%str(Checking a message holding backslashes compares),
283 outds=work.test_results
284)
285
286%mp_assert(
287 iftrue=("&res_doubled"="PASS"),
288 desc=%str(Checking the doubled extract separator is stripped),
289 outds=work.test_results
290)