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

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

Inital release of GPL*.m files for creating a CCR from VistA. Usage EXPORTGPLCCR

File size: 3.8 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 ; 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 ZARY(0)=CNT ; update the array counter
26 Q
27 ;
28ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference
29 ; ZARY IS PASSED BY NAME
30 ; ZARY = name of the root, closed array format (e.g., "^TMP($J)")
31 ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE
32 K @ZARY
33 S @ZARY@(0)=0 ; initialize array count
34 N LINE,LABEL,BODY
35 N INTEST S INTEST=0 ; switch for in the test case section
36 N SECTION S SECTION="[anonymous]" ; test case section
37 ;
38 N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D
39 . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section
40 . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section
41 . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section
42 . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section
43 . I INTEST D ; within the testing section
44 . . I LINE?." "1";;><".E D ; section name found
45 . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name
46 . . I LINE?." "1";;>>".E D ; test case found
47 . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array
48 S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL
49 Q
50 ;
51ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST
52 N I,ZX,ZR,ZP
53 S DEBUG=0
54 I '$D(ZARY(WHICH)) D ; TEST SECTION DOESN'T EXIST
55 . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,!
56 . Q ; EXIT
57 N FIRST,LAST
58 S FIRST=$P(ZARY(WHICH),"^",1)
59 S LAST=$P(ZARY(WHICH),"^",2)
60 F I=FIRST:1:LAST D
61 . I ZARY(I)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT
62 . . S ZP=$E(ZARY(I),2,$L(ZARY(I)))
63 . . ; W ZP,!
64 . . S ZX=ZP
65 . . W "RUNNING: "_ZP
66 . . X ZX
67 . . W "..SUCCESS: ",WHICH,!
68 . I ZARY(I)?1"?"1.E D ; THIS IS A TEST
69 . . S ZP=$E(ZARY(I),2,$L(ZARY(I)))
70 . . S ZX="S ZR="_ZP
71 . . W "TRYING: "_ZP
72 . . X ZX
73 . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),!
74 . . I '$D(TPASSED) D ; NOT INITIALIZED YET
75 . . . S TPASSED=0 S TFAILED=0
76 . . I ZR S TPASSED=TPASSED+1
77 . . I 'ZR S TFAILED=TFAILED+1
78 Q
79 ;
80TEST ; RUN ALL THE TEST CASES
81 N ZTMP
82 D ZLOAD(.ZTMP)
83 D ZTEST(.ZTMP,"ALL")
84 W "PASSED: ",TPASSED,!
85 W "FAILED: ",TFAILED,!
86 W !
87 W "THE TESTS!",!
88 ZWR ZTMP
89 Q
90 ;
91TLIST(ZARY) ; LIST ALL THE TESTS
92 ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES
93 ; ZARY IS PASSED BY REFERENCE
94 N I,J,K S I="" S I=$O(ZARY("TESTS",I))
95 S K=1
96 F J=0:0 Q:I="" D
97 . ; W "I IS NOW=",I,!
98 . W I," "
99 . S I=$O(ZARY("TESTS",I))
100 . S K=K+1 I K=6 D
101 . . W !
102 . . S K=1
103 Q
104 ;
Note: See TracBrowser for help on using the repository browser.