source: ccr/trunk/p/GPLUNIT.m@ 46

Last change on this file since 46 was 43, checked in by George Lilly, 16 years ago

Format changes for SAC compliance

File size: 5.3 KB
Line 
1GPLUNIT ; CCDCCR/GPL - Unit Testing Library; 5/07/08
2 ;;0.1;CCDCCR;nopatch;noreleasedate
3 W "This is a unit testing library",!
4 W !
5 Q
6 ;
7ZT(ZARY,BAT,TST) ; private routine to add a test case to the ZARY array
8 ; ZARY IS PASSED BY REFERENCE
9 ; BAT is a string identifying the test battery
10 ; TST is a test which will evaluate to true or false
11 ; I '$G(ZARY) D
12 ; . S ZARY(0)=0 ; initially there are no elements
13 ; W "GOT HERE LOADING "_TST,!
14 N CNT ; count of array elements
15 S CNT=ZARY(0) ; contains array count
16 S CNT=CNT+1 ; increment count
17 S ZARY(CNT)=TST ; put the test in the array
18 I $D(ZARY(BAT)) D ; NOT THE FIRST TEST IN BATTERY
19 . N II,TN ; TEMP FOR ENDING TEST IN BATTERY
20 . S II=$P(ZARY(BAT),"^",2)
21 . S $P(ZARY(BAT),"^",2)=II+1
22 I '$D(ZARY(BAT)) D ; FIRST TEST IN THIS BATTERY
23 . S ZARY(BAT)=CNT_"^"_CNT ; FIRST AND LAST TESTS IN BATTERY
24 . S ZARY("TESTS",BAT)="" ; PUT THE BATTERY IN THE TESTS INDEX
25 . ; S TN=$NA(ZARY("TESTS"))
26 . ; D PUSH^GPLXPATH(TN,BAT)
27 S ZARY(0)=CNT ; update the array counter
28 Q
29 ;
30ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference
31 ; ZARY IS PASSED BY NAME
32 ; ZARY = name of the root, closed array format (e.g., "^TMP($J)")
33 ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE
34 K @ZARY
35 S @ZARY@(0)=0 ; initialize array count
36 N LINE,LABEL,BODY
37 N INTEST S INTEST=0 ; switch for in the test case section
38 N SECTION S SECTION="[anonymous]" ; test case section
39 ;
40 N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D
41 . W NUM," ",LINE,!
42 . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section
43 . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section
44 . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section
45 . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section
46 . I INTEST D ; within the testing section
47 . . I LINE?." "1";;><".E D ; section name found
48 . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name
49 . . I LINE?." "1";;>>".E D ; test case found
50 . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array
51 S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL
52 Q
53 ;
54ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST
55 N I,ZX,ZR,ZP
56 S DEBUG=0
57 ; I WHICH="ALL" D Q ; RUN ALL THE TESTS
58 ; . W "DOING ALL",!
59 ; . N J,NT
60 ; . S NT=$NA(ZARY("TESTS"))
61 ; . W NT,@NT@(0),!
62 ; . F J=1:1:@NT@(0) D ;
63 ; . . W @NT@(J),!
64 ; . . D ZTEST^GPLUNIT(@ZARY,@NT@(J))
65 I '$D(ZARY(WHICH)) D ; TEST SECTION DOESN'T EXIST
66 . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,!
67 . Q ; EXIT
68 N FIRST,LAST
69 S FIRST=$P(ZARY(WHICH),"^",1)
70 S LAST=$P(ZARY(WHICH),"^",2)
71 F I=FIRST:1:LAST D
72 . I ZARY(I)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT
73 . . S ZP=$E(ZARY(I),2,$L(ZARY(I)))
74 . . ; W ZP,!
75 . . S ZX=ZP
76 . . W "RUNNING: "_ZP
77 . . X ZX
78 . . W "..SUCCESS: ",WHICH,!
79 . I ZARY(I)?1"?"1.E D ; THIS IS A TEST
80 . . S ZP=$E(ZARY(I),2,$L(ZARY(I)))
81 . . S ZX="S ZR="_ZP
82 . . W "TRYING: "_ZP
83 . . X ZX
84 . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),!
85 . . I '$D(TPASSED) D ; NOT INITIALIZED YET
86 . . . S TPASSED=0 S TFAILED=0
87 . . I ZR S TPASSED=TPASSED+1
88 . . I 'ZR S TFAILED=TFAILED+1
89 Q
90 ;
91TEST ; RUN ALL THE TEST CASES
92 N ZTMP
93 D ZLOAD(.ZTMP)
94 D ZTEST(.ZTMP,"ALL")
95 W "PASSED: ",TPASSED,!
96 W "FAILED: ",TFAILED,!
97 W !
98 W "THE TESTS!",!
99 ZWR ZTMP
100 Q
101 ;
102GTSTS(GTZARY,RTN) ; return an array of test names
103 N I,J S I="" S I=$O(GTZARY("TESTS",I))
104 F J=0:0 Q:I="" D
105 . D PUSH^GPLXPATH(RTN,I)
106 . S I=$O(GTZARY("TESTS",I))
107 Q
108 ;
109TESTALL(RNM) ; RUN ALL THE TESTS
110 N I,J,TZTMP,TSTS,TOTP,TOTF
111 S TOTP=0 S TOTF=0
112 D ZLOAD^GPLUNIT("TZTMP",RNM)
113 D GTSTS(.TZTMP,"TSTS")
114 F I=1:1:TSTS(0) D ;
115 . S TPASSED=0 S TFAILED=0
116 . D ZTEST^GPLUNIT(.TZTMP,TSTS(I))
117 . S TOTP=TOTP+TPASSED
118 . S TOTF=TOTF+TFAILED
119 . S $P(TSTS(I),"^",2)=TPASSED
120 . S $P(TSTS(I),"^",3)=TFAILED
121 F I=1:1:TSTS(0) D ;
122 . W "TEST=> ",$P(TSTS(I),"^",1)
123 . W " PASSED=>",$P(TSTS(I),"^",2)
124 . W " FAILED=>",$P(TSTS(I),"^",3),!
125 W "TOTAL=> PASSED:",TOTP," FAILED:",TOTF,!
126 Q
127 ;
128TLIST(ZARY) ; LIST ALL THE TESTS
129 ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES
130 ; ZARY IS PASSED BY REFERENCE
131 N I,J,K S I="" S I=$O(ZARY("TESTS",I))
132 S K=1
133 F J=0:0 Q:I="" D
134 . ; W "I IS NOW=",I,!
135 . W I," "
136 . S I=$O(ZARY("TESTS",I))
137 . S K=K+1 I K=6 D
138 . . W !
139 . . S K=1
140 Q
141 ;
Note: See TracBrowser for help on using the repository browser.