Changeset 1586 for ccr/trunk/p/C0CUNIT.m
- Timestamp:
- Oct 30, 2012, 1:11:02 PM (13 years ago)
- File:
-
- 1 edited
-
ccr/trunk/p/C0CUNIT.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ccr/trunk/p/C0CUNIT.m
r1544 r1586 1 1 C0CUNIT ; CCDCCR/GPL - Unit Testing Library; 5/07/08 2 ;;1.2;C0C;;May 11, 2012;Build 47 3 ;Copyright 2008 George Lilly. Licensed under the terms of the GNU 4 ;General Public License See attached copy of the License. 2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50 3 ;Copyright 2008 George Lilly. 5 4 ; 6 ; This program is free software;you can redistribute it and/or modify7 ; it under the terms of the GNU General Public License as published by8 ; the Free Software Foundation; either version 2 of the License, or9 ; (at your option) any later version.5 ; This program is free software: you can redistribute it and/or modify 6 ; it under the terms of the GNU Affero General Public License as 7 ; published by the Free Software Foundation, either version 3 of the 8 ; License, or (at your option) any later version. 10 9 ; 11 ; This program is distributed in the hope that it will be useful,12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14 ; GNUGeneral Public License for more details.10 ; This program is distributed in the hope that it will be useful, 11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 ; GNU Affero General Public License for more details. 15 14 ; 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. 15 ; You should have received a copy of the GNU Affero General Public License 16 ; along with this program. If not, see <http://www.gnu.org/licenses/>. 19 17 ; 20 W "This is a unit testing library",!21 W !22 Q23 ;18 W "This is a unit testing library",! 19 W ! 20 Q 21 ; 24 22 ZT(ZARY,BAT,TST) ; private routine to add a test case to the ZARY array 25 ; ZARY IS PASSED BY REFERENCE26 ; BAT is a string identifying the test battery27 ; TST is a test which will evaluate to true or false28 ; I '$G(ZARY) D29 ; . S ZARY(0)=0 ; initially there are no elements30 ; W "GOT HERE LOADING "_TST,!31 N CNT ; count of array elements32 S CNT=ZARY(0) ; contains array count33 S CNT=CNT+1 ; increment count34 S ZARY(CNT)=TST ; put the test in the array35 I $D(ZARY(BAT)) D ; NOT THE FIRST TEST IN BATTERY36 . N II,TN ; TEMP FOR ENDING TEST IN BATTERY37 . S II=$P(ZARY(BAT),"^",2)38 . S $P(ZARY(BAT),"^",2)=II+139 I '$D(ZARY(BAT)) D ; FIRST TEST IN THIS BATTERY40 . S ZARY(BAT)=CNT_"^"_CNT ; FIRST AND LAST TESTS IN BATTERY41 . S ZARY("TESTS",BAT)="" ; PUT THE BATTERY IN THE TESTS INDEX42 . ; S TN=$NA(ZARY("TESTS"))43 . ; D PUSH^C0CXPATH(TN,BAT)44 S ZARY(0)=CNT ; update the array counter45 Q46 ;23 ; ZARY IS PASSED BY REFERENCE 24 ; BAT is a string identifying the test battery 25 ; TST is a test which will evaluate to true or false 26 ; I '$G(ZARY) D 27 ; . S ZARY(0)=0 ; initially there are no elements 28 ; W "GOT HERE LOADING "_TST,! 29 N CNT ; count of array elements 30 S CNT=ZARY(0) ; contains array count 31 S CNT=CNT+1 ; increment count 32 S ZARY(CNT)=TST ; put the test in the array 33 I $D(ZARY(BAT)) D ; NOT THE FIRST TEST IN BATTERY 34 . N II,TN ; TEMP FOR ENDING TEST IN BATTERY 35 . S II=$P(ZARY(BAT),"^",2) 36 . S $P(ZARY(BAT),"^",2)=II+1 37 I '$D(ZARY(BAT)) D ; FIRST TEST IN THIS BATTERY 38 . S ZARY(BAT)=CNT_"^"_CNT ; FIRST AND LAST TESTS IN BATTERY 39 . S ZARY("TESTS",BAT)="" ; PUT THE BATTERY IN THE TESTS INDEX 40 . ; S TN=$NA(ZARY("TESTS")) 41 . ; D PUSH^C0CXPATH(TN,BAT) 42 S ZARY(0)=CNT ; update the array counter 43 Q 44 ; 47 45 ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference 48 ; ZARY IS PASSED BY NAME49 ; ZARY = name of the root, closed array format (e.g., "^TMP($J)")50 ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE51 K @ZARY52 S @ZARY@(0)=0 ; initialize array count53 N LINE,LABEL,BODY54 N INTEST S INTEST=0 ; switch for in the test case section55 N SECTION S SECTION="[anonymous]" ; test case section56 ;57 N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D58 . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section59 . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section60 . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section61 . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section62 . I INTEST D ; within the testing section63 . . I LINE?." "1";;><".E D ; section name found64 . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name65 . . I LINE?." "1";;>>".E D ; test case found66 . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array67 S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL68 Q69 ;46 ; ZARY IS PASSED BY NAME 47 ; ZARY = name of the root, closed array format (e.g., "^TMP($J)") 48 ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE 49 K @ZARY 50 S @ZARY@(0)=0 ; initialize array count 51 N LINE,LABEL,BODY 52 N INTEST S INTEST=0 ; switch for in the test case section 53 N SECTION S SECTION="[anonymous]" ; test case section 54 ; 55 N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D 56 . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section 57 . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section 58 . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section 59 . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section 60 . I INTEST D ; within the testing section 61 . . I LINE?." "1";;><".E D ; section name found 62 . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name 63 . . I LINE?." "1";;>>".E D ; test case found 64 . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array 65 S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL 66 Q 67 ; 70 68 ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST 71 N ZI,ZX,ZR,ZP72 S DEBUG=073 ; I WHICH="ALL" D Q ; RUN ALL THE TESTS74 ; . W "DOING ALL",!75 ; . N J,NT76 ; . 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^C0CUNIT(@ZARY,@NT@(J))81 I '$D(ZARY(WHICH)) D Q; TEST SECTION DOESN'T EXIST82 . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,!83 N FIRST,LAST84 S FIRST=$P(ZARY(WHICH),"^",1)85 S LAST=$P(ZARY(WHICH),"^",2)86 F ZI=FIRST:1:LAST D87 . I ZARY(ZI)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT88 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))89 . . ; W ZP,!90 . . S ZX=ZP91 . . W "RUNNING: "_ZP92 . . X ZX93 . . W "..SUCCESS: ",WHICH,!94 . I ZARY(ZI)?1"?"1.E D ; THIS IS A TEST95 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))96 . . S ZX="S ZR="_ZP97 . . W "TRYING: "_ZP98 . . X ZX99 . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),!100 . . I '$D(TPASSED) D ; NOT INITIALIZED YET101 . . . S TPASSED=0 S TFAILED=0102 . . I ZR S TPASSED=TPASSED+1103 . . I 'ZR S TFAILED=TFAILED+1104 Q105 ;69 N ZI,ZX,ZR,ZP 70 S DEBUG=0 71 ; I WHICH="ALL" D Q ; RUN ALL THE TESTS 72 ; . W "DOING ALL",! 73 ; . N J,NT 74 ; . S NT=$NA(ZARY("TESTS")) 75 ; . W NT,@NT@(0),! 76 ; . F J=1:1:@NT@(0) D ; 77 ; . . W @NT@(J),! 78 ; . . D ZTEST^C0CUNIT(@ZARY,@NT@(J)) 79 I '$D(ZARY(WHICH)) D Q ; TEST SECTION DOESN'T EXIST 80 . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,! 81 N FIRST,LAST 82 S FIRST=$P(ZARY(WHICH),"^",1) 83 S LAST=$P(ZARY(WHICH),"^",2) 84 F ZI=FIRST:1:LAST D 85 . I ZARY(ZI)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT 86 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI))) 87 . . ; W ZP,! 88 . . S ZX=ZP 89 . . W "RUNNING: "_ZP 90 . . X ZX 91 . . W "..SUCCESS: ",WHICH,! 92 . I ZARY(ZI)?1"?"1.E D ; THIS IS A TEST 93 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI))) 94 . . S ZX="S ZR="_ZP 95 . . W "TRYING: "_ZP 96 . . X ZX 97 . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),! 98 . . I '$D(TPASSED) D ; NOT INITIALIZED YET 99 . . . S TPASSED=0 S TFAILED=0 100 . . I ZR S TPASSED=TPASSED+1 101 . . I 'ZR S TFAILED=TFAILED+1 102 Q 103 ; 106 104 TEST ; RUN ALL THE TEST CASES 107 N ZTMP108 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 ZTMP115 Q116 ;105 N ZTMP 106 D ZLOAD(.ZTMP) 107 D ZTEST(.ZTMP,"ALL") 108 W "PASSED: ",TPASSED,! 109 W "FAILED: ",TFAILED,! 110 W ! 111 W "THE TESTS!",! 112 ; I DEBUG ZWR ZTMP 113 Q 114 ; 117 115 GTSTS(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="" D120 . D PUSH^C0CXPATH(RTN,I)121 . S I=$O(GTZARY("TESTS",I))122 Q123 ;116 N I,J S I="" S I=$O(GTZARY("TESTS",I)) 117 F J=0:0 Q:I="" D 118 . D PUSH^C0CXPATH(RTN,I) 119 . S I=$O(GTZARY("TESTS",I)) 120 Q 121 ; 124 122 TESTALL(RNM) ; RUN ALL THE TESTS 125 N ZI,J,TZTMP,TSTS,TOTP,TOTF126 S TOTP=0 S TOTF=0127 D ZLOAD^C0CUNIT("TZTMP",RNM)128 D GTSTS(.TZTMP,"TSTS")129 F ZI=1:1:TSTS(0) D ;130 . S TPASSED=0 S TFAILED=0131 . D ZTEST^C0CUNIT(.TZTMP,TSTS(ZI))132 . S TOTP=TOTP+TPASSED133 . S TOTF=TOTF+TFAILED134 . S $P(TSTS(ZI),"^",2)=TPASSED135 . S $P(TSTS(ZI),"^",3)=TFAILED136 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 Q142 ;123 N ZI,J,TZTMP,TSTS,TOTP,TOTF 124 S TOTP=0 S TOTF=0 125 D ZLOAD^C0CUNIT("TZTMP",RNM) 126 D GTSTS(.TZTMP,"TSTS") 127 F ZI=1:1:TSTS(0) D ; 128 . S TPASSED=0 S TFAILED=0 129 . D ZTEST^C0CUNIT(.TZTMP,TSTS(ZI)) 130 . S TOTP=TOTP+TPASSED 131 . S TOTF=TOTF+TFAILED 132 . S $P(TSTS(ZI),"^",2)=TPASSED 133 . S $P(TSTS(ZI),"^",3)=TFAILED 134 F ZI=1:1:TSTS(0) D ; 135 . W "TEST=> ",$P(TSTS(ZI),"^",1) 136 . W " PASSED=>",$P(TSTS(ZI),"^",2) 137 . W " FAILED=>",$P(TSTS(ZI),"^",3),! 138 W "TOTAL=> PASSED:",TOTP," FAILED:",TOTF,! 139 Q 140 ; 143 141 TLIST(ZARY) ; LIST ALL THE TESTS 144 ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES145 ; ZARY IS PASSED BY REFERENCE146 N I,J,K S I="" S I=$O(ZARY("TESTS",I))147 S K=1148 F J=0:0 Q:I="" D149 . ; W "I IS NOW=",I,!150 . W I," "151 . S I=$O(ZARY("TESTS",I))152 . S K=K+1 I K=6 D153 . . W !154 . . S K=1155 Q156 ;157 MEDS 142 ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES 143 ; ZARY IS PASSED BY REFERENCE 144 N I,J,K S I="" S I=$O(ZARY("TESTS",I)) 145 S K=1 146 F J=0:0 Q:I="" D 147 . ; W "I IS NOW=",I,! 148 . W I," " 149 . S I=$O(ZARY("TESTS",I)) 150 . S K=K+1 I K=6 D 151 . . W ! 152 . . S K=1 153 Q 154 ; 155 MEDS ; 158 156 N DEBUG S DEBUG=0 159 157 N DFN S DFN=5685 … … 172 170 D FILEOUT^C0CRNF(OUTXML,"TESTMEDS.xml") 173 171 Q 174 PAT 172 PAT ; 175 173 D ANALYZE^ARJTXRD("C0CDPT",.OUT) ; Analyze a routine in the directory 176 174 N X,Y
Note:
See TracChangeset
for help on using the changeset viewer.
