SASUnit Examples  Version 1.5.0
assertlibrary.sas
Go to the documentation of this file.
1 
42 %MACRO assertLibrary (i_actual = _NONE_
43  ,i_expected = _NONE_
44  ,i_desc = Compare libraries
45  ,i_libraryCheck = STRICT
46  ,i_compareCheck = STRICT
47  ,i_fuzz = _NONE_
48  ,i_id = _NONE_
49  ,i_ExcludeList = _NONE_
50  );
51 
52  /*-- verify correct sequence of calls-----------------------------------------*/
53  %GLOBAL g_inTestcase;
54  %IF &g_inTestcase EQ 1 %THEN %DO;
55  %endTestcall;
56  %END;
57  %ELSE %IF &g_inTestcase NE 2 %THEN %DO;
58  %PUT &g_error.(SASUNIT): assert must be called after initTestcase;
59  %RETURN;
60  %END;
61 
62  %LOCAL l_casid l_tstid ;
63  %_getScenarioTestId (i_scnid=&g_scnid, r_casid=l_casid, r_tstid=l_tstid);
64 
65  %local l_actual_ok l_expected_ok l_result l_path_actual l_path_expected _sysinfo l_col_names l_id_col l_counter l_id l_rc l_errMsg;
66  %let l_errMsg=;
67 
68  %*************************************************************;
69  %*** Check preconditions ***;
70  %*************************************************************;
71 
72  %*** check for valid actual libref ***;
73  %let l_actual_ok=%sysfunc (libref (&i_actual.));
74  %if (&l_actual_ok. > 0) %then %do;
75  %let l_rc=2;
76  %let l_errMsg=Libref i_actual (&i_actual.) is invalid!;
77  %goto Update;
78  %end;
79 
80  %*** check for valid expected libref ***;
81  %let l_expected_ok=%sysfunc (libref (&i_expected.));
82  %if (&l_expected_ok. > 0) %then %do;
83  %let l_rc=2;
84  %let l_errMsg=Libref i_expected (&i_expected.) is invalid!;
85  %goto Update;
86  %end;
87 
88  %*** check for equal librefs ***;
89  %if (&i_actual. = &i_expected.) %then %do;
90  %let l_rc=2;
91  %let l_errMsg=Librefs are identical!;
92  %goto Update;
93  %end;
94 
95  %*** check for identical paths ***;
96  %let l_path_actual = %sysfunc (pathname (&i_actual.));
97  %let l_path_expected = %sysfunc (pathname (&i_expected.));
98  %if ("&l_path_actual." = "&l_path_expected.") %then %do;
99  %let l_rc=2;
100  %let l_errMsg=Paths of librefs are identical!;
101  %goto Update;
102  %end;
103 
104  %*** Check valid values for i_LibraryCheck ***;
105  %let i_LibraryCheck = %upcase (%trim(&i_LibraryCheck.));
106  %if (&i_LibraryCheck. ne STRICT AND &i_LibraryCheck. ne MORETABLES) %then %do;
107  %let l_rc=2;
108  %let l_errMsg=Value of i_LibraryCheck (%trim(&i_LibraryCheck.)) is invalid!;
109  %goto Update;
110  %end;
111 
112  %*** Check valid values for i_CompareCheck ***;
113  %let i_CompareCheck = %upcase (%trim(&i_CompareCheck.));
114  %if (&i_CompareCheck. ne STRICT AND &i_CompareCheck. ne MORECOLUMNS
115  AND &i_CompareCheck. ne MOREOBS AND &i_CompareCheck. ne MORECOLSNOBS) %then %do;
116  %let l_rc=2;
117  %let l_errMsg=Value of i_CompareCheck (%trim(&i_CompareCheck.)) is invalid!;
118  %goto Update;
119  %end;
120 
121  %let i_ExcludeList = %upcase (%trim(&i_ExcludeList.));
122  %let l_errMsg=Differences between datasets in the libraries! Please check SASUnit documentation for details.;
123 
124  %*************************************************************;
125  %*** start tests ***;
126  %*************************************************************;
127  %_assertLibrary (i_actual =&i_actual.
128  ,i_expected =&i_expected.
129  ,i_ExcludeList =&i_Excludelist.
130  ,i_CompareCheck=&i_CompareCheck.
131  ,i_LibraryCheck=&i_LibraryCheck.
132  ,i_id =&i_id.
133  ,i_fuzz =&i_fuzz.
134  ,o_result =l_rc
135  );
136 
137 %Update:;
138  *** update result in test database ***;
139  %_asserts(i_type = assertLibrary
140  ,i_expected = &i_expected.
141  ,i_actual = &i_actual.
142  ,i_desc = &i_desc.
143  ,i_result = &l_rc.
144  ,i_errMsg = &l_errMsg.
145  )
146 %MEND;