SASUnit Examples  Version 1.5.0
assertreport.sas
Go to the documentation of this file.
1 
33 %MACRO assertReport (i_expected =
34  ,i_actual =
35  ,i_desc = Compare documents
36  ,i_manual = 1
37  );
38 
39  /*-- verify correct sequence of calls-----------------------------------------*/
40  %GLOBAL g_inTestcase;
41  %IF &g_inTestcase EQ 1 %THEN %DO;
42  %endTestcall;
43  %END;
44  %ELSE %IF &g_inTestcase NE 2 %THEN %DO;
45  %PUT &g_error.(SASUNIT): assert must be called after initTestcase;
46  %RETURN;
47  %END;
48 
49  %LOCAL l_expected l_exp_ext l_rep_ext l_result l_casid l_tstid l_path l_errmsg;
50 
51  %*** check parameters ***;
52  %LET l_rep_ext = %_getExtension(&i_actual);
53 
54  %IF ("&i_actual." EQ "") %THEN %DO;
55  %LET l_errmsg = parameter i_actual is missing!;
56  %LET l_result=2;
57  %GOTO Update;
58  %END;
59 
60  %IF not (%sysfunc (fileexist(&i_actual.))) %THEN %DO;
61  %LET l_errmsg = File i_actual (&i_actual.) does not exist!;
62  %LET l_result=2;
63  %GOTO Update;
64  %END;
65 
66  %IF ("&i_expected." EQ "") %THEN %DO;
67  %LET l_errmsg = parameter i_expected is missing!;
68  %END;
69  %ELSE %DO;
70  %LET l_expected = %_abspath(&g_refdata,&i_expected);
71  %IF (%sysfunc (fileexist(&l_expected.))) %THEN %DO;
72  %LET l_exp_ext = %_getExtension(&l_expected);
73  %END;
74  %END;
75 
76  /*-- check for existence and check change date -------------------------------*/
77  %LET l_result=2;
78  %LET l_errmsg=Report was not created anew!;
79  %local d_dir;
80  %_tempFileName(d_dir)
81  %_dir(i_path=&i_actual, o_out=&d_dir)
82  data _null_;
83  set &d_dir nobs=nobs;
84  if nobs ne 1 then stop;
85  if changed < dhms (today(), hour (input ("&systime",time5.)), minute (input ("&systime",time5.)), 0) then do;
86  stop;
87  end;
88  call symput ('l_result', '1');
89  stop;
90  run;
91  proc sql;
92  drop table &d_dir;
93  quit;
94 
95  %IF NOT &i_manual AND &l_result=1 %THEN %LET l_result=0;
96 
97  /*-- get current ids for test case and test --------- ------------------------*/
98  %_getScenarioTestId (i_scnid=&g_scnid, r_casid=l_casid, r_tstid=l_tstid);
99 
100  %*** create subfolder ***;
101  %_createTestSubfolder (i_assertType =assertreport
102  ,i_scnid =&g_scnid.
103  ,i_casid =&l_casid.
104  ,i_tstid =&l_tstid.
105  ,r_path =l_path
106  );
107 
108  /* copy actual report if it exists */
109  %IF &l_rep_ext. NE %THEN %DO;
110  %_copyFile(&i_actual, &l_path./_man_act&l_rep_ext);
111  %END;
112 
113  /* copy expected report if it exists */
114  %IF &l_exp_ext. NE %THEN %DO;
115  %_copyFile(&l_expected, &l_path./_man_exp&l_exp_ext);
116  %END;
117 
118 %Update:
119  %_asserts(i_type = assertReport
120  ,i_expected = &l_exp_ext.
121  ,i_actual = &l_rep_ext.
122  ,i_desc = &i_desc.
123  ,i_result = &l_result.
124  ,r_casid = l_casid
125  ,r_tstid = l_tstid
126  ,i_errmsg = &l_errmsg.
127  )
128 
129 %MEND assertReport;