SASUnit Examples  Version 1.5.0
initsasunit.sas
Go to the documentation of this file.
1 
59 %MACRO initSASUnit(i_root =
60  ,io_target =
61  ,i_overwrite = 0
62  ,i_project =
63  ,i_sasunit =
64  ,i_sasautos =
65  ,i_sasautos1 =
66  ,i_sasautos2 =
67  ,i_sasautos3 =
68  ,i_sasautos4 =
69  ,i_sasautos5 =
70  ,i_sasautos6 =
71  ,i_sasautos7 =
72  ,i_sasautos8 =
73  ,i_sasautos9 =
74  ,i_autoexec =
75  ,i_sascfg =
76  ,i_sasuser =
77  ,i_testdata =
78  ,i_refdata =
79  ,i_doc =
80  ,i_testcoverage = 1
81  ,i_verbose = 0
82  ,i_crossref = 1
83  ,i_crossrefsasunit = 0
84  );
85 
86  %GLOBAL g_version g_revision g_verbose g_error g_warning g_note;
87 
88  %LET g_version = 1.5.0;
89  %LET g_revision = $Revision: 368 $;
90  %LET g_revision = %scan(&g_revision,2,%str( $:));
91 
92  /*-- check value of parameters i_verbose, i_crossref and i_crossrefsasunit, if one of them has a value other than 0,
93  they will be set to 1 in order to assure that values will only be 0 or 1 ------*/
94  %IF (&i_crossrefsasunit. NE 0) %THEN %DO;
95  %LET i_crossrefsasunit = 1;
96  %END;
97  %IF (&i_crossref. NE 0) %THEN %DO;
98  %LET i_crossref = 1;
99  %END;
100  %IF (&i_verbose. NE 0) %THEN %DO;
101  %LET i_verbose = 1;
102  %END;
103  %LET g_verbose = &i_verbose;
104 
105 
106  %LOCAL l_macname l_current_dbversion l_target_abs l_newdb l_rc l_project l_root l_sasunit l_abs l_autoexec l_autoexec_abs
107  l_sascfg l_sascfg_abs l_sasuser l_sasuser_abs l_testdata l_testdata_abs l_refdata l_refdata_abs l_doc l_doc_abs
108  l_sasautos l_sasautos_abs i l_work l_sysrc l_sasunit_os l_cmdfile l_abspath_sasautos l_abspath_sasunit_os l_sasunitroot
109  restore_sasautos
110  ;
111 
112  %LET l_current_dbversion=0;
113  %LET l_macname=&sysmacroname;
114 
115  /*-- Resolve relative root path like .../. to an absolute root path ----------*/
116  libname _tmp "&i_root.";
117  %let l_root=%sysfunc (pathname(_tmp));
118  libname _tmp clear;
119 
120  /*-- Get SASUnit root path from environement variable ----------*/
121  libname _tmp "%sysget(SASUNIT_ROOT)";
122  %let l_sasunitroot=%sysfunc (pathname(_tmp));
123  libname _tmp clear;
124 
125  /*-- Get SASUnit macro paths ----------*/
126  libname _tmp "&i_sasunit";
127  %let l_sasunit=%sysfunc (pathname(_tmp));
128  libname _tmp clear;
129 
130  /*-- initialize error --------------------------------------------------------*/
131  %_initErrorHandler;
132 
133  /*-- check for operation system ----------------------------------------------*/
134  %IF %_handleError(&l_macname.
135  ,WrongOS
136  ,(%upcase(&sysscp.) NE WIN) AND (%upcase(&sysscpl.) NE LINUX) AND (%upcase(&sysscpl.) NE AIX)
137  ,Invalid operating system - only WIN%str(,) LINUX AND AIX
138  ,i_verbose=&i_verbose.
139  )
140  %THEN %GOTO errexit;
141 
142  /*-- set macro symbols for os commands ---------------------------------------*/
143  %IF (&sysscp. = WIN) %THEN %DO;
144  %LET l_sasunit_os = &l_sasunit./windows;
145  %END;
146  %ELSE %IF (%upcase(&sysscpl.) = LINUX) %THEN %DO;
147  %LET l_sasunit_os = &l_sasunit./linux;
148  %END;
149  %ELSE %IF (%upcase(&sysscpl.) = AIX) %THEN %DO;
150  %LET l_sasunit_os = &l_sasunit./unix_aix;
151  %END;
152  %LET l_abspath_sasunit =%_abspath(&i_root.,&i_sasunit.);
153  %LET l_abspath_sasunit_os=%_abspath(&i_root.,&l_sasunit_os.);
154  OPTIONS SASAUTOS=(SASAUTOS "&l_abspath_sasunit." "&l_abspath_sasunit_os.");
155  OPTIONS NOQUOTELENMAX;
156 
157  %_oscmds;
158 
159  %_detectSymbols(r_error_symbol=g_error, r_warning_symbol=g_warning, r_note_symbol=g_note);
160 
161  /*-- check SAS version -------------------------------------------------------*/
162  %IF %_handleError(&l_macname.
163  ,WrongVer
164  ,(&sysver. NE 9.2) AND (&sysver. NE 9.3) AND (&sysver. NE 9.4)
165  ,Invalid SAS version - only SAS 9.2 to 9.4
166  ,i_verbose=&i_verbose.
167  )
168  %THEN %GOTO errexit;
169 
170  /*-- check value of parameter i_testcoverage, if it has an other value than 1,
171  set it to 0 in order to assure that it will have only value 0 or 1 ------*/
172  %IF &i_testcoverage. NE 1 %THEN %DO;
173  %LET i_testcoverage = 0;
174  %END;
175  %ELSE %DO;
176  /*-- if test coverage should be assessed: check SAS version --------------*/
177  %IF %_handleError(&l_macname.
178  ,ErrorTargetLib
179  ,%quote(&syslibrc) NE 0
180  ,Error in parameter io_target: target directory &l_target_abs. cannot be assigned as a SAS library
181  ,i_verbose=&i_verbose.
182  )
183  %THEN %GOTO errexit;
184  %END;
185 
186  /*-- check for target directory ----------------------------------------------*/
187  %LET l_target_abs=%_abspath(&i_root,&io_target);
188  %IF %_handleError(&l_macname.
189  ,InvalidTargetDir
190  ,"&l_target_abs" EQ "" OR NOT %_existDir(&l_target_abs)
191  ,Error in parameter io_target: target directory does not exist
192  ,i_verbose=&i_verbose.
193  )
194  %THEN %GOTO errexit;
195 
196  LIBNAME target "&l_target_abs";
197  %IF %_handleError(&l_macname
198  ,ErrorTargetLib
199  ,%quote(&syslibrc.) NE 0
200  ,Error in parameter io_target: target directory &l_target_abs. cannot be assigned as a SAS library
201  ,i_verbose=&i_verbose.
202  )
203  %THEN %GOTO errexit;
204  %IF %_handleError(&l_macname.
205  ,ErrorTargetLibNotWritable
206  ,%quote(&syserr.) NE 0
207  ,Error in parameter io_target: target directory not writeable
208  ,i_verbose=&i_verbose.
209  )
210  %THEN %GOTO errexit;
211 
212  /*-- does the test database exist already? -----------------------------------*/
213  %IF "&i_overwrite" NE "1" %then %LET i_overwrite=0;
214  %IF &i_overwrite %THEN %LET l_newdb=1;
215  %ELSE %LET l_newdb=%eval(NOT %sysfunc(exist(target.tsu)));
216 
217  *** Check tsu db version ***;
218  *** Is there a need to recreate the database? ***;
219  %IF &l_newdb. ne 1 %THEN %DO;
220  data _null_;
221  if (exist ("target.tsu")) then do;
222  did = open ("target.tsu");
223  if varnum (did, "tsu_dbVersion") then do;
224  rc = fetch (did);
225  tsu_dbVersion = getvarc (did, varnum (did, "tsu_dbVersion"));
226  call symput ("l_current_dbversion", trim(tsu_dbVersion));
227  end;
228  did = close(did);
229  end;
230  run;
231  %LET l_newdb=%eval ("&l_current_dbversion." NE "&g_version.");
232  %END;
233 
234  /*-- create test database if necessary ---------------------------------------*/
235  %IF &l_newdb %THEN %DO;
236  PROC SQL NOPRINT;
237  CREATE TABLE target.tsu(COMPRESS=CHAR)
238  ( /* test suite */
239  tsu_project CHAR(1000) /* see i_project */
240  ,tsu_root CHAR(1000) /* see i_root */
241  ,tsu_target CHAR(1000) /* see io_target */
242  ,tsu_sasunitroot CHAR(1000) /* root path to sasunit files */
243  ,tsu_sasunit CHAR(1000) /* see i_sasunit */
244  ,tsu_sasunit_os CHAR(1000) /* os-specific sasunit macros */
245  ,tsu_sasautos CHAR(1000) /* see i_sasautos */
246  %DO i=1 %TO 9;
247  ,tsu_sasautos&i CHAR(1000) /* see i_sasautos<n> */
248  %END;
249  ,tsu_autoexec CHAR(1000) /* see i_autoexec */
250  ,tsu_sascfg CHAR(1000) /* see i_sascfg */
251  ,tsu_sasuser CHAR(1000) /* see i_sasuser */
252  ,tsu_testdata CHAR(1000) /* see i_testdata */
253  ,tsu_refdata CHAR(1000) /* see i_refdata */
254  ,tsu_doc CHAR(1000) /* see i_doc */
255  ,tsu_lastinit INT FORMAT=datetime21.2 /* date and time of last initialization */
256  ,tsu_lastrep INT FORMAT=datetime21.2 /* date and time of last report generation*/
257  ,tsu_testcoverage INT FORMAT=8. /* see i_testcoverage */
258  ,tsu_dbversion CHAR(8) /* Version String to force creation of a new test data base */
259  ,tsu_verbose INT FORMAT=8. /* see i_verbose */
260  ,tsu_crossref INT FORMAT=8. /* see i_crossref */
261  ,tsu_crossrefsasunit INT FORMAT=8. /* see i_crossrefsasunit */
262  );
263  INSERT INTO target.tsu VALUES (
264  "","","","","","","","","","","","","","","","","","","","","","",0,0,&i_testcoverage.,"",&i_verbose.,&i_crossref.,&i_crossrefsasunit.
265  );
266 
267  CREATE TABLE target.scn(COMPRESS=CHAR)
268  ( /* test scenario */
269  scn_id INT FORMAT=z3. /* number of scenario */
270  ,scn_path CHAR(1000) /* path to program file */
271  ,scn_desc CHAR(1000) /* description of program (brief tag in comment header) */
272  ,scn_start INT FORMAT=datetime21.2 /* starting date and time of the last run */
273  ,scn_end INT FORMAT=datetime21.2 /* ending date and time of the last run */
274  ,scn_rc INT /* return code of SAS session of last run */
275  ,scn_errorcount INT /* number of detected errors in the scenario log */
276  ,scn_warningcount INT /* number of detected warnings in the scenario log */
277  ,scn_res INT /* overall test result of last run: 0 .. OK, 1 .. not OK, 2 .. manual */
278  );
279  CREATE TABLE target.cas(COMPRESS=CHAR)
280  ( /* test case */
281  cas_scnid INT FORMAT=z3. /* reference to test scenario */
282  ,cas_id INT FORMAT=z3. /* sequential number of test case within test scenario */
283  ,cas_auton INT /* number of autocall path where program under test has been found or ., if not found */
284  ,cas_pgm CHAR(255) /* file name of program under test: only name if found in autocall paths, or fully qualified path otherwise */
285  ,cas_desc CHAR(1000) /* description of test case */
286  ,cas_spec CHAR(1000) /* optional: specification document, fully qualified path or only filename to be found in folder &g_doc */
287  ,cas_start INT FORMAT=datetime21.2 /* starting date and time of the last run */
288  ,cas_end INT FORMAT=datetime21.2 /* ending date and time of the last run */
289  ,cas_res INT /* overall test result of last run: 0 .. OK, 1 .. not OK, 2 .. manual */
290  );
291  CREATE TABLE target.tst(COMPRESS=CHAR)
292  ( /* Test */
293  tst_scnid INT FORMAT=z3. /* reference to test scenario */
294  ,tst_casid INT FORMAT=z3. /* reference to test case */
295  ,tst_id INT FORMAT=z3. /* sequential number of test within test case */
296  ,tst_type CHAR(32) /* type of test (name of assert macro) */
297  ,tst_desc CHAR(1000) /* description of test */
298  ,tst_exp CHAR(255) /* expected result */
299  ,tst_act CHAR(255) /* actual result */
300  ,tst_res INT /* test result of the last run: 0 .. OK, 1 .. manual, 2 .. not OK */
301  ,tst_errmsg CHAR(1000) /* custom error message for asserts */
302  );
303  QUIT;
304  %IF %_handleError(&l_macname.
305  ,ErrorCreateDB
306  ,&syserr. NE 0
307  ,Error on creation of test database
308  ,i_verbose=&i_verbose.
309  )
310  %THEN %GOTO errexit;
311 
312 
313  /*-- regenerate empty folders ------------------------------------------------*/
314  %LET l_cmdfile=%sysfunc(pathname(WORK))/remove_dir.cmd;
315  DATA _null_;
316  FILE "&l_cmdfile." encoding=pcoem850; /* wg. Umlauten in Pfaden */
317  PUT "&g_removedir ""&l_target_abs/log""&g_endcommand";
318  PUT "&g_removedir ""&l_target_abs/tst""&g_endcommand";
319  PUT "&g_removedir ""&l_target_abs/rep""&g_endcommand";
320  RUN;
321  %_executeCMDFile(&l_cmdfile.);
322  %LET l_rc=%_delfile(&l_cmdfile.);
323  %LET rc = %sysfunc (sleep(2,1));
324  %LET l_cmdfile=%sysfunc(pathname(WORK))/make_dir.cmd;
325  DATA _null_;
326  FILE "&l_cmdfile." encoding=pcoem850; /* wg. Umlauten in Pfaden */
327  PUT "&g_makedir ""&l_target_abs/log""&g_endcommand";
328  PUT "&g_makedir ""&l_target_abs/tst""&g_endcommand";
329  PUT "&g_makedir ""&l_target_abs/rep""&g_endcommand";
330  RUN;
331  %_executeCMDFile(&l_cmdfile.);
332  %LET l_rc=%_delfile(&l_cmdfile.);
333  %END; /* %if &l_newdb */
334 
335  /*-- folder for crossreference json files has to be always recreated -----------*/
336  %LET l_cmdfile=%sysfunc(pathname(WORK))/remove_dir.cmd;
337  DATA _null_;
338  FILE "&l_cmdfile." encoding=pcoem850; /* wg. Umlauten in Pfaden */
339  PUT "&g_removedir ""&l_target_abs/tst/crossreference""&g_endcommand";
340  RUN;
341  %_executeCMDFile(&l_cmdfile.);
342  %LET l_rc=%_delfile(&l_cmdfile.);
343  %LET rc = %sysfunc (sleep(2,1));
344  %LET l_cmdfile=%sysfunc(pathname(WORK))/make_dir.cmd;
345  DATA _null_;
346  FILE "&l_cmdfile." encoding=pcoem850; /* wg. Umlauten in Pfaden */
347  PUT "&g_makedir ""&l_target_abs/tst/crossreference""&g_endcommand";
348  RUN;
349  %_executeCMDFile(&l_cmdfile.);
350  %LET l_rc=%_delfile(&l_cmdfile.);
351 
352  /*-- check folders -----------------------------------------------------------*/
353  %IF %_handleError(&l_macname.
354  ,NoLogDir
355  ,NOT %_existdir(&l_target_abs./log)
356  ,folder &l_target_abs./log does not exist
357  ,i_verbose=&i_verbose.
358  )
359  %THEN %GOTO errexit;
360  %IF %_handleError(&l_macname.
361  ,NoTstDir
362  ,NOT %_existdir(&l_target_abs./tst)
363  ,folder &l_target_abs./tst does not exist
364  ,i_verbose=&i_verbose.
365  )
366  %THEN %GOTO errexit;
367  %IF %_handleError(&l_macname.
368  ,NoRepDir
369  ,NOT %_existdir(&l_target_abs./rep)
370  ,folder &l_target_abs./rep does not exist
371  ,i_verbose=&i_verbose.
372  )
373  %THEN %GOTO errexit;
374  PROC SQL NOPRINT;
375  UPDATE target.tsu SET tsu_target = "&io_target";
376  QUIT;
377 
378  /*-- project name ------------------------------------------------------------*/
379  %IF "&i_project" = "" %THEN %DO;
380  PROC SQL NOPRINT;
381  SELECT tsu_project INTO :l_project FROM target.tsu;
382  QUIT;
383  %LET l_project=&l_project;
384  %END;
385  %ELSE %DO;
386  %LET l_project=&i_project;
387  %END;
388  %IF %_handleError(&l_macname.
389  ,MissingProjectName
390  ,"&l_project" EQ ""
391  ,Parameter i_project must be specified
392  ,i_verbose=&i_verbose.
393  )
394  %THEN %GOTO errexit;
395  PROC SQL NOPRINT;
396  UPDATE target.tsu SET tsu_project = "&l_project";
397  QUIT;
398 
399  /*-- root folder -------------------------------------------------------------*/
400  %IF "&l_root" = "" %THEN %DO;
401  PROC SQL NOPRINT;
402  SELECT tsu_root INTO :l_root FROM target.tsu;
403  QUIT;
404  %LET l_root=&l_root;
405  %END;
406  %IF %_handleError(&l_macname.
407  ,InvalidRoot
408  ,"&l_root" NE "" AND NOT %_existdir(&l_root)
409  ,%str(Error in parameter i_root: folder must exist when specified)
410  ,i_verbose=&i_verbose.
411  )
412  %THEN %GOTO errexit;
413  PROC SQL NOPRINT;
414  UPDATE target.tsu SET tsu_root = "&l_root";
415  QUIT;
416 
417  /*-- sasunit root folder -------------------------------------------------------------*/
418  %LET l_sasunitroot=&l_sasunitroot;
419  %IF %_handleError(&l_macname.
420  ,InvalidRoot
421  ,"&l_sasunitroot" NE "" AND NOT %_existdir(&l_sasunitroot)
422  ,%str(Error in parameter l_sasunitroot: folder must exist when specified)
423  ,i_verbose=&i_verbose.
424  )
425  %THEN %GOTO errexit;
426  PROC SQL NOPRINT;
427  UPDATE target.tsu SET tsu_sasunitroot = "&l_sasunitroot";
428  QUIT;
429 
430  /*-- sasunit folder ----------------------------------------------------------*/
431  %IF "&l_sasunit" = "" %THEN %DO;
432  PROC SQL NOPRINT;
433  SELECT tsu_sasunit INTO :l_sasunit FROM target.tsu;
434  QUIT;
435  %LET l_sasunit=&l_sasunit;
436  %END;
437  %LET l_abs=%_abspath(&l_root.,&l_sasunit.);
438  %IF %_handleError(&l_macname.
439  ,InvalidSASUnitDir
440  ,"&l_abs." EQ "" OR NOT %sysfunc(fileexist(&l_abs./_scenario.sas))
441  ,Error in parameter i_sasunit: SASUnit macro programs not found
442  ,i_verbose=&i_verbose.
443  )
444  %THEN %GOTO errexit;
445  PROC SQL NOPRINT;
446  UPDATE target.tsu SET tsu_sasunit = "&l_sasunit";
447  QUIT;
448 
449  /*-- os-specific sasunit folder ----------------------------------------------------------*/
450  %LET l_sasunit_os=&l_sasunit_os;
451  %IF %_handleError(&l_macname.
452  ,InvalidSASUnitDir
453  ,"&l_abspath_sasunit_os." EQ "" OR NOT %sysfunc(fileexist(&l_abspath_sasunit_os./_oscmds.sas))
454  ,Error in parameter i_sasunit: os-specific SASUnit macro programs not found
455  ,i_verbose=&i_verbose.
456  )
457  %THEN %GOTO errexit;
458  PROC SQL NOPRINT;
459  UPDATE target.tsu SET tsu_sasunit_os = "&l_sasunit_os";
460  QUIT;
461  /*-- check if autoexec exists where specified --------------------------------*/
462  PROC SQL NOPRINT;
463  SELECT tsu_autoexec INTO :l_autoexec FROM target.tsu;
464  QUIT;
465  %LET l_autoexec=&l_autoexec;
466  %*** because we need to specify a real blank (%str( )) as parameter, ***;
467  %*** we need to use a different method of assignment. ***;
468  %IF "&i_autoexec" NE "" %THEN %LET l_autoexec=%trim(&i_autoexec);
469  %LET l_autoexec_abs=%_abspath(&l_root,&l_autoexec);
470  %IF %_handleError(&l_macname.
471  ,AutoexecNotFound
472  ,"&l_autoexec" NE "" AND NOT %sysfunc(fileexist(&l_autoexec_abs%str( )))
473  ,Error in parameter i_autoexec: file not found
474  ,i_verbose=&i_verbose.
475  )
476  %THEN %GOTO errexit;
477  PROC SQL NOPRINT;
478  UPDATE target.tsu SET tsu_autoexec = "&l_autoexec";
479  QUIT;
480 
481  /*-- check if sascfg exists where specified ----------------------------------*/
482  PROC SQL NOPRINT;
483  SELECT tsu_sascfg INTO :l_sascfg FROM target.tsu;
484  QUIT;
485  %LET l_sascfg=&l_sascfg;
486  %IF "&i_sascfg" NE "" %THEN %LET l_sascfg=&i_sascfg;
487  %LET l_sascfg_abs=%_abspath(&l_root,&l_sascfg);
488  %IF %_handleError(&l_macname.
489  ,SASCfgNotFound
490  ,"&l_sascfg" NE "" AND NOT %sysfunc(fileexist(&l_sascfg_abs%str( )))
491  ,Error in parameter i_sascfg: file not found
492  ,i_verbose=&i_verbose.
493  )
494  %THEN %GOTO errexit;
495  PROC SQL NOPRINT;
496  UPDATE target.tsu SET tsu_sascfg = "&l_sascfg";
497  QUIT;
498 
499  /*-- check sasuser folder ----------------------------------------------------*/
500  PROC SQL NOPRINT;
501  SELECT tsu_sasuser INTO :l_sasuser FROM target.tsu;
502  QUIT;
503  %LET l_sasuser=&l_sasuser;
504  %IF "&i_sasuser" NE "" %THEN %LET l_sasuser=&i_sasuser;
505  %LET l_sasuser_abs=%_abspath(&l_root,&l_sasuser);
506  %IF %_handleError(&l_macname.
507  ,InvalidSasuser
508  ,"&l_sasuser_abs" NE "" AND NOT %_existdir(&l_sasuser_abs)
509  ,Error in parameter i_sasuser: folder not found
510  ,i_verbose=&i_verbose.
511  )
512  %THEN %GOTO errexit;
513  PROC SQL NOPRINT;
514  UPDATE target.tsu SET tsu_sasuser = "&l_sasuser";
515  QUIT;
516 
517  /*-- check test data folder --------------------------------------------------*/
518  PROC SQL NOPRINT;
519  SELECT tsu_testdata INTO :l_testdata FROM target.tsu;
520  QUIT;
521  %LET l_testdata=&l_testdata;
522  %IF "&i_testdata" NE "" %THEN %LET l_testdata=&i_testdata;
523  %LET l_testdata_abs=%_abspath(&l_root,&l_testdata);
524  %IF %_handleError(&l_macname.
525  ,InvalidTestdata
526  ,"&l_testdata_abs" NE "" AND NOT %_existdir(&l_testdata_abs)
527  ,Error in parameter i_testdata: folder not found
528  ,i_verbose=&i_verbose.
529  )
530  %THEN %GOTO errexit;
531  PROC SQL NOPRINT;
532  UPDATE target.tsu SET tsu_testdata = "&l_testdata";
533  QUIT;
534 
535  /*-- check reference data folder ---------------------------------------------*/
536  PROC SQL NOPRINT;
537  SELECT tsu_refdata INTO :l_refdata FROM target.tsu;
538  QUIT;
539  %LET l_refdata=&l_refdata;
540  %IF "&i_refdata" NE "" %THEN %LET l_refdata=&i_refdata;
541  %LET l_refdata_abs=%_abspath(&l_root,&l_refdata);
542  %IF %_handleError(&l_macname.
543  ,InvalidRefdata
544  ,"&l_refdata_abs" NE "" AND NOT %_existdir(&l_refdata_abs)
545  ,Error in parameter i_refdata: folder not found
546  ,i_verbose=&i_verbose.
547  )
548  %THEN %GOTO errexit;
549  PROC SQL NOPRINT;
550  UPDATE target.tsu SET tsu_refdata = "&l_refdata";
551  QUIT;
552 
553  /*-- check folder for specification documents --------------------------------*/
554  PROC SQL NOPRINT;
555  SELECT tsu_doc INTO :l_doc FROM target.tsu;
556  QUIT;
557  %LET l_doc=&l_doc;
558  %IF "&i_doc" NE "" %THEN %LET l_doc=&i_doc;
559  %LET l_doc_abs=%_abspath(&l_root,&l_doc);
560  %IF %_handleError(&l_macname.
561  ,InvalidDoc
562  ,"&l_doc_abs" NE "" AND NOT %_existdir(&l_doc_abs)
563  ,Error in parameter i_doc: folder not found
564  ,i_verbose=&i_verbose.
565  )
566  %THEN %GOTO errexit;
567  PROC SQL NOPRINT;
568  UPDATE target.tsu SET tsu_doc = "&l_doc";
569  QUIT;
570 
571  /*-- check autocall paths ----------------------------------------------------*/
572  %LET restore_sasautos=%sysfunc(getoption(sasautos));
573 
574  PROC SQL NOPRINT;
575  SELECT tsu_sasautos INTO :l_sasautos FROM target.tsu;
576  QUIT;
577  %LET l_sasautos=&l_sasautos;
578  %IF "&i_sasautos" NE "" %THEN %LET l_sasautos=&i_sasautos;
579  %LET l_sasautos_abs=%_abspath(&l_root,&l_sasautos);
580  %IF %_handleError(&l_macname.
581  ,InvalidSASAutos
582  ,"&l_sasautos_abs" NE "" AND NOT %_existdir(&l_sasautos_abs)
583  ,Error in parameter i_sasautos: folder not found
584  ,i_verbose=&i_verbose.
585  )
586  %THEN %GOTO errexit;
587  PROC SQL NOPRINT;
588  UPDATE target.tsu SET tsu_sasautos = "&l_sasautos";
589  QUIT;
590 
591  %DO i=1 %TO 9;
592  PROC SQL NOPRINT;
593  SELECT tsu_sasautos&i. INTO :l_sasautos FROM target.tsu;
594  QUIT;
595  %LET l_sasautos=&l_sasautos;
596  %IF "&&i_sasautos&i" NE "" %THEN %LET l_sasautos=&&i_sasautos&i;
597  %LET l_sasautos_abs=%_abspath(&l_root,&l_sasautos);
598  %IF %_handleError(&l_macname.
599  ,InvalidSASAutosN
600  ,"&l_sasautos_abs" NE "" AND NOT %_existdir(&l_sasautos_abs)
601  ,Error in parameter i_sasautos&i: folder not found
602  ,i_verbose=&i_verbose.
603  )
604  %THEN %GOTO errexit;
605  PROC SQL NOPRINT;
606  UPDATE target.tsu SET tsu_sasautos&i. = "&l_sasautos";
607  QUIT;
608  %END; /* i=1 %TO 9 */
609 
610  /*-- update parameters ----------------------------------------------------*/
611  PROC SQL NOPRINT;
612  UPDATE target.tsu SET tsu_testcoverage =&i_testcoverage;
613  UPDATE target.tsu SET tsu_verbose =&i_verbose;
614  UPDATE target.tsu SET tsu_crossref =&i_crossref;
615  UPDATE target.tsu SET tsu_crossrefsasunit =&i_crossrefsasunit;
616  QUIT;
617 
618  /*-- load relevant information from test database to global macro symbols ----*/
619  %_loadEnvironment (i_withLibrefs = 0
620  )
621  /* Correct Termstring in Textfiles */
622  %_prepareTextFiles;
623 
624  %IF "&g_error_code" NE "" %THEN %GOTO errexit;
625 
626  /*-- check spawning of a SAS process -----------------------------------------*/
627  /* a file will be created in the work library of the parent (this) process
628  to check whether spawning works */
629  %LET l_work = %sysfunc(pathname(work));
630  PROC DATASETS NOLIST NOWARN LIB=work;
631  DELETE check;
632  QUIT;
633 
634  DATA _null_;
635  FILE "&l_work/check_spawning.sas";
636  PUT "LIBNAME awork ""&l_work"";";
637  PUT "DATA awork.check; RUN;";
638  RUN;
639 
640  %_runProgramSpawned(i_program =&l_work./check_spawning.sas
641  ,i_scnid =000
642  ,i_generateMcoverage=0
643  ,r_sysrc =l_sysrc
644  );
645 
646  %IF %_handleError(&l_macname.
647  ,ErrorSASCall2
648  ,NOT %sysfunc(exist(work.check))
649  ,Error spawning SAS process in initialization
650  ,i_verbose=&i_verbose.
651  )
652  %THEN %GOTO errexit;
653 
654  PROC DATASETS NOLIST NOWARN LIB=work;
655  DELETE check;
656  QUIT;
657 
658  %LET l_rc=%_delFile(&l_work/run.sas);
659 
660  /*-- save time of initialization ---------------------------------------------*/
661  PROC SQL NOPRINT;
662  UPDATE target.tsu
663  SET tsu_lastinit = %sysfunc(datetime())
664  ;
665  QUIT;
666 
667  /*-- update column tsu_dbVersion ------------------------------------------*/
668  PROC SQL NOPRINT;
669  UPDATE target.tsu
670  SET tsu_dbVersion = "&g_version."
671  ;
672  QUIT;
673 
674  %PUT;
675  %PUT ============================ SASUnit has been initialized successfully ==========================;
676  %PUT;
677 
678  %GOTO exit;
679 %errexit:
680  %PUT;
681  %PUT &g_error: ===================== Error! Testsuite aborted! ===========================================;
682  %PUT;
683  LIBNAME target;
684  endsas;
685 %exit:
686 %MEND initSASUnit;
687