Loading...
Searching...
No Matches
mpe_assert_abort.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Asserts that a service returned a sasjsAbort object
4 @details Reads the child's status row and records a PASS when the child was
5 canceled, which is what happens when a service rejects its input and calls
6 mp_abort. When msg is supplied the ERRMSG value must match it, so the
7 assertion proves the service aborted for the expected reason rather than for
8 any reason at all.
9
10 The message comes from the status row rather than from the response text: core
11 publishes STATE and ERRMSG per call, ERRMSG holds the whole message including
12 quotes and anything longer than a single record, and reading it needs no
13 parsing of the response.
14
15 Two things are handled here rather than in core:
16
17 - mp_abort appends cats(msg,'\n\nLog Extract:\n',logmsg) to the message, so
18 the tail is cut at the two newlines that precede the marker. A message that
19 merely mentions "Log Extract:" is not preceded by them and survives.
20 - a platform that reports no job state at all (SAS 9 PROC STP) cannot show the
21 abort this way; the row reads 'unknown' and the assertion fails rather than
22 guessing.
23
24 Usage:
25
26 %mpe_execute(&_program,
27 inputfiles=&f1:sascontroltable,
28 outstatus=work.ab1,
29 failfast=0
30 )
31 %mpe_assert_abort(
32 desc=An invalid libds aborts the service,
33 outstatus=work.ab1,
34 msg=Invalid libds
35 )
36
37 @param [in] desc The description recorded in the test results
38 @param [in] outstatus The dataset given to %mpe_execute, holding STATE and
39 ERRMSG for the child call
40 @param [in] msg= (0) Expected ERRMSG value. 0 accepts any abort message.
41 @param [out] outds= (work.test_results) Results dataset
42
43 <h4> SAS Macros </h4>
44 @li mp_assert.sas
45
46 @sasjslint {"maxLineLength": 94}
47
48**/
49
50%macro mpe_assert_abort(desc, outstatus, msg=0, outds=work.test_results);
51%local ok seen abortseen;
52%let ok=0;
53%let seen=;
54%let abortseen=0;
55
56%if %sysfunc(exist(&outstatus)) ne 1 %then %do;
57 %put %str(WARN)ING: &sysmacroname: &outstatus does not exist - the child left no status row;
58%end;
59%else %do;
60 data _null_;
61 length got $32767;
62 set &outstatus;
63 if state='canceled' then call symputx('abortseen',1,'l');
64 got=errmsg;
65 /* mp_abort appends cats(msg,'\n\nLog Extract:\n',logmsg). Those newlines
66 reach here as characters, as an escaped pair, or as a doubled pair - which
67 one depends on the producer - so all three are tried */
68 cut=index(got,'0A0A'x||'Log Extract:');
69 if cut=0 then cut=index(got,'\n\nLog Extract:');
70 if cut=0 then cut=index(got,'\\n\\nLog Extract:');
71 if cut>1 then got=substr(got,1,cut-1);
72 call symputx('seen',got,'l');
73 run;
74%end;
75
76%if &abortseen=1 %then %do;
77 %if "%superq(msg)"="0" %then %let ok=1;
78 %else %if "%superq(seen)"="%superq(msg)" %then %let ok=1;
79%end;
80%if "%superq(seen)" ne "" %then %put NOTE: &sysmacroname: sasjsAbort MSG=&seen;
81
82%mp_assert(
83 iftrue=(&ok=1),
84 desc=&desc,
85 outds=&outds
86)
87%mend mpe_assert_abort;