Changeset 1586 for ccr/trunk/p/C0CUNIT.m
- Timestamp:
- Oct 30, 2012, 1:11:02 PM (12 years ago)
- File:
-
- 1 edited
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 21 22 23 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 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 72 73 74 75 76 77 78 79 80 81 I '$D(ZARY(WHICH)) D Q; TEST SECTION DOESN'T EXIST82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 108 109 110 111 112 113 114 115 116 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 119 120 121 122 123 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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 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 145 146 147 148 149 150 151 152 153 154 155 156 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.