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

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

fixed printing test name ie: TESTGPLXPATH

File size: 6.1 KB
Line 
1GPLUNIT ; CCDCCR/GPL - Unit Testing Library; 5/07/08
2 ;;0.1;CCDCCR;nopatch;noreleasedate
3 ;Copyright 2008 WorldVistA. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
5 ;
6 ;This program is free software; you can redistribute it and/or modify
7 ;it under the terms of the GNU General Public License as published by
8 ;the Free Software Foundation; either version 2 of the License, or
9 ;(at your option) any later version.
10 ;
11 ;This program is distributed in the hope that it will be useful,
12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;GNU General Public License for more details.
15 ;
16 ;You should have received a copy of the GNU General Public License along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 W "This is a unit testing library",!
21 W !
22 Q
23 ;
24ZT(ZARY,BAT,TST) ; private routine to add a test case to the ZARY array
25 ; ZARY IS PASSED BY REFERENCE
26 ; BAT is a string identifying the test battery
27 ; TST is a test which will evaluate to true or false
28 ; I '$G(ZARY) D
29 ; . S ZARY(0)=0 ; initially there are no elements
30 ; W "GOT HERE LOADING "_TST,!
31 N CNT ; count of array elements
32 S CNT=ZARY(0) ; contains array count
33 S CNT=CNT+1 ; increment count
34 S ZARY(CNT)=TST ; put the test in the array
35 I $D(ZARY(BAT)) D ; NOT THE FIRST TEST IN BATTERY
36 . N II,TN ; TEMP FOR ENDING TEST IN BATTERY
37 . S II=$P(ZARY(BAT),"^",2)
38 . S $P(ZARY(BAT),"^",2)=II+1
39 I '$D(ZARY(BAT)) D ; FIRST TEST IN THIS BATTERY
40 . S ZARY(BAT)=CNT_"^"_CNT ; FIRST AND LAST TESTS IN BATTERY
41 . S ZARY("TESTS",BAT)="" ; PUT THE BATTERY IN THE TESTS INDEX
42 . ; S TN=$NA(ZARY("TESTS"))
43 . ; D PUSH^GPLXPATH(TN,BAT)
44 S ZARY(0)=CNT ; update the array counter
45 Q
46 ;
47ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference
48 ; ZARY IS PASSED BY NAME
49 ; ZARY = name of the root, closed array format (e.g., "^TMP($J)")
50 ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE
51 K @ZARY
52 S @ZARY@(0)=0 ; initialize array count
53 N LINE,LABEL,BODY
54 N INTEST S INTEST=0 ; switch for in the test case section
55 N SECTION S SECTION="[anonymous]" ; test case section
56 ;
57 N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D
58 . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section
59 . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section
60 . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section
61 . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section
62 . I INTEST D ; within the testing section
63 . . I LINE?." "1";;><".E D ; section name found
64 . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name
65 . . I LINE?." "1";;>>".E D ; test case found
66 . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array
67 S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL
68 Q
69 ;
70ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST
71 N ZI,ZX,ZR,ZP
72 S DEBUG=0
73 ; I WHICH="ALL" D Q ; RUN ALL THE TESTS
74 ; . W "DOING ALL",!
75 ; . N J,NT
76 ; . S NT=$NA(ZARY("TESTS"))
77 ; . W NT,@NT@(0),!
78 ; . F J=1:1:@NT@(0) D ;
79 ; . . W @NT@(J),!
80 ; . . D ZTEST^GPLUNIT(@ZARY,@NT@(J))
81 I '$D(ZARY(WHICH)) D Q ; TEST SECTION DOESN'T EXIST
82 . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,!
83 N FIRST,LAST
84 S FIRST=$P(ZARY(WHICH),"^",1)
85 S LAST=$P(ZARY(WHICH),"^",2)
86 F ZI=FIRST:1:LAST D
87 . I ZARY(ZI)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT
88 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))
89 . . ; W ZP,!
90 . . S ZX=ZP
91 . . W "RUNNING: "_ZP
92 . . X ZX
93 . . W "..SUCCESS: ",WHICH,!
94 . I ZARY(ZI)?1"?"1.E D ; THIS IS A TEST
95 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))
96 . . S ZX="S ZR="_ZP
97 . . W "TRYING: "_ZP
98 . . X ZX
99 . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),!
100 . . I '$D(TPASSED) D ; NOT INITIALIZED YET
101 . . . S TPASSED=0 S TFAILED=0
102 . . I ZR S TPASSED=TPASSED+1
103 . . I 'ZR S TFAILED=TFAILED+1
104 Q
105 ;
106TEST ; RUN ALL THE TEST CASES
107 N ZTMP
108 D ZLOAD(.ZTMP)
109 D ZTEST(.ZTMP,"ALL")
110 W "PASSED: ",TPASSED,!
111 W "FAILED: ",TFAILED,!
112 W !
113 W "THE TESTS!",!
114 ; I DEBUG ZWR ZTMP
115 Q
116 ;
117GTSTS(GTZARY,RTN) ; return an array of test names
118 N I,J S I="" S I=$O(GTZARY("TESTS",I))
119 F J=0:0 Q:I="" D
120 . D PUSH^GPLXPATH(RTN,I)
121 . S I=$O(GTZARY("TESTS",I))
122 Q
123 ;
124TESTALL(RNM) ; RUN ALL THE TESTS
125 N ZI,J,TZTMP,TSTS,TOTP,TOTF
126 S TOTP=0 S TOTF=0
127 D ZLOAD^GPLUNIT("TZTMP",RNM)
128 D GTSTS(.TZTMP,"TSTS")
129 F ZI=1:1:TSTS(0) D ;
130 . S TPASSED=0 S TFAILED=0
131 . D ZTEST^GPLUNIT(.TZTMP,TSTS(ZI))
132 . S TOTP=TOTP+TPASSED
133 . S TOTF=TOTF+TFAILED
134 . S $P(TSTS(ZI),"^",2)=TPASSED
135 . S $P(TSTS(ZI),"^",3)=TFAILED
136 F ZI=1:1:TSTS(0) D ;
137 . W "TEST=> ",$P(TSTS(ZI),"^",1)
138 . W " PASSED=>",$P(TSTS(ZI),"^",2)
139 . W " FAILED=>",$P(TSTS(ZI),"^",3),!
140 W "TOTAL=> PASSED:",TOTP," FAILED:",TOTF,!
141 Q
142 ;
143TLIST(ZARY) ; LIST ALL THE TESTS
144 ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES
145 ; ZARY IS PASSED BY REFERENCE
146 N I,J,K S I="" S I=$O(ZARY("TESTS",I))
147 S K=1
148 F J=0:0 Q:I="" D
149 . ; W "I IS NOW=",I,!
150 . W I," "
151 . S I=$O(ZARY("TESTS",I))
152 . S K=K+1 I K=6 D
153 . . W !
154 . . S K=1
155 Q
156 ;
Note: See TracBrowser for help on using the repository browser.