1 | GPLUNIT ; 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 | ;
|
---|
7 | ZT(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 | ;
|
---|
30 | ZLOAD(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 | . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section
|
---|
42 | . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section
|
---|
43 | . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section
|
---|
44 | . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section
|
---|
45 | . I INTEST D ; within the testing section
|
---|
46 | . . I LINE?." "1";;><".E D ; section name found
|
---|
47 | . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name
|
---|
48 | . . I LINE?." "1";;>>".E D ; test case found
|
---|
49 | . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array
|
---|
50 | S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL
|
---|
51 | Q
|
---|
52 | ;
|
---|
53 | ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST
|
---|
54 | N I,ZX,ZR,ZP
|
---|
55 | S DEBUG=0
|
---|
56 | ; I WHICH="ALL" D Q ; RUN ALL THE TESTS
|
---|
57 | ; . W "DOING ALL",!
|
---|
58 | ; . N J,NT
|
---|
59 | ; . S NT=$NA(ZARY("TESTS"))
|
---|
60 | ; . W NT,@NT@(0),!
|
---|
61 | ; . F J=1:1:@NT@(0) D ;
|
---|
62 | ; . . W @NT@(J),!
|
---|
63 | ; . . D ZTEST^GPLUNIT(@ZARY,@NT@(J))
|
---|
64 | I '$D(ZARY(WHICH)) D ; TEST SECTION DOESN'T EXIST
|
---|
65 | . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,!
|
---|
66 | . Q ; EXIT
|
---|
67 | N FIRST,LAST
|
---|
68 | S FIRST=$P(ZARY(WHICH),"^",1)
|
---|
69 | S LAST=$P(ZARY(WHICH),"^",2)
|
---|
70 | F I=FIRST:1:LAST D
|
---|
71 | . I ZARY(I)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT
|
---|
72 | . . S ZP=$E(ZARY(I),2,$L(ZARY(I)))
|
---|
73 | . . ; W ZP,!
|
---|
74 | . . S ZX=ZP
|
---|
75 | . . W "RUNNING: "_ZP
|
---|
76 | . . X ZX
|
---|
77 | . . W "..SUCCESS: ",WHICH,!
|
---|
78 | . I ZARY(I)?1"?"1.E D ; THIS IS A TEST
|
---|
79 | . . S ZP=$E(ZARY(I),2,$L(ZARY(I)))
|
---|
80 | . . S ZX="S ZR="_ZP
|
---|
81 | . . W "TRYING: "_ZP
|
---|
82 | . . X ZX
|
---|
83 | . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),!
|
---|
84 | . . I '$D(TPASSED) D ; NOT INITIALIZED YET
|
---|
85 | . . . S TPASSED=0 S TFAILED=0
|
---|
86 | . . I ZR S TPASSED=TPASSED+1
|
---|
87 | . . I 'ZR S TFAILED=TFAILED+1
|
---|
88 | Q
|
---|
89 | ;
|
---|
90 | TEST ; RUN ALL THE TEST CASES
|
---|
91 | N ZTMP
|
---|
92 | D ZLOAD(.ZTMP)
|
---|
93 | D ZTEST(.ZTMP,"ALL")
|
---|
94 | W "PASSED: ",TPASSED,!
|
---|
95 | W "FAILED: ",TFAILED,!
|
---|
96 | W !
|
---|
97 | W "THE TESTS!",!
|
---|
98 | ZWR ZTMP
|
---|
99 | Q
|
---|
100 | ;
|
---|
101 | GTSTS(GTZARY,RTN) ; return an array of test names
|
---|
102 | N I,J S I="" S I=$O(GTZARY("TESTS",I))
|
---|
103 | F J=0:0 Q:I="" D
|
---|
104 | . D PUSH^GPLXPATH(RTN,I)
|
---|
105 | . S I=$O(GTZARY("TESTS",I))
|
---|
106 | Q
|
---|
107 | ;
|
---|
108 | TESTALL(RNM) ; RUN ALL THE TESTS
|
---|
109 | N I,J,TZTMP,TSTS,TOTP,TOTF
|
---|
110 | S TOTP=0 S TOTF=0
|
---|
111 | D ZLOAD^GPLUNIT("TZTMP",RNM)
|
---|
112 | D GTSTS(.TZTMP,"TSTS")
|
---|
113 | F I=1:1:TSTS(0) D ;
|
---|
114 | . S TPASSED=0 S TFAILED=0
|
---|
115 | . D ZTEST^GPLUNIT(.TZTMP,TSTS(I))
|
---|
116 | . S TOTP=TOTP+TPASSED
|
---|
117 | . S TOTF=TOTF+TFAILED
|
---|
118 | . S $P(TSTS(I),"^",2)=TPASSED
|
---|
119 | . S $P(TSTS(I),"^",3)=TFAILED
|
---|
120 | F I=1:1:TSTS(0) D ;
|
---|
121 | . W "TEST=> ",$P(TSTS(I),"^",1)
|
---|
122 | . W " PASSED=>",$P(TSTS(I),"^",2)
|
---|
123 | . W " FAILED=>",$P(TSTS(I),"^",3),!
|
---|
124 | W "TOTAL=> PASSED:",TOTP," FAILED:",TOTF,!
|
---|
125 | Q
|
---|
126 | ;
|
---|
127 | TLIST(ZARY) ; LIST ALL THE TESTS
|
---|
128 | ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES
|
---|
129 | ; ZARY IS PASSED BY REFERENCE
|
---|
130 | N I,J,K S I="" S I=$O(ZARY("TESTS",I))
|
---|
131 | S K=1
|
---|
132 | F J=0:0 Q:I="" D
|
---|
133 | . ; W "I IS NOW=",I,!
|
---|
134 | . W I," "
|
---|
135 | . S I=$O(ZARY("TESTS",I))
|
---|
136 | . S K=K+1 I K=6 D
|
---|
137 | . . W !
|
---|
138 | . . S K=1
|
---|
139 | Q
|
---|
140 | ;
|
---|