Loading...
Searching...
No Matches
mpe_makesampledata.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mpe_makesampledata macro
4
5 <h4> SAS Macros </h4>
6 @li mf_mkdir.sas
7 @li mp_assert.sas
8 @li mpe_makesampledata.sas
9
10 @author 4GL Apps Ltd
11 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
12 and may not be re-distributed or re-sold without the express permission of
13 4GL Apps Ltd.
14
15 @sasjslint {"maxLineLength": 80}
16
17**/
18
19%let dc_sample_root=%sysfunc(pathname(work))/mpe_makesampledata_test;
20%mf_mkdir(&dc_sample_root)
21libname dcsample "&dc_sample_root";
22
23/* A control library holding only the table mpe_makesampledata appends to.
24
25 The structure comes from the real control table rather than a column list
26 written here: the macro appends through `if 0 then set &lib..mpe_tables`, so
27 its append dataset carries the base's shape, and any column this fixture
28 lacks - notes, or pre_edit_hook on the hooked demo row - becomes a new
29 variable on the append side and PROC APPEND refuses the lot. A hand-written
30 list is a second definition of that table, waiting to drift; `stop` keeps the
31 copy empty. */
32data dcsample.mpe_tables;
33 set &dc_libref..mpe_tables;
34 stop;
35run;
36
37/**
38 * Test 1 - the option is off unless it is asked for: iftrue defaults to N, so
39 * a call that omits the argument builds nothing. This is what makes the flag
40 * safe to add to a deployment that knows nothing about it.
41 */
42%mpe_makesampledata(lib=dcsample,path=%str(&dc_sample_root))
43%let dc_sample_dir=&dc_sample_root/dcdemo;
44%let dc_exists=0;
45data _null_;
46 if fileexist("&dc_sample_dir") then call symputx('dc_exists',1);
47run;
48%mp_assert(
49 iftrue=("&dc_exists"="0"),
50 desc=The library is not created when the flag is off,
51 outds=work.test_results
52)
53
54/**
55 * Test 1b - N is the same as not asking, so a caller can pass the request's
56 * flag straight through without converting it
57 */
58%mpe_makesampledata(lib=dcsample,path=%str(&dc_sample_root),iftrue=N)
59%let dc_exists=0;
60data _null_;
61 if fileexist("&dc_sample_dir") then call symputx('dc_exists',1);
62run;
63%mp_assert(
64 iftrue=("&dc_exists"="0"),
65 desc=An N builds nothing,
66 outds=work.test_results
67)
68
69/**
70 * Test 2 - asking for it creates the library and the generated tables
71 */
72%mpe_makesampledata(lib=dcsample,path=%str(&dc_sample_root),iftrue=Y)
73%let dc_exists=0;
74data _null_;
75 if fileexist("&dc_sample_dir") then call symputx('dc_exists',1);
76run;
77%mp_assert(
78 iftrue=("&dc_exists"="1"),
79 desc=The library is created when the flag is on,
80 outds=work.test_results
81)
82
83libname dcdemo2 "&dc_sample_dir";
84%let dc_students=0;
85%let dc_vehicles=0;
86%let dc_formats=0;
87proc sql noprint;
88 select count(*) into :dc_students from dcdemo2.students;
89 select count(*) into :dc_vehicles from dcdemo2.vehicles;
90 select count(*) into :dc_formats from dcdemo2.formats;
91quit;
92%mp_assert(
93 iftrue=(&dc_students=20),
94 desc=The student table holds twenty rows,
95 outds=work.test_results
96)
97%mp_assert(
98 iftrue=(&dc_vehicles=30),
99 desc=The vehicle table holds thirty rows,
100 outds=work.test_results
101)
102%mp_assert(
103 iftrue=(&dc_formats=1),
104 desc=The format checks table holds one row,
105 outds=work.test_results
106)
107
108/**
109 * Test 3 - and the rows are the ones the rule documents, which is what the
110 * mock transcribes. A change to either side has to be made on the other.
111 */
112%let dc_ok=0;
113data _null_;
114 set dcdemo2.students(where=(id=2));
115 if name='student 02' and sex='F' and age=14 and height=52 and weight=82
116 then call symputx('dc_ok',1);
117run;
118%mp_assert(
119 iftrue=(&dc_ok=1),
120 desc=The generated student row is the documented one,
121 outds=work.test_results
122)
123
124%let dc_ok=0;
125data _null_;
126 set dcdemo2.vehicles(where=(id=5));
127 if make='Toyota' and model='Model 05' and type='SUV'
128 and origin='Asia' and drivetrain='Front' and msrp=23750
129 then call symputx('dc_ok',1);
130run;
131%mp_assert(
132 iftrue=(&dc_ok=1),
133 desc=The generated vehicle row is the documented one,
134 outds=work.test_results
135)
136
137%let dc_ok=0;
138data _null_;
139 set dcdemo2.formats;
140 /* 01JAN2026 and 01JAN2026:13:45:00 as SAS values */
141 if pk=1 and e8601da=24107 and dtm=2082894300
142 then call symputx('dc_ok',1);
143run;
144%mp_assert(
145 iftrue=(&dc_ok=1),
146 desc=The format checks row carries the documented dates,
147 outds=work.test_results
148)
149
150/**
151 * Test 4 - the tables are registered in MPE_TABLES, or DC cannot browse them
152 */
153%let dc_regs=0;
154%let dc_bad=0;
155proc sql noprint;
156 /* the fixture copied structure and no rows, so every registration here came
157 from the macro: counting them all is what fails when the macro grows a table
158 the count was not updated for, and when one is dropped */
159 select count(*) into :dc_regs
160 from dcsample.mpe_tables
161 where libref='DC_DEMO';
162 select count(*) into :dc_bad
163 from dcsample.mpe_tables
164 where libref='DC_DEMO'
165 and (buskey is missing or strip(buskey)='');
166quit;
167%mp_assert(
168 iftrue=(&dc_regs=12),
169 desc=Every demo table is registered,
170 outds=work.test_results
171)
172%mp_assert(
173 iftrue=(&dc_bad=0),
174 desc=Each registration carries its business key,
175 outds=work.test_results
176)
177
178/**
179 * Test 5 - a caller with no control library is told, not left with a half
180 * built library: the macro does what it can and reports through syscc
181 */
182%let dc_cc=0;
183%mpe_makesampledata(lib=,path=%str(&dc_sample_root))
184%let dc_cc=&syscc;
185%mp_assert(
186 iftrue=(&dc_cc=0),
187 desc=A missing control library is skipped rather than failing the deploy,
188 outds=work.test_results
189)
190
191libname dcdemo2 clear;
192libname dcsample clear;