59 %MACRO initSASUnit(i_root =
83 ,i_crossrefsasunit = 0
86 %GLOBAL g_version g_revision g_verbose g_error g_warning g_note;
88 %LET g_version = 1.5.0;
89 %LET g_revision = $Revision: 368 $;
90 %LET g_revision = %scan(&g_revision,2,%str( $:));
94 %IF (&i_crossrefsasunit. NE 0) %THEN %DO;
95 %LET i_crossrefsasunit = 1;
97 %IF (&i_crossref. NE 0) %THEN %DO;
100 %IF (&i_verbose. NE 0) %THEN %DO;
103 %LET g_verbose = &i_verbose;
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
112 %LET l_current_dbversion=0;
113 %LET l_macname=&sysmacroname;
116 libname _tmp
"&i_root.";
117 %let l_root=%sysfunc (pathname(_tmp));
121 libname _tmp
"%sysget(SASUNIT_ROOT)";
122 %let l_sasunitroot=%sysfunc (pathname(_tmp));
126 libname _tmp
"&i_sasunit";
127 %let l_sasunit=%sysfunc (pathname(_tmp));
134 %IF %_handleError(&l_macname.
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.
143 %IF (&sysscp. = WIN) %THEN %DO;
144 %LET l_sasunit_os = &l_sasunit./windows;
146 %ELSE %IF (%upcase(&sysscpl.) = LINUX) %THEN %DO;
147 %LET l_sasunit_os = &l_sasunit./linux;
149 %ELSE %IF (%upcase(&sysscpl.) = AIX) %THEN %DO;
150 %LET l_sasunit_os = &l_sasunit./unix_aix;
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;
159 %_detectSymbols(r_error_symbol=g_error, r_warning_symbol=g_warning, r_note_symbol=g_note);
162 %IF %_handleError(&l_macname.
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.
172 %IF &i_testcoverage. NE 1 %THEN %DO;
173 %LET i_testcoverage = 0;
177 %IF %_handleError(&l_macname.
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.
187 %LET l_target_abs=%_abspath(&i_root,&io_target);
188 %IF %_handleError(&l_macname.
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.
196 LIBNAME target
"&l_target_abs";
197 %IF %_handleError(&l_macname
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.
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.
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)));
217 *** Check tsu db version ***;
218 *** Is there a need to recreate the database? ***;
219 %IF &l_newdb. ne 1 %THEN %DO;
221 if (exist (
"target.tsu")) then
do;
222 did = open (
"target.tsu");
223 if varnum (did,
"tsu_dbVersion") then do;
225 tsu_dbVersion = getvarc (did, varnum (did, "tsu_dbVersion"));
226 call symput ("l_current_dbversion", trim(tsu_dbVersion));
231 %LET l_newdb=%eval ("&l_current_dbversion." NE "&g_version.");
235 %IF &l_newdb %THEN %DO;
237 CREATE TABLE target.tsu(COMPRESS=CHAR)
239 tsu_project CHAR(1000)
241 ,tsu_target CHAR(1000)
242 ,tsu_sasunitroot CHAR(1000)
243 ,tsu_sasunit CHAR(1000)
244 ,tsu_sasunit_os CHAR(1000)
245 ,tsu_sasautos CHAR(1000)
247 ,tsu_sasautos&i CHAR(1000)
249 ,tsu_autoexec CHAR(1000)
250 ,tsu_sascfg CHAR(1000)
251 ,tsu_sasuser CHAR(1000)
252 ,tsu_testdata CHAR(1000)
253 ,tsu_refdata CHAR(1000)
255 ,tsu_lastinit INT FORMAT=datetime21.2
256 ,tsu_lastrep INT FORMAT=datetime21.2
257 ,tsu_testcoverage INT FORMAT=8.
258 ,tsu_dbversion CHAR(8)
259 ,tsu_verbose INT FORMAT=8.
260 ,tsu_crossref INT FORMAT=8.
261 ,tsu_crossrefsasunit INT FORMAT=8.
263 INSERT INTO target.tsu VALUES (
264 "","","","","","","","","","","","","","","","","","","","","","",0,0,&i_testcoverage.,"",&i_verbose.,&i_crossref.,&i_crossrefsasunit.
267 CREATE TABLE target.scn(COMPRESS=CHAR)
269 scn_id INT FORMAT=z3.
272 ,scn_start INT FORMAT=datetime21.2
273 ,scn_end INT FORMAT=datetime21.2
276 ,scn_warningcount INT
279 CREATE TABLE target.cas(COMPRESS=CHAR)
281 cas_scnid INT FORMAT=z3.
282 ,cas_id INT FORMAT=z3.
287 ,cas_start INT FORMAT=datetime21.2
288 ,cas_end INT FORMAT=datetime21.2
291 CREATE TABLE target.tst(COMPRESS=CHAR)
293 tst_scnid INT FORMAT=z3.
294 ,tst_casid INT FORMAT=z3.
295 ,tst_id INT FORMAT=z3.
301 ,tst_errmsg CHAR(1000)
304 %IF %_handleError(&l_macname.
307 ,Error on creation of test database
308 ,i_verbose=&i_verbose.
314 %LET l_cmdfile=%sysfunc(pathname(WORK))/remove_dir.cmd;
316 FILE "&l_cmdfile." encoding=pcoem850;
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";
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;
326 FILE "&l_cmdfile." encoding=pcoem850;
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";
331 %_executeCMDFile(&l_cmdfile.);
332 %LET l_rc=%_delfile(&l_cmdfile.);
336 %LET l_cmdfile=%sysfunc(pathname(WORK))/remove_dir.cmd;
338 FILE "&l_cmdfile." encoding=pcoem850;
339 PUT "&g_removedir ""&l_target_abs/tst/crossreference""&g_endcommand";
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;
346 FILE "&l_cmdfile." encoding=pcoem850;
347 PUT "&g_makedir ""&l_target_abs/tst/crossreference""&g_endcommand";
349 %_executeCMDFile(&l_cmdfile.);
350 %LET l_rc=%_delfile(&l_cmdfile.);
353 %IF %_handleError(&l_macname.
355 ,NOT %_existdir(&l_target_abs./log)
356 ,folder &l_target_abs./log does not exist
357 ,i_verbose=&i_verbose.
360 %IF %_handleError(&l_macname.
362 ,NOT %_existdir(&l_target_abs./tst)
363 ,folder &l_target_abs./tst does not exist
364 ,i_verbose=&i_verbose.
367 %IF %_handleError(&l_macname.
369 ,NOT %_existdir(&l_target_abs./rep)
370 ,folder &l_target_abs./rep does not exist
371 ,i_verbose=&i_verbose.
375 UPDATE target.tsu SET tsu_target = "&io_target";
379 %IF "&i_project" = "" %THEN %DO;
381 SELECT tsu_project INTO :l_project FROM target.tsu;
383 %LET l_project=&l_project;
386 %LET l_project=&i_project;
388 %IF %_handleError(&l_macname.
391 ,Parameter i_project must be specified
392 ,i_verbose=&i_verbose.
396 UPDATE target.tsu SET tsu_project = "&l_project";
400 %IF "&l_root" = "" %THEN %DO;
402 SELECT tsu_root INTO :l_root FROM target.tsu;
406 %IF %_handleError(&l_macname.
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.
414 UPDATE target.tsu SET tsu_root = "&l_root";
418 %LET l_sasunitroot=&l_sasunitroot;
419 %IF %_handleError(&l_macname.
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.
427 UPDATE target.tsu SET tsu_sasunitroot = "&l_sasunitroot";
431 %IF "&l_sasunit" = "" %THEN %DO;
433 SELECT tsu_sasunit INTO :l_sasunit FROM target.tsu;
435 %LET l_sasunit=&l_sasunit;
437 %LET l_abs=%_abspath(&l_root.,&l_sasunit.);
438 %IF %_handleError(&l_macname.
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.
446 UPDATE target.tsu SET tsu_sasunit = "&l_sasunit";
450 %LET l_sasunit_os=&l_sasunit_os;
451 %IF %_handleError(&l_macname.
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.
459 UPDATE target.tsu SET tsu_sasunit_os = "&l_sasunit_os";
463 SELECT tsu_autoexec INTO :l_autoexec FROM target.tsu;
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.
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.
478 UPDATE target.tsu SET tsu_autoexec = "&l_autoexec";
483 SELECT tsu_sascfg INTO :l_sascfg FROM target.tsu;
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.
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.
496 UPDATE target.tsu SET tsu_sascfg = "&l_sascfg";
501 SELECT tsu_sasuser INTO :l_sasuser FROM target.tsu;
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.
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.
514 UPDATE target.tsu SET tsu_sasuser = "&l_sasuser";
519 SELECT tsu_testdata INTO :l_testdata FROM target.tsu;
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.
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.
532 UPDATE target.tsu SET tsu_testdata = "&l_testdata";
537 SELECT tsu_refdata INTO :l_refdata FROM target.tsu;
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.
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.
550 UPDATE target.tsu SET tsu_refdata = "&l_refdata";
555 SELECT tsu_doc INTO :l_doc FROM target.tsu;
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.
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.
568 UPDATE target.tsu SET tsu_doc = "&l_doc";
572 %LET restore_sasautos=%sysfunc(getoption(sasautos));
575 SELECT tsu_sasautos INTO :l_sasautos FROM target.tsu;
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.
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.
588 UPDATE target.tsu SET tsu_sasautos = "&l_sasautos";
593 SELECT tsu_sasautos&i. INTO :l_sasautos FROM target.tsu;
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.
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.
606 UPDATE target.tsu SET tsu_sasautos&i. = "&l_sasautos";
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;
619 %_loadEnvironment (i_withLibrefs = 0
624 %IF "&g_error_code" NE "" %THEN %GOTO errexit;
629 %LET l_work = %sysfunc(pathname(work));
630 PROC DATASETS NOLIST NOWARN LIB=work;
635 FILE "&l_work/check_spawning.sas";
636 PUT "LIBNAME awork ""&l_work"";";
637 PUT "DATA awork.check; RUN;";
640 %_runProgramSpawned(i_program =&l_work./check_spawning.sas
642 ,i_generateMcoverage=0
646 %IF %_handleError(&l_macname.
648 ,NOT %sysfunc(exist(work.check))
649 ,Error spawning SAS process in initialization
650 ,i_verbose=&i_verbose.
654 PROC DATASETS NOLIST NOWARN LIB=work;
658 %LET l_rc=%_delFile(&l_work/run.sas);
663 SET tsu_lastinit = %sysfunc(datetime())
670 SET tsu_dbVersion = "&g_version."
675 %PUT ============================ SASUnit has been initialized successfully ==========================;
681 %PUT &g_error: ===================== Error! Testsuite aborted! ===========================================;