Updates for M-Unit testing functionality

Changes to functionality include:

STARTUP and SHUTDOWN will be run in each routine instead of the first
instance of STARTUP and SHUTDOWN encountered being the only ones that
were run.  This change was made because of possible suites of tests
which have their own STARTUP and SHUTDOWN that need to be run.  Also, it
does not depend on the order in which test routines are run.

While the coverage functionality can only be run on GT.M systems at the
present time, the routine %utcover has been added to provide additional
ability to run a number of unit tests at one time so that coverage
across all of them can be obtained in one run, this includes
the ability to specify entry at different APIs (e.g., if both verbose
and nonverbose entries are available) as well as run code which is not
part of a unit test to include in the analysis.  The routine %uttcovr
uses this functionality to provide a means of doing coverage analysis on
the %ut routines and can be used as an example of its usage.

A new tag (COV) has been added to the %ut routine (it simply calls the
one in %ut1) so that all user APIs can be accessed within the %ut
routine.

A potential problem with setting up the %ut namespace in the local
instance was addressed by Sam Habiel in the preinstall routine ZZUTPRE.
This commit is contained in:
JOEL IVEY 2015-07-03 14:17:15 -07:00
parent b431e49cd7
commit 8fb0b7b4a1
14 changed files with 6190 additions and 4294 deletions

View File

@ -1,485 +1,487 @@
%ut ;VEN-SMH/JLI - PRIMARY PROGRAM FOR M-UNIT TESTING ;08/24/14 21:45 %ut ;VEN-SMH/JLI - PRIMARY PROGRAM FOR M-UNIT TESTING ;08/29/14 09:31
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
; ;
; This routine and its companion, %ut1, provide the basic functionality for ; This routine and its companion, %ut1, provide the basic functionality for
; running unit tests on parts of M programs either at the command line level ; running unit tests on parts of M programs either at the command line level
; or via the M-Unit GUI application for windows operating systems. ; or via the M-Unit GUI application for windows operating systems.
; ;
; Original by Dr. Joel Ivey ; Original by Dr. Joel Ivey
; Contributions by Dr. Sam Habiel ; Contributions by Dr. Sam Habiel
; ;
; 100622 JLI - corrected typo in comments where %utINPT was listed as %utINP ; 100622 JLI - corrected typo in comments where %utINPT was listed as %utINP
; 100622 JLI - removed a comment which indicated data could potentially be returned from the called routine ; 100622 JLI - removed a comment which indicated data could potentially be returned from the called routine
; in the %utINPT array. ; in the %utINPT array.
; 100622 JLI - added code to handle STARTUP and SHUTDOWN from GUI app ; 100622 JLI - added code to handle STARTUP and SHUTDOWN from GUI app
; 110719 JLI - modified separators in GUI handling from ^ to ~~^~~ ; 110719 JLI - modified separators in GUI handling from ^ to ~~^~~
; in the variable XTGUISEP if using a newer version of the ; in the variable XTGUISEP if using a newer version of the
; GUI app (otherwise, it is simply set to ^) since results ; GUI app (otherwise, it is simply set to ^) since results
; with a series of ^ embedded disturbed the output reported ; with a series of ^ embedded disturbed the output reported
; 130726 SMH - Fixed SETUP and TEARDOWN so that they run before/after each ; 130726 SMH - Fixed SETUP and TEARDOWN so that they run before/after each
; test rather than once. General refactoring. ; test rather than once. General refactoring.
; 130726 SMH - SETUT initialized IO in case it's not there to $P. Inits vars ; 130726 SMH - SETUT initialized IO in case it's not there to $P. Inits vars
; using DT^DICRW. ; using DT^DICRW.
; 131217 SMH - Change call in SETUP to S U="^" instead of DT^DICRW ; 131217 SMH - Change call in SETUP to S U="^" instead of DT^DICRW
; 131218 SMH - Any checks to $ZE will also check $ZS for GT.M. ; 131218 SMH - Any checks to $ZE will also check $ZS for GT.M.
; 131218 SMH - Remove calls to %ZISUTL to manage devices to prevent dependence on VISTA. ; 131218 SMH - Remove calls to %ZISUTL to manage devices to prevent dependence on VISTA.
; Use %utNIT("DEV","OLD") for old devices ; Use %utNIT("DEV","OLD") for old devices
; 140109 SMH - Add parameter %utBREAK - Break upon error ; 140109 SMH - Add parameter %utBREAK - Break upon error
; 1402 SMH - Break will cause the break to happen even on failed tests. ; 1402 SMH - Break will cause the break to happen even on failed tests.
; 140401 SMH - Added Succeed entry point for take it into your hands tester. ; 140401 SMH - Added Succeed entry point for take it into your hands tester.
; 140401 SMH - Reformatted the output of M-Unit so that the test's name ; 140401 SMH - Reformatted the output of M-Unit so that the test's name
; will print BEFORE the execution of the test. This has been ; will print BEFORE the execution of the test. This has been
; really confusing for beginning users of M-Unit, so this was ; really confusing for beginning users of M-Unit, so this was
; necessary. ; necessary.
; 140401 SMH - OK message gets printed at the end of --- as [OK]. ; 140401 SMH - OK message gets printed at the end of --- as [OK].
; 140401 SMH - FAIL message now prints. Previously, OK failed to be printed. ; 140401 SMH - FAIL message now prints. Previously, OK failed to be printed.
; Unfortunately, that's rather passive aggressive. Now it ; Unfortunately, that's rather passive aggressive. Now it
; explicitly says that a test failed. ; explicitly says that a test failed.
; 140503 SMH - Fixed IO issues all over the routine. Much simpler now. ; 140503 SMH - Fixed IO issues all over the routine. Much simpler now.
; 140731 JLI - Combined routine changes between JLI and SMH ; 140731 JLI - Combined routine changes between JLI and SMH
; Moved routines from %utNIT and %utNIT1 to %ut and %ut1 ; Moved routines from %utNIT and %utNIT1 to %ut and %ut1
; Updated unit test routines (%utt1 to %utt6) ; Updated unit test routines (%utt1 to %utt6)
; Created M-UNIT TEST GROUP file at 17.9001 based on the 17.9001 file ; Created M-UNIT TEST GROUP file at 17.9001 based on the 17.9001 file
Q Q
; ;
EN(%utRNAM,%utVERB,%utBREAK) ; .SR Entry point with primary test routine name, optional 1 for verbose output EN(%utRNAM,%utVERB,%utBREAK) ; .SR Entry point with primary test routine name, optional 1 for verbose output
N %utLIST,%utROU,%ut N %utLIST,%utROU,%ut
I '+$G(%utVERB) S %utVERB=0 I '+$G(%utVERB) S %utVERB=0
S %utLIST=1,%utROU(%utLIST)=%utRNAM S %utLIST=1,%utROU(%utLIST)=%utRNAM
D SETUT D SETUT
D EN1(.%utROU,%utLIST) D EN1(.%utROU,%utLIST)
Q Q
; ;
SETUT ; SETUT ;
; VEN/SMH 26JUL2013 ; VEN/SMH 26JUL2013
I '($D(IO)#2) S IO=$P I '($D(IO)#2) S IO=$P
S U="^" S U="^"
; VEN/SMH 26JUL2013 END ; VEN/SMH 26JUL2013 END
; ;
; ZEXCEPT: %ut -- NEWED ON ENTRY ; ZEXCEPT: %ut -- NEWED ON ENTRY
S %ut("IO")=IO S %ut("IO")=IO
S %ut=1 ; set to identify unit test being run check with $$ISUTEST^%ut() S %ut=1 ; set to identify unit test being run check with $$ISUTEST^%ut()
; ;
; ZEXCEPT: %utBREAK ; ZEXCEPT: %utBREAK
I $G(%utBREAK) S %ut("BREAK")=1 I $G(%utBREAK) S %ut("BREAK")=1
Q Q
; ;
EN1(%utROU,%utLIST) ; EN1(%utROU,%utLIST) ;
; VEN/SMH 26JUL2013 - This block is refactored to fix problems with ; VEN/SMH 26JUL2013 - This block is refactored to fix problems with
; SETUP and TEARDOWN not happening at the right time ; SETUP and TEARDOWN not happening at the right time
N %utERRL,%utK,%utI,%utJ,%utSTRT N %utERRL,%utK,%utI,%utJ,%utSTRT
; ZEXCEPT: %utVERB -- ARGUMENT TO EN ; ZEXCEPT: %utVERB -- ARGUMENT TO EN
; ZEXCEPT: %utGUI -- CONDITIONALLY DEFINED BY GUINEXT ; ZEXCEPT: %utGUI -- CONDITIONALLY DEFINED BY GUINEXT
; ZEXCEPT: %ut -- NEWED IN EN ; ZEXCEPT: %ut -- NEWED IN EN
; ;
; Structure map for %ut ; Structure map for %ut
; -- CURR = Counter for routine number. Used as sub in %utROU ; -- CURR = Counter for routine number. Used as sub in %utROU
; -- ECNT = Entry point count in loop (cf. NERT); VEN/SMH - Needed? ; -- ECNT = Entry point count in loop (cf. NERT); VEN/SMH - Needed?
; -- FAIL = Number of failures ; -- FAIL = Number of failures
; -- CHK = Number of checks ran (TF/EQ/FAIL) ; -- CHK = Number of checks ran (TF/EQ/FAIL)
; -- NENT = Number of entry points ran ; -- NENT = Number of entry points ran
; -- ERRN = Number of errors ; -- ERRN = Number of errors
S %ut("CURR")=0,%ut("ECNT")=0,%ut("FAIL")=0,%ut("CHK")=0,%ut("NENT")=0,%ut("ERRN")=0 S %ut("CURR")=0,%ut("ECNT")=0,%ut("FAIL")=0,%ut("CHK")=0,%ut("NENT")=0,%ut("ERRN")=0
; ;
; -- GET LIST OF ROUTINES -- ; -- GET LIST OF ROUTINES --
; first get any tree of routines from this one ; first get any tree of routines from this one
D GETTREE^%ut1(.%utROU,.%utLIST) D GETTREE^%ut1(.%utROU,.%utLIST)
; ;
; -- STARTUP -- ; -- STARTUP --
; 070224 - following code added to allow one overall STARTUP code JLI ; 070224 - following code added to allow one overall STARTUP code JLI
F S %ut("CURR")=%ut("CURR")+1 Q:'$D(%utROU(%ut("CURR"))) D I $G(%utSTRT)'="" D @%utSTRT Q F S %ut("CURR")=%ut("CURR")+1 Q:'$D(%utROU(%ut("CURR"))) D I $G(%utSTRT)'="" D @%utSTRT Q
. I $T(@("STARTUP^"_%utROU(%ut("CURR"))))'="" S %utSTRT="STARTUP^"_%utROU(%ut("CURR")) . I $T(@("STARTUP^"_%utROU(%ut("CURR"))))'="" S %utSTRT="STARTUP^"_%utROU(%ut("CURR"))
. Q . Q
; 070224 - end of addition JLI ; 070224 - end of addition JLI
; ;
; ;
; Now process each routine that has been referenced ; Now process each routine that has been referenced
S %ut("CURR")=0 S %ut("CURR")=0
F S %ut("CURR")=%ut("CURR")+1 Q:'$D(%utROU(%ut("CURR"))) D F S %ut("CURR")=%ut("CURR")+1 Q:'$D(%utROU(%ut("CURR"))) D
. N %utETRY ; Test list to run . N %utETRY ; Test list to run
. ; . ;
. ; Collect Test list. . ; Collect Test list.
. D CHEKTEST^%ut1(%utROU(%ut("CURR")),.%ut,.%utETRY) . D CHEKTEST^%ut1(%utROU(%ut("CURR")),.%ut,.%utETRY)
. ; . ;
. ; if a SETUP entry point exists, save it off in %ut . ; if a SETUP entry point exists, save it off in %ut
. N %utSETUP S %utSETUP="SETUP^"_%utROU(%ut("CURR")) . N %utSETUP S %utSETUP="SETUP^"_%utROU(%ut("CURR"))
. S %ut("LINE")=$T(@%utSETUP) I %ut("LINE")'="" S %ut("SETUP")=%utSETUP . S %ut("LINE")=$T(@%utSETUP) I %ut("LINE")'="" S %ut("SETUP")=%utSETUP
. K %utSETUP ; we're done! . K %utSETUP ; we're done!
. ; . ;
. ; if a TEARDOWN entry point exists, ditto . ; if a TEARDOWN entry point exists, ditto
. N %utTEARDOWN S %utTEARDOWN="TEARDOWN^"_%utROU(%ut("CURR")) . N %utTEARDOWN S %utTEARDOWN="TEARDOWN^"_%utROU(%ut("CURR"))
. S %ut("LINE")=$T(@%utTEARDOWN) I %ut("LINE")'="" S %ut("TEARDOWN")=%utTEARDOWN . S %ut("LINE")=$T(@%utTEARDOWN) I %ut("LINE")'="" S %ut("TEARDOWN")=%utTEARDOWN
. K %utTEARDOWN ; done here. . K %utTEARDOWN ; done here.
. ; . ;
. ; VEN/SMH 26JUL2013 - this block changed to correct running of setup and teardown . ; VEN/SMH 26JUL2013 - this block changed to correct running of setup and teardown
. ; run each of the specified entry points . ; run each of the specified entry points
. ; . ;
. ; == THIS FOR/DO BLOCK IS THE CENTRAL TEST RUNNER == . ; == THIS FOR/DO BLOCK IS THE CENTRAL TEST RUNNER ==
. S %utI=0 . S %utI=0
. F S %utI=$O(%utETRY(%utI)) Q:%utI'>0 S %ut("ENUM")=%ut("ERRN")+%ut("FAIL") D . F S %utI=$O(%utETRY(%utI)) Q:%utI'>0 S %ut("ENUM")=%ut("ERRN")+%ut("FAIL") D
. . N $ETRAP S $ETRAP="D ERROR^%ut" . . N $ETRAP S $ETRAP="D ERROR^%ut"
. . ; . . ;
. . ; Run Set-up Code (only if present) . . ; Run Set-up Code (only if present)
. . S %ut("ENT")=$G(%ut("SETUP")) ; Current entry . . S %ut("ENT")=$G(%ut("SETUP")) ; Current entry
. . S %ut("NAME")="Set-up Code" . . S %ut("NAME")="Set-up Code"
. . D:%ut("ENT")]"" @%ut("ENT") . . D:%ut("ENT")]"" @%ut("ENT")
. . ; . . ;
. . ; Run actual test . . ; Run actual test
. . S %ut("ECNT")=%ut("ECNT")+1 . . S %ut("ECNT")=%ut("ECNT")+1
. . S %ut("NAME")=%utETRY(%utI,"NAME") . . S %ut("NAME")=%utETRY(%utI,"NAME")
. . S %ut("ENT")=%utETRY(%utI)_"^"_%utROU(%ut("CURR")) . . S %ut("ENT")=%utETRY(%utI)_"^"_%utROU(%ut("CURR"))
. . I %utVERB,'$D(%utGUI) D VERBOSE1(.%utETRY,%utI) ; Say what we executed. . . I %utVERB,'$D(%utGUI) D VERBOSE1(.%utETRY,%utI) ; Say what we executed.
. . D @%ut("ENT") . . D @%ut("ENT")
. . ; . . ;
. . ; Run Teardown Code (only if present) . . ; Run Teardown Code (only if present)
. . S %ut("ENT")=$G(%ut("TEARDOWN")) . . S %ut("ENT")=$G(%ut("TEARDOWN"))
. . S %ut("NAME")="Teardown Code" . . S %ut("NAME")="Teardown Code"
. . D:%ut("ENT")]"" @%ut("ENT") . . D:%ut("ENT")]"" @%ut("ENT")
. . ; . . ;
. . ; ENUM = Number of errors + failures . . ; ENUM = Number of errors + failures
. . ; Only print out the success message [OK] If our error number remains . . ; Only print out the success message [OK] If our error number remains
. . ; the same as when we started the loop. . . ; the same as when we started the loop.
. . I %utVERB,'$D(%utGUI) D . . I %utVERB,'$D(%utGUI) D
. . . I %ut("ENUM")=(%ut("ERRN")+%ut("FAIL")) D VERBOSE(.%utETRY,%utI,1) I 1 . . . I %ut("ENUM")=(%ut("ERRN")+%ut("FAIL")) D VERBOSE(.%utETRY,%utI,1) I 1
. . . E D VERBOSE(.%utETRY,%utI,0) . . . E D VERBOSE(.%utETRY,%utI,0)
. ; . ;
. ; . ;
. ; keep a %utCNT of number of entry points executed across all routines . ; keep a %utCNT of number of entry points executed across all routines
. S %ut("NENT")=%ut("NENT")+%ut("ENTN") . S %ut("NENT")=%ut("NENT")+%ut("ENTN")
. Q . Q
; ;
; -- SHUTDOWN -- ; -- SHUTDOWN --
; 070224 - following code added to allow one overall SHUTDOWN code JLI ; 070224 - following code added to allow one overall SHUTDOWN code JLI
N XTFINISH N XTFINISH
S %ut("CURR")=0 S %ut("CURR")=0
F S %ut("CURR")=%ut("CURR")+1 Q:'$D(%utROU(%ut("CURR"))) D I $G(XTFINISH)'="" D @XTFINISH Q F S %ut("CURR")=%ut("CURR")+1 Q:'$D(%utROU(%ut("CURR"))) D I $G(XTFINISH)'="" D @XTFINISH Q
. I $T(@("SHUTDOWN^"_%utROU(%ut("CURR"))))'="" S XTFINISH="SHUTDOWN^"_%utROU(%ut("CURR")) . I $T(@("SHUTDOWN^"_%utROU(%ut("CURR"))))'="" S XTFINISH="SHUTDOWN^"_%utROU(%ut("CURR"))
. Q . Q
; 070224 - End of addition JLI ; 070224 - End of addition JLI
; and output the results ; and output the results
D SETIO D SETIO
W !!,"Ran ",%utLIST," Routine",$S(%utLIST>1:"s",1:""),", ",%ut("NENT")," Entry Tag",$S(%ut("NENT")>1:"s",1:"") W !!,"Ran ",%utLIST," Routine",$S(%utLIST>1:"s",1:""),", ",%ut("NENT")," Entry Tag",$S(%ut("NENT")>1:"s",1:"")
W !,"Checked ",%ut("CHK")," test",$S(%ut("CHK")>1:"s",1:""),", with ",%ut("FAIL")," failure",$S(%ut("FAIL")'=1:"s",1:"")," and encountered ",%ut("ERRN")," error",$S(%ut("ERRN")'=1:"s",1:""),"." W !,"Checked ",%ut("CHK")," test",$S(%ut("CHK")>1:"s",1:""),", with ",%ut("FAIL")," failure",$S(%ut("FAIL")'=1:"s",1:"")," and encountered ",%ut("ERRN")," error",$S(%ut("ERRN")'=1:"s",1:""),"."
D RESETIO D RESETIO
Q Q
; -- end EN1 ; -- end EN1
VERBOSE(%utETRY,%utI,SUCCESS) ; Say whether we succeeded or failed. VERBOSE(%utETRY,%utI,SUCCESS) ; Say whether we succeeded or failed.
; ZEXCEPT: %ut - NEWED IN EN ; ZEXCEPT: %ut - NEWED IN EN
D SETIO D SETIO
N I F I=$X+3:1:73 W "-" N I F I=$X+3:1:73 W "-"
W ?73 W ?73
I $G(SUCCESS) W "[OK]" I $G(SUCCESS) W "[OK]"
E W "[FAIL]" E W "[FAIL]"
D RESETIO D RESETIO
Q Q
; ;
VERBOSE1(%utETRY,%utI) ; Print out the entry point info VERBOSE1(%utETRY,%utI) ; Print out the entry point info
; ZEXCEPT: %ut - NEWED IN EN ; ZEXCEPT: %ut - NEWED IN EN
D SETIO D SETIO
W !,%utETRY(%utI) I $G(%utETRY(%utI,"NAME"))'="" W " - ",%utETRY(%utI,"NAME") W !,%utETRY(%utI) I $G(%utETRY(%utI,"NAME"))'="" W " - ",%utETRY(%utI,"NAME")
D RESETIO D RESETIO
Q Q
CHKTF(XTSTVAL,XTERMSG) ; Entry point for checking True or False values CHKTF(XTSTVAL,XTERMSG) ; Entry point for checking True or False values
; ZEXCEPT: %utERRL,%utGUI - CREATED IN SETUP, KILLED IN END ; ZEXCEPT: %utERRL,%utGUI - CREATED IN SETUP, KILLED IN END
; ZEXCEPT: %ut - NEWED IN EN ; ZEXCEPT: %ut - NEWED IN EN
; ZEXCEPT: XTGUISEP - newed in GUINEXT ; ZEXCEPT: XTGUISEP - newed in GUINEXT
I '$D(XTSTVAL) D NVLDARG Q I '$D(XTSTVAL) D NVLDARG Q
I $G(XTERMSG)="" S XTERMSG="no failure message provided" I $G(XTERMSG)="" S XTERMSG="no failure message provided"
S %ut("CHK")=$G(%ut("CHK"))+1 S %ut("CHK")=$G(%ut("CHK"))+1
I '$D(%utGUI) D I '$D(%utGUI) D
. D SETIO . D SETIO
. I 'XTSTVAL W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - " D . I 'XTSTVAL W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - " D
. . W XTERMSG,! S %ut("FAIL")=%ut("FAIL")+1,%utERRL(%ut("FAIL"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=XTERMSG,%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT") . . W XTERMSG,! S %ut("FAIL")=%ut("FAIL")+1,%utERRL(%ut("FAIL"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=XTERMSG,%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT")
. . I $D(%ut("BREAK")) BREAK ; Break upon failure . . I $D(%ut("BREAK")) BREAK ; Break upon failure
. . Q . . Q
. I XTSTVAL W "." . I XTSTVAL W "."
. D RESETIO . D RESETIO
. Q . Q
I $D(%utGUI),'XTSTVAL S %ut("CNT")=%ut("CNT")+1,@%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"FAILURE"_XTGUISEP_XTERMSG I $D(%utGUI),'XTSTVAL S %ut("CNT")=%ut("CNT")+1,@%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"FAILURE"_XTGUISEP_XTERMSG,%ut("FAIL")=%ut("FAIL")+1
Q Q
; ;
CHKEQ(XTEXPECT,XTACTUAL,XTERMSG) ; Entry point for checking values to see if they are EQUAL CHKEQ(XTEXPECT,XTACTUAL,XTERMSG) ; Entry point for checking values to see if they are EQUAL
N FAILMSG N FAILMSG
; ZEXCEPT: %utERRL,%utGUI -CREATED IN SETUP, KILLED IN END ; ZEXCEPT: %utERRL,%utGUI -CREATED IN SETUP, KILLED IN END
; ZEXCEPT: %ut -- NEWED IN EN ; ZEXCEPT: %ut -- NEWED IN EN
; ZEXCEPT: XTGUISEP - newed in GUINEXT ; ZEXCEPT: XTGUISEP - newed in GUINEXT
I '$D(XTEXPECT)!'$D(XTACTUAL) D NVLDARG Q ; JLI 140824 changed from AND to OR, since both necessary, but only one might be entered I '$D(XTEXPECT)!'$D(XTACTUAL) D NVLDARG Q ; JLI 140824 changed from AND to OR, since both necessary, but only one might be entered
S XTACTUAL=$G(XTACTUAL),XTEXPECT=$G(XTEXPECT) S XTACTUAL=$G(XTACTUAL),XTEXPECT=$G(XTEXPECT)
I $G(XTERMSG)="" S XTERMSG="no failure message provided" I $G(XTERMSG)="" S XTERMSG="no failure message provided"
S %ut("CHK")=%ut("CHK")+1 S %ut("CHK")=%ut("CHK")+1
I XTEXPECT'=XTACTUAL S FAILMSG="<"_XTEXPECT_"> vs <"_XTACTUAL_"> - " I XTEXPECT'=XTACTUAL S FAILMSG="<"_XTEXPECT_"> vs <"_XTACTUAL_"> - "
I '$D(%utGUI) D I '$D(%utGUI) D
. D SETIO . D SETIO
. I XTEXPECT'=XTACTUAL W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - " W FAILMSG,XTERMSG,! D . I XTEXPECT'=XTACTUAL W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - " W FAILMSG,XTERMSG,! D
. . S %ut("FAIL")=%ut("FAIL")+1,%utERRL(%ut("FAIL"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=XTERMSG,%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT") . . S %ut("FAIL")=%ut("FAIL")+1,%utERRL(%ut("FAIL"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=XTERMSG,%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT")
. . I $D(%ut("BREAK")) BREAK ; Break upon failure . . I $D(%ut("BREAK")) BREAK ; Break upon failure
. . Q . . Q
. E W "." . E W "."
. D RESETIO . D RESETIO
. Q . Q
I $D(%utGUI),XTEXPECT'=XTACTUAL S %ut("CNT")=%ut("CNT")+1,@%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"FAILURE"_XTGUISEP_FAILMSG_XTERMSG I $D(%utGUI),XTEXPECT'=XTACTUAL S %ut("CNT")=%ut("CNT")+1,@%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"FAILURE"_XTGUISEP_FAILMSG_XTERMSG,%ut("FAIL")=%ut("FAIL")+1
Q Q
; ;
FAIL(XTERMSG) ; Entry point for generating a failure message FAIL(XTERMSG) ; Entry point for generating a failure message
; ZEXCEPT: %utERRL,%utGUI -CREATED IN SETUP, KILLED IN END ; ZEXCEPT: %utERRL,%utGUI -CREATED IN SETUP, KILLED IN END
; ZEXCEPT: %ut -- NEWED ON ENTRY ; ZEXCEPT: %ut -- NEWED ON ENTRY
; ZEXCEPT: XTGUISEP - newed in GUINEXT ; ZEXCEPT: XTGUISEP - newed in GUINEXT
I $G(XTERMSG)="" S XTERMSG="no failure message provided" I $G(XTERMSG)="" S XTERMSG="no failure message provided"
S %ut("CHK")=%ut("CHK")+1 S %ut("CHK")=%ut("CHK")+1
I '$D(%utGUI) D I '$D(%utGUI) D
. D SETIO . D SETIO
. W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - " W XTERMSG,! D . W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - " W XTERMSG,! D
. . S %ut("FAIL")=%ut("FAIL")+1,%utERRL(%ut("FAIL"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=XTERMSG,%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT") . . S %ut("FAIL")=%ut("FAIL")+1,%utERRL(%ut("FAIL"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=XTERMSG,%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT")
. . I $D(%ut("BREAK")) BREAK ; Break upon failure . . I $D(%ut("BREAK")) BREAK ; Break upon failure
. . Q . . Q
. D RESETIO . D RESETIO
. Q . Q
I $D(%utGUI) S %ut("CNT")=%ut("CNT")+1,@%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"FAILURE"_XTGUISEP_XTERMSG I $D(%utGUI) S %ut("CNT")=%ut("CNT")+1,@%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"FAILURE"_XTGUISEP_XTERMSG,%ut("FAIL")=%ut("FAIL")+1
Q Q
SUCCEED ; Entry point for forcing a success (Thx David Whitten) SUCCEED ; Entry point for forcing a success (Thx David Whitten)
; ZEXCEPT: %utERRL,%utGUI - CREATED IN SETUP, KILLED IN END ; ZEXCEPT: %utERRL,%utGUI - CREATED IN SETUP, KILLED IN END
; ZEXCEPT: %ut - NEWED IN EN ; ZEXCEPT: %ut - NEWED IN EN
; Switch IO and write out the dot for activity ; Switch IO and write out the dot for activity
I '$D(%utGUI) D I '$D(%utGUI) D
. D SETIO . D SETIO
. W "." . W "."
. D RESETIO . D RESETIO
; ;
; Increment test counter ; Increment test counter
S %ut("CHK")=%ut("CHK")+1 S %ut("CHK")=%ut("CHK")+1
QUIT QUIT
; ;
CHKLEAKS(%utCODE,%utLOC,%utINPT) ; functionality to check for variable leaks on executing a section of code CHKLEAKS(%utCODE,%utLOC,%utINPT) ; functionality to check for variable leaks on executing a section of code
; %utCODE - A string that specifies the code that is to be XECUTED and checked for leaks. ; %utCODE - A string that specifies the code that is to be XECUTED and checked for leaks.
; this should be a complete piece of code (e.g., "S X=$$NOW^XLFDT()" or "D EN^%ut(""ROUNAME"")") ; this should be a complete piece of code (e.g., "S X=$$NOW^XLFDT()" or "D EN^%ut(""ROUNAME"")")
; %utLOC - A string that is used to indicate the code tested for variable leaks ; %utLOC - A string that is used to indicate the code tested for variable leaks
; %utINPT - An optional variable which may be passed by reference. This may ; %utINPT - An optional variable which may be passed by reference. This may
; be used to pass any variable values, etc. into the code to be ; be used to pass any variable values, etc. into the code to be
; XECUTED. In this case, set the subscript to the variable name and the ; XECUTED. In this case, set the subscript to the variable name and the
; value of the subscripted variable to the desired value of the subscript. ; value of the subscripted variable to the desired value of the subscript.
; e.g., (using NAME as my current namespace) ; e.g., (using NAME as my current namespace)
; S CODE="S %utINPT=$$ENTRY^ROUTINE(ZZVALUE1,ZZVALUE2)" ; S CODE="S %utINPT=$$ENTRY^ROUTINE(ZZVALUE1,ZZVALUE2)"
; S NAMELOC="ENTRY^ROUTINE leak test" (or simply "ENTRY^ROUTINE") ; S NAMELOC="ENTRY^ROUTINE leak test" (or simply "ENTRY^ROUTINE")
; S NAMEINPT("ZZVALUE1")=ZZVALUE1 ; S NAMEINPT("ZZVALUE1")=ZZVALUE1
; S NAMEINPT("ZZVALUE2")=ZZVALUE2 ; S NAMEINPT("ZZVALUE2")=ZZVALUE2
; D CHKLEAKS^%ut(CODE,NAMELOC,.NAMEINPT) ; D CHKLEAKS^%ut(CODE,NAMELOC,.NAMEINPT)
; ;
; If part of a unit test, any leaked variables in ENTRY^ROUTINE which result ; If part of a unit test, any leaked variables in ENTRY^ROUTINE which result
; from running the code with the variables indicated will be shown as FAILUREs. ; from running the code with the variables indicated will be shown as FAILUREs.
; ;
; If called outside of a unit test, any leaked variables will be printed to the ; If called outside of a unit test, any leaked variables will be printed to the
; current device. ; current device.
; ;
N (%utCODE,%utLOC,%utINPT,DUZ,IO,U,%utERRL,%ut,%utGUI,%utI,%utJ,%utK,%utLIST,%utROU,%utSTRT) N (%utCODE,%utLOC,%utINPT,DUZ,IO,U,%utERRL,%ut,%utGUI,%utERR,%utI,%utJ,%utK,%utLIST,%utROU,%utSTRT,XTGUISEP)
; ZEXCEPT: %ut - part of exclusive NEW TESTS FOR EXISTENCE ONLY ; ZEXCEPT: %ut - part of exclusive NEW TESTS FOR EXISTENCE ONLY
; ZEXCEPT: %utVAR - handled by exclusive NEW ; ZEXCEPT: %utVAR - handled by exclusive NEW
; ;
; ACTIVATE ANY VARIABLES PASSED AS SUBSCRIPTS TO %utINPT TO THEIR VALUES ; ACTIVATE ANY VARIABLES PASSED AS SUBSCRIPTS TO %utINPT TO THEIR VALUES
S %utVAR=" " F S %utVAR=$O(%utINPT(%utVAR)) Q:%utVAR="" S (@%utVAR)=%utINPT(%utVAR) S %utVAR=" " F S %utVAR=$O(%utINPT(%utVAR)) Q:%utVAR="" S (@%utVAR)=%utINPT(%utVAR)
X %utCODE X %utCODE
N ZZUTVAR S ZZUTVAR="%" N ZZUTVAR S ZZUTVAR="%"
I $G(%ut)=1 D I $G(%ut)=1 D
. I $D(@ZZUTVAR),'$D(%utINPT(ZZUTVAR)) D FAIL^%ut(%utLOC_" VARIABLE LEAK: "_ZZUTVAR) . I $D(@ZZUTVAR),'$D(%utINPT(ZZUTVAR)) D FAIL^%ut(%utLOC_" VARIABLE LEAK: "_ZZUTVAR)
. F S ZZUTVAR=$O(@ZZUTVAR) Q:ZZUTVAR="" I $E(ZZUTVAR,1,3)'="%ut",'$D(%utINPT(ZZUTVAR)),",DUZ,IO,U,DTIME,ZZUTVAR,DT,%ut,"'[(","_ZZUTVAR_",") D FAIL^%ut(%utLOC_" VARIABLE LEAK: "_ZZUTVAR) . F S ZZUTVAR=$O(@ZZUTVAR) Q:ZZUTVAR="" I $E(ZZUTVAR,1,3)'="%ut",'$D(%utINPT(ZZUTVAR)),",DUZ,IO,U,DTIME,ZZUTVAR,DT,%ut,XTGUISEP,"'[(","_ZZUTVAR_",") D FAIL^%ut(%utLOC_" VARIABLE LEAK: "_ZZUTVAR)
. Q . Q
I '($G(%ut)=1) D I '($G(%ut)=1) D
. I $D(@ZZUTVAR),'$D(%utINPT(ZZUTVAR)) W !,%utLOC_" VARIABLE LEAK: "_ZZUTVAR . I $D(@ZZUTVAR),'$D(%utINPT(ZZUTVAR)) W !,%utLOC_" VARIABLE LEAK: "_ZZUTVAR
. F S ZZUTVAR=$O(@ZZUTVAR) Q:ZZUTVAR="" I $E(ZZUTVAR,1,3)'="%ut",'$D(%utINPT(ZZUTVAR)),",DUZ,IO,U,DTIME,ZZUTVAR,DT,%ut,"'[(","_ZZUTVAR_",") W !,%utLOC_" VARIABLE LEAK: "_ZZUTVAR . F S ZZUTVAR=$O(@ZZUTVAR) Q:ZZUTVAR="" I $E(ZZUTVAR,1,3)'="%ut",'$D(%utINPT(ZZUTVAR)),",DUZ,IO,U,DTIME,ZZUTVAR,DT,%ut,XTGUISEP,"'[(","_ZZUTVAR_",") W !,%utLOC_" VARIABLE LEAK: "_ZZUTVAR
. Q . Q
Q Q
; ;
NVLDARG ; generate message for invalid arguments to test NVLDARG ; generate message for invalid arguments to test
N XTERMSG N XTERMSG
; ZEXCEPT: %ut -- NEWED ON ENTRY ; ZEXCEPT: %ut -- NEWED ON ENTRY
; ZEXCEPT: %utERRL,%utGUI -CREATED IN SETUP, KILLED IN END ; ZEXCEPT: %utERRL,%utGUI -CREATED IN SETUP, KILLED IN END
; ZEXCEPT: XTGUISEP - newed in GUINEXT ; ZEXCEPT: XTGUISEP - newed in GUINEXT
S XTERMSG="NO VALUES INPUT TO CHKEQ^%ut - no evaluation possible" S XTERMSG="NO VALUES INPUT TO CHKEQ^%ut - no evaluation possible"
I '$D(%utGUI) D I '$D(%utGUI) D
. D SETIO . D SETIO
. W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - " W XTERMSG,! D . W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - " W XTERMSG,! D
. . S %ut("FAIL")=%ut("FAIL")+1,%utERRL(%ut("FAIL"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=XTERMSG,%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT") . . S %ut("FAIL")=%ut("FAIL")+1,%utERRL(%ut("FAIL"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=XTERMSG,%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT")
. . Q . . Q
. D RESETIO . D RESETIO
. Q . Q
I $D(%utGUI) S %ut("CNT")=%ut("CNT")+1,@%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"FAILURE"_XTGUISEP_XTERMSG I $D(%utGUI) S %ut("CNT")=%ut("CNT")+1,@%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"FAILURE"_XTGUISEP_XTERMSG,%ut("FAIL")=%ut("FAIL")+1
Q Q
; ;
ERROR ; record errors ERROR ; record errors
; ZEXCEPT: %utERRL,%utGUI,%utERR -CREATED IN SETUP, KILLED IN END ; ZEXCEPT: %utERRL,%utGUI,%utERR -CREATED IN SETUP, KILLED IN END
; ZEXCEPT: %ut -- NEWED ON ENTRY ; ZEXCEPT: %ut -- NEWED ON ENTRY
; ZEXCEPT: XTGUISEP - newed in GUINEXT ; ZEXCEPT: XTGUISEP - newed in GUINEXT
S %ut("CHK")=%ut("CHK")+1 S %ut("CHK")=%ut("CHK")+1
I '$D(%utGUI) D ERROR1 I '$D(%utGUI) D ERROR1
I $D(%utGUI) D I $D(%utGUI) D
. S %ut("CNT")=%ut("CNT")+1 . S %ut("CNT")=%ut("CNT")+1
. S %utERR=%utERR+1 . S %utERR=%utERR+1
. S @%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"ERROR"_XTGUISEP_$S(+$SY=47:$ZS,1:$ZE) . S @%ut("RSLT")@(%ut("CNT"))=%ut("LOC")_XTGUISEP_"ERROR"_XTGUISEP_$S(+$SY=47:$ZS,1:$ZE)
. Q . Q
S @($S(+$SY=47:"$ZS",1:"$ZE")_"="_""""""),$EC="" S @($S(+$SY=47:"$ZS",1:"$ZE")_"="_""""""),$EC=""
Q Q
; ;
ERROR1 ; ERROR1 ;
I $G(%ut("BREAK")) BREAK ; if we are asked to break upon error, please do so! I $G(%ut("BREAK")) BREAK ; if we are asked to break upon error, please do so!
; ZEXCEPT: %utERRL -CREATED IN SETUP, KILLED IN END ; ZEXCEPT: %utERRL -CREATED IN SETUP, KILLED IN END
; ZEXCEPT: %ut -- NEWED ON ENTRY ; ZEXCEPT: %ut -- NEWED ON ENTRY
D SETIO D SETIO
W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - Error: " W $S(+$SY=47:$ZS,1:$ZE),! D W !,%ut("ENT")," - " W:%ut("NAME")'="" %ut("NAME")," - Error: " W $S(+$SY=47:$ZS,1:$ZE),! D
. S %ut("ERRN")=%ut("ERRN")+1,%utERRL(%ut("ERRN"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=$S(+$SY=47:$ZS,1:$ZE),%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT") . S %ut("ERRN")=%ut("ERRN")+1,%utERRL(%ut("ERRN"))=%ut("NAME"),%utERRL(%ut("FAIL"),"MSG")=$S(+$SY=47:$ZS,1:$ZE),%utERRL(%ut("FAIL"),"ENTRY")=%ut("ENT")
. Q . Q
D RESETIO D RESETIO
Q Q
SETIO ; Set M-Unit Device to write the results to... SETIO ; Set M-Unit Device to write the results to...
; ZEXCEPT: %ut -- NEWED ON ENTRY ; ZEXCEPT: %ut -- NEWED ON ENTRY
I $IO'=%ut("IO") S (IO(0),%ut("DEV","OLD"))=$IO USE %ut("IO") SET IO=$IO I $IO'=%ut("IO") S (IO(0),%ut("DEV","OLD"))=$IO USE %ut("IO") SET IO=$IO
QUIT QUIT
; ;
RESETIO ; Reset $IO back to the original device if we changed it. RESETIO ; Reset $IO back to the original device if we changed it.
; ZEXCEPT: %ut -- NEWED ON ENTRY ; ZEXCEPT: %ut -- NEWED ON ENTRY
I $D(%ut("DEV","OLD")) S IO(0)=%ut("IO") U %ut("DEV","OLD") S IO=$IO K %ut("DEV","OLD") I $D(%ut("DEV","OLD")) S IO(0)=%ut("IO") U %ut("DEV","OLD") S IO=$IO K %ut("DEV","OLD")
QUIT QUIT
; ;
ISUTEST() ; .SUPPORTED API TO DETERMINE IF CURRENTLY IN UNIT TEST ISUTEST() ; .SUPPORTED API TO DETERMINE IF CURRENTLY IN UNIT TEST
; ZEXCEPT: %ut -- NEWED ON ENTRY ; ZEXCEPT: %ut -- NEWED ON ENTRY
Q $G(%ut)=1 Q $G(%ut)=1
; ;
PICKSET ; .OPT Interactive selection of MUnit Test Group PICKSET ; .OPT Interactive selection of MUnit Test Group
N DIC,Y,%utROU,%utLIST,DIR N DIC,Y,%utROU,%utLIST,DIR
S DIC=17.9001,DIC(0)="AEQM" D ^DIC Q:Y'>0 W ! S DIC=17.9001,DIC(0)="AEQM" D ^DIC Q:Y'>0 W !
D GETSET(+Y,.%utROU,.%utLIST) D GETSET(+Y,.%utROU,.%utLIST)
N DIC,Y,%ut N DIC,Y,%ut
D SETUT D SETUT
D EN1(.%utROU,%utLIST) D EN1(.%utROU,%utLIST)
S DIR(0)="EA",DIR("A")="Enter RETURN to continue:" D ^DIR K DIR S DIR(0)="EA",DIR("A")="Enter RETURN to continue:" D ^DIR K DIR
Q Q
; ;
RUNSET(SETNAME,VERBOSE) ; .SR Run with Specified Selection of MUnit Test Group RUNSET(SETNAME,VERBOSE) ; .SR Run with Specified Selection of MUnit Test Group
N Y,%utROU,%utLIST,%utVERB N Y,%utROU,%utLIST,%utVERB
Q:$G(SETNAME)="" Q:$G(SETNAME)=""
S %utVERB=$G(VERBOSE,0) S %utVERB=$G(VERBOSE,0)
S Y=+$$FIND1^DIC(17.9001,"","X",SETNAME) Q:Y'>0 S Y=+$$FIND1^DIC(17.9001,"","X",SETNAME) Q:Y'>0
D GETSET(Y,.%utROU,.%utLIST) D GETSET(Y,.%utROU,.%utLIST)
N Y,SETNAME,%ut N Y,SETNAME,%ut
D SETUT D SETUT
D EN1(.%utROU,%utLIST) D EN1(.%utROU,%utLIST)
Q Q
; ;
; DOSET CAN BE USED TO RUN A SET OF TESTS BASED ON THE IEN IN THE MUNIT TEST GROUP file (#17.9001) ; DOSET CAN BE USED TO RUN A SET OF TESTS BASED ON THE IEN IN THE MUNIT TEST GROUP file (#17.9001)
DOSET(IEN,%utVERB) ; 140731 JLI added %utVERB as a second argument DOSET(IEN,%utVERB) ; 140731 JLI added %utVERB as a second argument
; IEN - Internal entry number for selected set of tests in the MUNIT TEST GROUP file (#17.9001) ; IEN - Internal entry number for selected set of tests in the MUNIT TEST GROUP file (#17.9001)
; %utVERB - optional input that indicates verbose output is permitted ; %utVERB - optional input that indicates verbose output is permitted
; ;
N %utROU,%utLIST N %utROU,%utLIST
I '$D(%utVERB) S %utVERB=0 I '$D(%utVERB) S %utVERB=0
S %utLIST=0 S %utLIST=0
D GETSET($G(IEN),.%utROU,.%utLIST) D GETSET($G(IEN),.%utROU,.%utLIST)
I %utLIST>0 N IEN,%ut D SETUT,EN1(.%utROU,%utLIST) I %utLIST>0 N IEN,%ut D SETUT,EN1(.%utROU,%utLIST)
Q Q
; ;
GETSET(IEN,%utROU,%utLIST) ; JLI 140731 - called from PICKSET, RUNSET, DOSET, GUISET GETSET(IEN,%utROU,%utLIST) ; JLI 140731 - called from PICKSET, RUNSET, DOSET, GUISET
N IENS,%utROOT N IENS,%utROOT
S IENS=IEN_"," D GETS^DIQ(17.9001,IENS,"1*","","%utROOT") S IENS=IEN_"," D GETS^DIQ(17.9001,IENS,"1*","","%utROOT")
S %utLIST=0,IENS="" F S IENS=$O(%utROOT(17.90011,IENS)) Q:IENS="" S %utLIST=%utLIST+1,%utROU(%utLIST)=%utROOT(17.90011,IENS,.01) S %utLIST=0,IENS="" F S IENS=$O(%utROOT(17.90011,IENS)) Q:IENS="" S %utLIST=%utLIST+1,%utROU(%utLIST)=%utROOT(17.90011,IENS,.01)
Q Q
; ;
GUISET(%utRSLT,XTSET) ; Entry point for GUI start with selected Test Set IEN - called by %ut-TEST GROUP LOAD rpc GUISET(%utRSLT,XTSET) ; Entry point for GUI start with selected Test Set IEN - called by %ut-TEST GROUP LOAD rpc
N %utROU,%utLIST,%ut N %utROU,%utLIST,%ut
D SETUT D SETUT
S %ut("RSLT")=$NA(^TMP("MUNIT-%utRSLT",$J)) K @%ut("RSLT") S %ut("RSLT")=$NA(^TMP("MUNIT-%utRSLT",$J)) K @%ut("RSLT")
D GETSET(XTSET,.%utROU,.%utLIST) D GETSET(XTSET,.%utROU,.%utLIST)
D GETLIST(.%utROU,%utLIST,%ut("RSLT")) D GETLIST(.%utROU,%utLIST,%ut("RSLT"))
S @%ut("RSLT")@(1)=(@%ut("RSLT")@(1))_"^1" ; 110719 mark as new version S @%ut("RSLT")@(1)=(@%ut("RSLT")@(1))_"^1" ; 110719 mark as new version
S %utRSLT=%ut("RSLT") S %utRSLT=%ut("RSLT")
Q Q
; ;
GUILOAD(%utRSLT,%utROUN) ; Entry point for GUI start with %utROUN containing primary routine name - called by %ut-TEST LOAD rpc GUILOAD(%utRSLT,%utROUN) ; Entry point for GUI start with %utROUN containing primary routine name - called by %ut-TEST LOAD rpc
N %utROU,%ut N %utROU,%ut
D SETUT D SETUT
S %ut("RSLT")=$NA(^TMP("MUNIT-%utRSLT",$J)) K @%ut("RSLT") S %ut("RSLT")=$NA(^TMP("MUNIT-%utRSLT",$J)) K @%ut("RSLT")
S %utROU(1)=%utROUN S %utROU(1)=%utROUN
D GETLIST(.%utROU,1,%ut("RSLT")) D GETLIST(.%utROU,1,%ut("RSLT"))
S @%ut("RSLT")@(1)=(@%ut("RSLT")@(1))_"^1" ; 110719 mark as new version S @%ut("RSLT")@(1)=(@%ut("RSLT")@(1))_"^1" ; 110719 mark as new version
S %utRSLT=%ut("RSLT") S %utRSLT=%ut("RSLT")
Q Q
; ;
GETLIST(%utROU,%utLIST,%utRSLT) ; called from GUISET, GUILOAD GETLIST(%utROU,%utLIST,%utRSLT) ; called from GUISET, GUILOAD
N I,%utROUL,%utROUN,%ut,XTCOMNT,XTVALUE,%utCNT N I,%utROUL,%utROUN,%ut,XTCOMNT,XTVALUE,%utCNT
S XTVALUE=$NA(^TMP("GUI-MUNIT",$J)) K @XTVALUE S XTVALUE=$NA(^TMP("GUI-MUNIT",$J)) K @XTVALUE
S %utCNT=0,XTCOMNT="" S %utCNT=0,XTCOMNT=""
D GETTREE^%ut1(.%utROU,%utLIST) D GETTREE^%ut1(.%utROU,%utLIST)
F I=1:1 Q:'$D(%utROU(I)) S %utROUL(%utROU(I))="" F I=1:1 Q:'$D(%utROU(I)) S %utROUL(%utROU(I))=""
S %utROUN="" F S %utROUN=$O(%utROUL(%utROUN)) Q:%utROUN="" D LOAD(%utROUN,.%utCNT,XTVALUE,XTCOMNT,.%utROUL) S %utROUN="" F S %utROUN=$O(%utROUL(%utROUN)) Q:%utROUN="" D LOAD(%utROUN,.%utCNT,XTVALUE,XTCOMNT,.%utROUL)
M @%utRSLT=@XTVALUE M @%utRSLT=@XTVALUE
K @%utRSLT@("SHUTDOWN") K @%utRSLT@("SHUTDOWN")
K @%utRSLT@("STARTUP") K @%utRSLT@("STARTUP")
S @XTVALUE@("LASTROU")="" ; Use this to keep track of place in routines S @XTVALUE@("LASTROU")="" ; Use this to keep track of place in routines
Q Q
; ;
; generate list of unit test routines, entry points and comments on test for entry point ; generate list of unit test routines, entry points and comments on test for entry point
LOAD(%utROUN,%utNCNT,XTVALUE,XTCOMNT,%utROUL) ; called from GETLIST, and recursively from LOAD LOAD(%utROUN,%utNCNT,XTVALUE,XTCOMNT,%utROUL) ; called from GETLIST, and recursively from LOAD
I $T(@("^"_%utROUN))="" S %utNCNT=%utNCNT+1,@XTVALUE@(%utNCNT)=%utROUN_"^^*** ERROR - ROUTINE NAME NOT FOUND" Q I $T(@("^"_%utROUN))="" S %utNCNT=%utNCNT+1,@XTVALUE@(%utNCNT)=%utROUN_"^^*** ERROR - ROUTINE NAME NOT FOUND" Q
S %utNCNT=%utNCNT+1,@XTVALUE@(%utNCNT)=%utROUN_U_U_XTCOMNT S %utNCNT=%utNCNT+1,@XTVALUE@(%utNCNT)=%utROUN_U_U_XTCOMNT
;N %utI,XTX1,XTX2,LINE ;N %utI,XTX1,XTX2,LINE
N %utI,XTX1,XTX2,LINE,LIST,I N %utI,XTX1,XTX2,LINE,LIST,I
; 100622 JLI added code to identify STARTUP and TEARDOWN ; 100622 JLI added code to identify STARTUP and TEARDOWN
I $T(@("STARTUP^"_%utROUN))'="",'$D(@XTVALUE@("STARTUP")) S @XTVALUE@("STARTUP")="STARTUP^"_%utROUN I $T(@("STARTUP^"_%utROUN))'="",'$D(@XTVALUE@("STARTUP")) S @XTVALUE@("STARTUP")="STARTUP^"_%utROUN
I $T(@("SHUTDOWN^"_%utROUN))'="",'$D(@XTVALUE@("SHUTDOWN")) S @XTVALUE@("SHUTDOWN")="SHUTDOWN^"_%utROUN I $T(@("SHUTDOWN^"_%utROUN))'="",'$D(@XTVALUE@("SHUTDOWN")) S @XTVALUE@("SHUTDOWN")="SHUTDOWN^"_%utROUN
; JLI 140731 handle @TEST identified test tags ; JLI 140731 handle @TEST identified test tags
D NEWSTYLE^%ut1(.LIST,%utROUN) D NEWSTYLE^%ut1(.LIST,%utROUN)
F I=1:1:LIST S %utNCNT=%utNCNT+1,@XTVALUE@(%utNCNT)=%utROUN_U_LIST(I) F I=1:1:LIST S %utNCNT=%utNCNT+1,@XTVALUE@(%utNCNT)=%utROUN_U_LIST(I)
; JLI 140731 end of @TEST addition ; JLI 140731 end of @TEST addition
F %utI=1:1 S LINE=$T(@("XTENT+"_%utI_"^"_%utROUN)) S XTX1=$P(LINE,";",3) Q:XTX1="" S XTX2=$P(LINE,";",4),%utNCNT=%utNCNT+1,@XTVALUE@(%utNCNT)=%utROUN_U_XTX1_U_XTX2 F %utI=1:1 S LINE=$T(@("XTENT+"_%utI_"^"_%utROUN)) S XTX1=$P(LINE,";",3) Q:XTX1="" S XTX2=$P(LINE,";",4),%utNCNT=%utNCNT+1,@XTVALUE@(%utNCNT)=%utROUN_U_XTX1_U_XTX2
F %utI=1:1 S LINE=$T(@("XTROU+"_%utI_"^"_%utROUN)) S XTX1=$P(LINE,";",3) Q:XTX1="" S XTCOMNT=$P(LINE,";",4) I '$D(%utROUL(XTX1)) S %utROUL(XTX1)="" D LOAD(XTX1,.%utNCNT,XTVALUE,XTCOMNT,.%utROUL) F %utI=1:1 S LINE=$T(@("XTROU+"_%utI_"^"_%utROUN)) S XTX1=$P(LINE,";",3) Q:XTX1="" S XTCOMNT=$P(LINE,";",4) I '$D(%utROUL(XTX1)) S %utROUL(XTX1)="" D LOAD(XTX1,.%utNCNT,XTVALUE,XTCOMNT,.%utROUL)
Q Q
; ;
GUINEXT(%utRSLT,%utLOC,XTGUISEP) ; Entry point for GUI execute next test - called by %ut-TEST NEXT rpc GUINEXT(%utRSLT,%utLOC,XTGUISEP) ; Entry point for GUI execute next test - called by %ut-TEST NEXT rpc
; XTGUISEP - added 110719 to provide for changing separator for GUI ; XTGUISEP - added 110719 to provide for changing separator for GUI
; return from ^ to another value ~~^~~ so that data returned ; return from ^ to another value ~~^~~ so that data returned
; is not affected by ^ values in the data - if not present ; is not affected by ^ values in the data - if not present
; sets value to default ^ ; sets value to default ^
N %utETRY,%utROUT,XTOLROU,XTVALUE,%utERR,%utGUI N %utETRY,%utROUT,XTOLROU,XTVALUE,%utERR,%utGUI
N %ut N %ut
I $G(XTGUISEP)="" S XTGUISEP="^" I $G(XTGUISEP)="" S XTGUISEP="^"
D SETUT D SETUT
S %ut("LOC")=%utLOC S %ut("LOC")=%utLOC
S %ut("CURR")=0,%ut("ECNT")=0,%ut("FAIL")=0,%ut("CHK")=0,%ut("NENT")=0,%ut("ERRN")=0 S %ut("CURR")=0,%ut("ECNT")=0,%ut("FAIL")=0,%ut("CHK")=0,%ut("NENT")=0,%ut("ERRN")=0
S XTVALUE=$NA(^TMP("GUI-MUNIT",$J)) S XTVALUE=$NA(^TMP("GUI-MUNIT",$J))
S %ut("RSLT")=$NA(^TMP("GUINEXT",$J)) K @%ut("RSLT") S %ut("RSLT")=$NA(^TMP("GUINEXT",$J)) K @%ut("RSLT")
S %utRSLT=%ut("RSLT") S %utRSLT=%ut("RSLT")
S %utETRY=$P(%utLOC,U),%utROUT=$P(%utLOC,U,2),XTOLROU=$G(@XTVALUE@("LASTROU")) S %utETRY=$P(%utLOC,U),%utROUT=$P(%utLOC,U,2),XTOLROU=$G(@XTVALUE@("LASTROU"))
S %utGUI=1 S %utGUI=1
; I %utROUT'=XTOLROU D I %utROUT="" S @%utRSLT@(1)="" K @XTVALUE Q ;140731 JLI - commented out S %ut("CHK")=0,%ut("CNT")=1,%utERR=0
D I %utROUT="" S @%utRSLT@(1)="" K @XTVALUE Q ; 140731 JLI - replaced previous line - moves check for SHUTDOWN at end of processing ; I %utROUT'=XTOLROU D I %utROUT="" S @%utRSLT@(1)="" K @XTVALUE Q ;140731 JLI - commented out
. I XTOLROU="",$D(@XTVALUE@("STARTUP")) D ;D I %utROUT="" S @%utRSLT@(1)="" K @XTVALUE Q ; 140731 JLI - replaced previous line - moves check for SHUTDOWN at end of processing
. . S %ut("LOC")=@XTVALUE@("STARTUP") D I %utROUT="" S @%utRSLT@(1)="" Q ; 140829 JLI - Have to leave XTVALUE intact, in case they simply run again for STARTUP, etc.
. . N $ETRAP S $ETRAP="D ERROR^%ut" . I XTOLROU="",$D(@XTVALUE@("STARTUP")) D
. . D @(@XTVALUE@("STARTUP")) . . S %ut("LOC")=@XTVALUE@("STARTUP")
. . Q . . N $ETRAP S $ETRAP="D ERROR^%ut"
. S @XTVALUE@("LASTROU")=%utROUT I %utROUT'="",$T(@("SETUP^"_%utROUT))'="" D . . D @(@XTVALUE@("STARTUP"))
. . S %ut("LOC")="SETUP^"_%utROUT . . Q
. . N $ETRAP S $ETRAP="D ERROR^%ut" . S @XTVALUE@("LASTROU")=%utROUT I %utROUT'="",$T(@("SETUP^"_%utROUT))'="" D
. . D @("SETUP^"_%utROUT) . . S %ut("LOC")="SETUP^"_%utROUT
. . Q . . N $ETRAP S $ETRAP="D ERROR^%ut"
. I %utROUT="",$D(@XTVALUE@("SHUTDOWN")) D . . D @("SETUP^"_%utROUT)
. . S %ut("LOC")=@XTVALUE@("SHUTDOWN") . . Q
. . N $ETRAP S $ETRAP="D ERROR^%ut" . I %utROUT="",$D(@XTVALUE@("SHUTDOWN")) D
. . D @(@XTVALUE@("SHUTDOWN")) . . S %ut("LOC")=@XTVALUE@("SHUTDOWN")
. . Q . . N $ETRAP S $ETRAP="D ERROR^%ut"
. Q . . D @(@XTVALUE@("SHUTDOWN"))
S %ut("LOC")=%utLOC . . Q
S %ut("CHK")=0,%ut("CNT")=1,%utERR=0 . Q
D ; to limit range of error trap so we continue through other tests S %ut("LOC")=%utLOC
. N $ETRAP S $ETRAP="D ERROR^%ut" S %ut("CHK")=0,%ut("CNT")=1,%utERR=0
. D @%ut("LOC") D ; to limit range of error trap so we continue through other tests
. Q . N $ETRAP S $ETRAP="D ERROR^%ut"
I $T(@("TEARDOWN^"_%utROUT))'="" D . D @%ut("LOC")
. S %ut("LOC")="TEARDOWN^"_%utROUT . Q
. N $ETRAP S $ETRAP="D ERROR^%ut" I $T(@("TEARDOWN^"_%utROUT))'="" D
. D @("TEARDOWN^"_%utROUT) . S %ut("LOC")="TEARDOWN^"_%utROUT
. Q . N $ETRAP S $ETRAP="D ERROR^%ut"
S @%ut("RSLT")@(1)=%ut("CHK")_XTGUISEP_(%ut("CNT")-1-%utERR)_XTGUISEP_%utERR . D @("TEARDOWN^"_%utROUT)
Q . Q
; S @%ut("RSLT")@(1)=%ut("CHK")_XTGUISEP_(%ut("CNT")-1-%utERR)_XTGUISEP_%utERR
TESTCOVR ; entry under coverage analysis Q
D ENTRY^%uttcovr ; does analysis while running various unit tests ;
Q TESTCOVR ; entry under coverage analysis
; D ENTRY^%uttcovr ; does analysis while running various unit tests
Q
;

View File

@ -1,277 +1,267 @@
%ut1 ;VEN/SMH/JLI - CONTINUATION OF M-UNIT PROCESSING ;2014-09-10 7:41 PM %ut1 ;VEN/SMH/JLI - CONTINUATION OF M-UNIT PROCESSING ;09/10/14 14:27
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
; ;
;following is original header from XTMUNIT1 in unreleased patch XT*7.3*81 VA code ;following is original header from XTMUNIT1 in unreleased patch XT*7.3*81 VA code
;XTMUNIT1 ;JLI/FO-OAK-CONTINUATION OF UNIT TEST ROUTINE ;2014-04-17 5:26 PM ;XTMUNIT1 ;JLI/FO-OAK-CONTINUATION OF UNIT TEST ROUTINE ;2014-04-17 5:26 PM
;;7.3;TOOLKIT;**81**;APR 25 1995;Build 24 ;;7.3;TOOLKIT;**81**;APR 25 1995;Build 24
; ;
; ;
; Original by Dr. Joel Ivey ; Original by Dr. Joel Ivey
; Major contributions by Dr. Sam Habiel ; Major contributions by Dr. Sam Habiel
; ;
; Changes: ; Changes:
; 130726 SMH - Moved test collection logic from %utUNIT to here (multiple places) ; 130726 SMH - Moved test collection logic from %utUNIT to here (multiple places)
; 131218 SMH - dependence on XLFSTR removed ; 131218 SMH - dependence on XLFSTR removed
; 131218 SMH - CHEKTEST refactored to use $TEXT instead of ^%ZOSF("LOAD") ; 131218 SMH - CHEKTEST refactored to use $TEXT instead of ^%ZOSF("LOAD")
; 131218 SMH - CATCHERR now nulls out $ZS if on GT.M ; 131218 SMH - CATCHERR now nulls out $ZS if on GT.M
; ;
; TODO: find this routine and add to repo. Q
D EN^%ut("%utt3") ;
Q CHEKTEST(%utROU,%ut,%utUETRY) ; Collect Test list.
; ; %utROU - input - Name of routine to check for tags with @TEST attribute
CHEKTEST(%utROU,%ut,%utUETRY) ; Collect Test list. ; %ut - input/output - passed by reference
; %utROU - input - Name of routine to check for tags with @TEST attribute ; %utUETRY - input/output - passed by reference
; %ut - input/output - passed by reference ;
; %utUETRY - input/output - passed by reference ; Test list collected in two ways:
; ; - @TEST on labellines
; Test list collected in two ways: ; - Offsets of XTENT
; - @TEST on labellines ;
; - Offsets of XTENT S %ut("ENTN")=0 ; Number of test, sub to %utUETRY.
; ;
S %ut("ENTN")=0 ; Number of test, sub to %utUETRY. ; This stanza and everything below is for collecting @TEST.
; ; VEN/SMH - block refactored to use $TEXT instead of ^%ZOSF("LOAD")
; This stanza and everything below is for collecting @TEST. N I,LIST
; VEN/SMH - block refactored to use $TEXT instead of ^%ZOSF("LOAD") S I=$L($T(@(U_%utROU))) I I<0 Q "-1^Invalid Routine Name"
N I,LIST ; 140731 JLI - the following SMH code is replaced by the code below
S I=$L($T(@(U_%utROU))) I I<0 Q "-1^Invalid Routine Name" ; Complexity galore: $TEXT loops through routine
N $ETRAP S $ETRAP="D CATCHERR^%ut1" ; IF tab or space isn't the first character ($C(9,32)) and line contains @TEST
; 140731 JLI - the following SMH code is replaced by the code below ; Load that line as a testing entry point
; Complexity galore: $TEXT loops through routine ; F I=1:1 S LINE=$T(@("+"_I_U_%utROU)) Q:LINE="" I $C(9,32)'[$E(LINE),$$UP(LINE)["@TEST" D
; IF tab or space isn't the first character ($C(9,32)) and line contains @TEST ; . N TAGNAME,CHAR,NPAREN S TAGNAME="",NPAREN=0
; Load that line as a testing entry point ; . F Q:LINE="" S CHAR=$E(LINE),LINE=$E(LINE,2,999) Q:CHAR="" Q:" ("[CHAR S TAGNAME=TAGNAME_CHAR
; F I=1:1 S LINE=$T(@("+"_I_U_%utROU)) Q:LINE="" I $C(9,32)'[$E(LINE),$$UP(LINE)["@TEST" D ; . ; should be no paren or arguments
; . N TAGNAME,CHAR,NPAREN S TAGNAME="",NPAREN=0 ; . I CHAR="(" Q
; . F Q:LINE="" S CHAR=$E(LINE),LINE=$E(LINE,2,999) Q:CHAR="" Q:" ("[CHAR S TAGNAME=TAGNAME_CHAR ; . F Q:LINE="" S CHAR=$E(LINE) Q:" ;"'[CHAR S LINE=$E(LINE,2,999)
; . ; should be no paren or arguments ; . I $$UP($E(LINE,1,5))="@TEST" S LINE=$E(LINE,6,999) D
; . I CHAR="(" Q ; . . S %ut("ENTN")=%ut("ENTN")+1,%utUETRY(%ut("ENTN"))=TAGNAME
; . F Q:LINE="" S CHAR=$E(LINE) Q:" ;"'[CHAR S LINE=$E(LINE,2,999) ; . . F Q:LINE="" S CHAR=$E(LINE) Q:CHAR?1AN S LINE=$E(LINE,2,999)
; . I $$UP($E(LINE,1,5))="@TEST" S LINE=$E(LINE,6,999) D ; . . S %utUETRY(%ut("ENTN"),"NAME")=LINE
; . . S %ut("ENTN")=%ut("ENTN")+1,%utUETRY(%ut("ENTN"))=TAGNAME ; JLI 140731 - end of code replaced by following code
; . . F Q:LINE="" S CHAR=$E(LINE) Q:CHAR?1AN S LINE=$E(LINE,2,999) ; JLI 140731 - the following code replaces the code above
; . . S %utUETRY(%ut("ENTN"),"NAME")=LINE D NEWSTYLE(.LIST,%utROU)
; JLI 140731 - end of code replaced by following code F I=1:1:LIST S %ut("ENTN")=%ut("ENTN")+1,%utUETRY(%ut("ENTN"))=$P(LIST(I),U),%utUETRY(%ut("ENTN"),"NAME")=$P(LIST(I),U,2,99)
; JLI 140731 - the following code replaces the code above ; JLI 140731 - end of replacement code
D NEWSTYLE(.LIST,%utROU) ;
F I=1:1:LIST S %ut("ENTN")=%ut("ENTN")+1,%utUETRY(%ut("ENTN"))=$P(LIST(I),U),%utUETRY(%ut("ENTN"),"NAME")=$P(LIST(I),U,2,99) ;
; JLI 140731 - end of replacement code ; This Stanza is to collect XTENT offsets
; N %utUI F %utUI=1:1 S %ut("ELIN")=$T(@("XTENT+"_%utUI_"^"_%utROU)) Q:$P(%ut("ELIN"),";",3)="" D
; . S %ut("ENTN")=%ut("ENTN")+1,%utUETRY(%ut("ENTN"))=$P(%ut("ELIN"),";",3),%utUETRY(%ut("ENTN"),"NAME")=$P(%ut("ELIN"),";",4)
; This Stanza is to collect XTENT offsets . Q
N %utUI F %utUI=1:1 S %ut("ELIN")=$T(@("XTENT+"_%utUI_"^"_%utROU)) Q:$P(%ut("ELIN"),";",3)="" D ;
. S %ut("ENTN")=%ut("ENTN")+1,%utUETRY(%ut("ENTN"))=$P(%ut("ELIN"),";",3),%utUETRY(%ut("ENTN"),"NAME")=$P(%ut("ELIN"),";",4) QUIT
. Q ;
; ; VEN/SMH 26JUL2013 - Moved GETTREE here.
QUIT GETTREE(%utROU,%utULIST) ;
; ; first get any other routines this one references for running subsequently
; VEN/SMH - Is this catch needed anymore? ; then any that they refer to as well
CATCHERR ; catch error on trying to load file if it doesn't exist ; JLI 120806 ; this builds a tree of all routines referred to by any routine including each only once
W !,"In CATCHERR",! ; JLI 140910 DEBUG N %utUK,%utUI,%utUJ,%utURNAM,%utURLIN
S $ZE="",$EC="" F %utUK=1:1 Q:'$D(%utROU(%utUK)) D
I +$SY=47 S $ZS="" ; VEN/SMH fur GT.M. . F %utUI=1:1 S %utURLIN=$T(@("XTROU+"_%utUI_"^"_%utROU(%utUK))) S %utURNAM=$P(%utURLIN,";",3) Q:%utURNAM="" D
QUIT . . F %utUJ=1:1:%utULIST I %utROU(%utUJ)=%utURNAM S %utURNAM="" Q
; . . I %utURNAM'="",$T(@("+1^"_%utURNAM))="" W:'$D(XWBOS) "Referenced routine ",%utURNAM," not found.",! Q
; VEN/SMH 26JUL2013 - Moved GETTREE here. . . S:%utURNAM'="" %utULIST=%utULIST+1,%utROU(%utULIST)=%utURNAM
GETTREE(%utROU,%utULIST) ; QUIT
; first get any other routines this one references for running subsequently ;
; then any that they refer to as well NEWSTYLE(LIST,ROUNAME) ; JLI 140726 identify and return list of newstyle tags or entries for this routine
; this builds a tree of all routines referred to by any routine including each only once ; LIST - input, passed by reference - returns containing array with list of tags identified as tests
N %utUK,%utUI,%utUJ,%utURNAM,%utURLIN ; LIST indicates number of tags identified, LIST(n)=tag^test_info where tag is entry point for test
F %utUK=1:1 Q:'$D(%utROU(%utUK)) D ; ROUNAME - input - routine name in which tests should be identified
. F %utUI=1:1 S %utURLIN=$T(@("XTROU+"_%utUI_"^"_%utROU(%utUK))) S %utURNAM=$P(%utURLIN,";",3) Q:%utURNAM="" D ;
. . F %utUJ=1:1:%utULIST I %utROU(%utUJ)=%utURNAM S %utURNAM="" Q N I,VALUE,LINE
. . I %utURNAM'="",$T(@("+1^"_%utURNAM))="" W:'$D(XWBOS) "Referenced routine ",%utURNAM," not found.",! Q K LIST S LIST=0
. . S:%utURNAM'="" %utULIST=%utULIST+1,%utROU(%utULIST)=%utURNAM ; search routine by line for a tag and @TEST declaration
QUIT F I=1:1 S LINE=$T(@("+"_I_"^"_ROUNAME)) Q:LINE="" S VALUE=$$CHECKTAG(LINE) I VALUE'="" S LIST=LIST+1,LIST(LIST)=VALUE
; Q
NEWSTYLE(LIST,ROUNAME) ; JLI 140726 identify and return list of newstyle tags or entries for this routine ;
; LIST - input, passed by reference - returns containing array with list of tags identified as tests CHECKTAG(LINE) ; JLI 140726 check line to determine @test TAG
; LIST indicates number of tags identified, LIST(n)=tag^test_info where tag is entry point for test ; LINE - input - Line of code to be checked
; ROUNAME - input - routine name in which tests should be identified ; returns null line if not @TEST line, otherwise TAG^NOTE
; N TAG,NOTE,CHAR
N I,VALUE,LINE I $E(LINE)=" " Q "" ; test entry must have a tag
K LIST S LIST=0 I $$UP(LINE)'["@TEST" Q "" ; must have @TEST declaration
; search routine by line for a tag and @TEST declaration I $P($$UP(LINE),"@TEST")["(" Q "" ; can't have an argument
F I=1:1 S LINE=$T(@("+"_I_"^"_ROUNAME)) Q:LINE="" S VALUE=$$CHECKTAG(LINE) I VALUE'="" S LIST=LIST+1,LIST(LIST)=VALUE S TAG=$P(LINE," "),LINE=$P(LINE," ",2,400),NOTE=$P($$UP(LINE),"@TEST"),LINE=$E(LINE,$L(NOTE)+5+1,$L(LINE))
Q F Q:NOTE="" S CHAR=$E(NOTE),NOTE=$E(NOTE,2,$L(NOTE)) I " ;"'[CHAR Q ;
; I $L(NOTE)'=0 Q "" ; @TEST must be first text on line
CHECKTAG(LINE) ; JLI 140726 check line to determine @test TAG F Q:$E(LINE)'=" " S LINE=$E(LINE,2,$L(LINE)) ; remove leading spaces from test info
; LINE - input - Line of code to be checked S TAG=TAG_U_LINE
; returns null line if not @TEST line, otherwise TAG^NOTE Q TAG
N TAG,NOTE,CHAR ;
I $E(LINE)=" " Q "" ; test entry must have a tag ; VEN/SMH 17DEC2013 - Remove dependence on VISTA - Uppercase here instead of XLFSTR.
I $$UP(LINE)'["@TEST" Q "" ; must have @TEST declaration UP(X) ;
I $P($$UP(LINE),"@TEST")["(" Q "" ; can't have an argument Q $TR(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
S TAG=$P(LINE," "),LINE=$P(LINE," ",2,400),NOTE=$P($$UP(LINE),"@TEST"),LINE=$E(LINE,$L(NOTE)+5+1,$L(LINE)) ;
F Q:NOTE="" S CHAR=$E(NOTE),NOTE=$E(NOTE,2,$L(NOTE)) I " ;"'[CHAR Q ; COV(NMSP,COVCODE,VERBOSITY) ; VEN/SMH - PUBLIC ENTRY POINT; Coverage calculations
I $L(NOTE)'=0 Q "" ; @TEST must be first text on line ; NMSP: Namespace of the routines to analyze. End with * to include all routines.
F Q:$E(LINE)'=" " S LINE=$E(LINE,2,$L(LINE)) ; remove leading spaces from test info ; Not using * will only include the routine with NMSP name.
S TAG=TAG_U_LINE ; e.g. PSOM* will include all routines starting with PSOM
Q TAG ; PSOM will only include PSOM.
; ; COVCODE: Mumps code to run over which coverage will be calculated. Typically Unit Tests.
; VEN/SMH 17DEC2013 - Remove dependence on VISTA - Uppercase here instead of XLFSTR. ; VERBOSITY (optional): Scalar from -1 to 3.
UP(X) ; ; - -1 = Global output in ^TMP("%utCOVREPORT",$J)
Q $TR(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ") ; - 0 = Print only total coverage
; ; - 1 = Break down by routine
COV(NMSP,COVCODE,VERBOSITY) ; VEN/SMH - PUBLIC ENTRY POINT; Coverage calculations ; - 2 = Break down by routine and tag
; NMSP: Namespace of the routines to analyze. End with * to include all routines. ; - 3 = Break down by routine and tag, and print lines that didn't execute for each tag.
; Not using * will only include the routine with NMSP name. ;
; e.g. PSOM* will include all routines starting with PSOM Q:'(+$SY=47) ; GT.M only!
; PSOM will only include PSOM. ;
; COVCODE: Mumps code to run over which coverage will be calculated. Typically Unit Tests. ; ZEXCEPT: CTRAP - not really a variable
; VERBOSITY (optional): Scalar from -1 to 3. S VERBOSITY=+$G(VERBOSITY) ; Get 0 if not passed.
; - -1 = Global output in ^TMP("%utCOVREPORT",$J) N %ZR ; GT.M specific
; - 0 = Print only total coverage D SILENT^%RSEL(NMSP,"SRC") ; GT.M specific. On Cache use $O(^$R(RTN)).
; - 1 = Break down by routine ;
; - 2 = Break down by routine and tag N RN S RN=""
; - 3 = Break down by routine and tag, and print lines that didn't execute for each tag. W "Loading routines to test coverage...",!
; F S RN=$O(%ZR(RN)) Q:RN="" W RN," " D
Q:'(+$SY=47) ; GT.M only! . N L2 S L2=$T(+2^@RN)
; . S L2=$TR(L2,$C(9,32)) ; Translate spaces and tabs out
; ZEXCEPT: CTRAP - not really a variable . I $E(L2,1,2)'=";;" K %ZR(RN) ; Not a human produced routine
S VERBOSITY=+$G(VERBOSITY) ; Get 0 if not passed. ;
N %ZR ; GT.M specific N RTNS M RTNS=%ZR
D SILENT^%RSEL(NMSP,"SRC") ; GT.M specific. On Cache use $O(^$R(RTN)). K %ZR
; ;
N RN S RN="" N GL
W "Loading routines to test coverage...",! S GL=$NA(^TMP("%utCOVCOHORT",$J))
F S RN=$O(%ZR(RN)) Q:RN="" W RN," " D K @GL
. N L2 S L2=$T(+2^@RN) D RTNANAL(.RTNS,GL)
. S L2=$TR(L2,$C(9,32)) ; Translate spaces and tabs out K ^TMP("%utCOVCOHORTSAV",$J)
. I $E(L2,1,2)'=";;" K %ZR(RN) ; Not a human produced routine M ^TMP("%utCOVCOHORTSAV",$J)=^TMP("%utCOVCOHORT",$J)
; ;
N RTNS M RTNS=%ZR ;
K %ZR K ^TMP("%utCOVRESULT",$J)
; VIEW "TRACE":1:$NA(^TMP("%utCOVRESULT",$J)) ; GT.M START PROFILING
N GL DO ; Run the code, but keep our variables to ourselves.
S GL=$NA(^TMP("%utCOVCOHORT",$J)) . NEW $ETRAP,$ESTACK
K @GL . SET $ETRAP="Q:($ES&$Q) -9 Q:$ES W ""CTRL-C ENTERED"""
D RTNANAL(.RTNS,GL) . USE $PRINCIPAL:(CTRAP=$C(3))
K ^TMP("%utCOVCOHORTSAV",$J) . NEW (DUZ,IO,COVCODE,U,DILOCKTM,DISYS,DT,DTIME,IOBS,IOF,IOM,ION,IOS,IOSL,IOST,IOT,IOXY)
M ^TMP("%utCOVCOHORTSAV",$J)=^TMP("%utCOVCOHORT",$J) . XECUTE COVCODE
; VIEW "TRACE":0:$NA(^TMP("%utCOVRESULT",$J)) ; GT.M STOP PROFILING
; ;
K ^TMP("%utCOVRESULT",$J) D COVCOV($NA(^TMP("%utCOVCOHORT",$J)),$NA(^TMP("%utCOVRESULT",$J))) ; Venn diagram matching between globals
VIEW "TRACE":1:$NA(^TMP("%utCOVRESULT",$J)) ; GT.M START PROFILING ;
DO ; Run the code, but keep our variables to ourselves. ; Report
. NEW $ETRAP,$ESTACK I VERBOSITY=-1 D
. SET $ETRAP="Q:($ES&$Q) -9 Q:$ES W ""CTRL-C ENTERED""" . K ^TMP("%utCOVREPORT",$J)
. USE $PRINCIPAL:(CTRAP=$C(3)) . D COVRPTGL($NA(^TMP("%utCOVCOHORTSAV",$J)),$NA(^TMP("%utCOVCOHORT",$J)),$NA(^TMP("%utCOVRESULT",$J)),$NA(^TMP("%utCOVREPORT",$J)))
. NEW (DUZ,IO,COVCODE,U,DILOCKTM,DISYS,DT,DTIME,IOBS,IOF,IOM,ION,IOS,IOSL,IOST,IOT,IOXY) E D COVRPT($NA(^TMP("%utCOVCOHORTSAV",$J)),$NA(^TMP("%utCOVCOHORT",$J)),$NA(^TMP("%utCOVRESULT",$J)),VERBOSITY)
. XECUTE COVCODE ;
VIEW "TRACE":0:$NA(^TMP("%utCOVRESULT",$J)) ; GT.M STOP PROFILING QUIT
; ;
D COVCOV($NA(^TMP("%utCOVCOHORT",$J)),$NA(^TMP("%utCOVRESULT",$J))) ; Venn diagram matching between globals RTNANAL(RTNS,GL) ; [Private] - Routine Analysis
; ; Create a global similar to the trace global produced by GT.M in GL
; Report ; Only non-comment lines are stored.
I VERBOSITY=-1 D ; A tag is always stored. Tag,0 is stored only if there is code on the tag line (format list or actual code).
. K ^TMP("%utCOVREPORT",$J) ; tags by themselves don't count toward the total.
. D COVRPTGL($NA(^TMP("%utCOVCOHORTSAV",$J)),$NA(^TMP("%utCOVCOHORT",$J)),$NA(^TMP("%utCOVRESULT",$J)),$NA(^TMP("%utCOVREPORT",$J))) ;
E D COVRPT($NA(^TMP("%utCOVCOHORTSAV",$J)),$NA(^TMP("%utCOVCOHORT",$J)),$NA(^TMP("%utCOVRESULT",$J)),VERBOSITY) N RTN S RTN=""
; F S RTN=$O(RTNS(RTN)) Q:RTN="" D ; for each routine
QUIT . N TAG
; . S TAG=RTN ; start the tags at the first
RTNANAL(RTNS,GL) ; [Private] - Routine Analysis . N I,LN F I=2:1 S LN=$T(@TAG+I^@RTN) Q:LN="" D ; for each line, starting with the 3rd line (2 off the first tag)
; Create a global similar to the trace global produced by GT.M in GL . . I $E(LN)?1A D QUIT ; formal line
; Only non-comment lines are stored. . . . N T ; Terminator
; A tag is always stored. Tag,0 is stored only if there is code on the tag line (format list or actual code). . . . N J F J=1:1:$L(LN) S T=$E(LN,J) Q:T'?1AN ; Loop to...
; tags by themselves don't count toward the total. . . . S TAG=$E(LN,1,J-1) ; Get tag
; . . . S @GL@(RTN,TAG)=TAG ; store line
N RTN S RTN="" . . . I T="(" S @GL@(RTN,TAG,0)=LN ; formal list
F S RTN=$O(RTNS(RTN)) Q:RTN="" D ; for each routine . . . E D ; No formal list
. N TAG . . . . N LNTR S LNTR=$P(LN,TAG,2,999),LNTR=$TR(LNTR,$C(9,32)) ; Get rest of line, Remove spaces and tabs
. S TAG=RTN ; start the tags at the first . . . . I $E(LNTR)=";" QUIT ; Comment
. N I,LN F I=2:1 S LN=$T(@TAG+I^@RTN) Q:LN="" D ; for each line, starting with the 3rd line (2 off the first tag) . . . . S @GL@(RTN,TAG,0)=LN ; Otherwise, store for testing
. . I $E(LN)?1A D QUIT ; formal line . . . S I=0 ; Start offsets from zero (first one at the for will be 1)
. . . N T ; Terminator . . I $C(32,9)[$E(LN) D QUIT ; Regular line
. . . N J F J=1:1:$L(LN) S T=$E(LN,J) Q:T'?1AN ; Loop to... . . . N LNTR S LNTR=$TR(LN,$C(32,9)) ; Remove all spaces and tabs
. . . S TAG=$E(LN,1,J-1) ; Get tag . . . I $E(LNTR)=";" QUIT ; Comment line -- don't want.
. . . S @GL@(RTN,TAG)=TAG ; store line . . . S @GL@(RTN,TAG,I)=LN ; Record line
. . . I T="(" S @GL@(RTN,TAG,0)=LN ; formal list QUIT
. . . E D ; No formal list ;
. . . . N LNTR S LNTR=$P(LN,TAG,2,999),LNTR=$TR(LNTR,$C(9,32)) ; Get rest of line, Remove spaces and tabs ACTLINES(GL) ; [Private] $$ ; Count active lines
. . . . I $E(LNTR)=";" QUIT ; Comment ;
. . . . S @GL@(RTN,TAG,0)=LN ; Otherwise, store for testing N CNT S CNT=0
. . . S I=0 ; Start offsets from zero (first one at the for will be 1) N REF S REF=GL
. . I $C(32,9)[$E(LN) D QUIT ; Regular line N GLQL S GLQL=$QL(GL)
. . . N LNTR S LNTR=$TR(LN,$C(32,9)) ; Remove all spaces and tabs F S REF=$Q(@REF) Q:REF="" Q:(GL'=$NA(@REF,GLQL)) D
. . . I $E(LNTR)=";" QUIT ; Comment line -- don't want. . N REFQL S REFQL=$QL(REF)
. . . S @GL@(RTN,TAG,I)=LN ; Record line . N LASTSUB S LASTSUB=$QS(REF,REFQL)
QUIT . I LASTSUB?1.N S CNT=CNT+1
; QUIT CNT
ACTLINES(GL) ; [Private] $$ ; Count active lines ;
; COVCOV(C,R) ; [Private] - Analyze coverage Cohort vs Result
N CNT S CNT=0 N RTN S RTN=""
N REF S REF=GL F S RTN=$O(@C@(RTN)) Q:RTN="" D ; For each routine in cohort set
N GLQL S GLQL=$QL(GL) . I '$D(@R@(RTN)) QUIT ; Not present in result set
F S REF=$Q(@REF) Q:REF="" Q:(GL'=$NA(@REF,GLQL)) D . N TAG S TAG=""
. N REFQL S REFQL=$QL(REF) . F S TAG=$O(@R@(RTN,TAG)) Q:TAG="" D ; For each tag in the routine in the result set
. N LASTSUB S LASTSUB=$QS(REF,REFQL) . . N LN S LN=""
. I LASTSUB?1.N S CNT=CNT+1 . . F S LN=$O(@R@(RTN,TAG,LN)) Q:LN="" D ; for each line in the tag in the routine in the result set
QUIT CNT . . . I $D(@C@(RTN,TAG,LN)) K ^(LN) ; if present in cohort, kill off
; QUIT
COVCOV(C,R) ; [Private] - Analyze coverage Cohort vs Result ;
N RTN S RTN="" COVRPT(C,S,R,V) ; [Private] - Coverage Report
F S RTN=$O(@C@(RTN)) Q:RTN="" D ; For each routine in cohort set ; C = COHORT - Global name
. I '$D(@R@(RTN)) QUIT ; Not present in result set ; S = SURVIVORS - Global name
. N TAG S TAG="" ; R = RESULT - Global name
. F S TAG=$O(@R@(RTN,TAG)) Q:TAG="" D ; For each tag in the routine in the result set ; V = Verbosity - Scalar from -1 to 3
. . N LN S LN="" N ORIGLINES S ORIGLINES=$$ACTLINES(C)
. . F S LN=$O(@R@(RTN,TAG,LN)) Q:LN="" D ; for each line in the tag in the routine in the result set N LEFTLINES S LEFTLINES=$$ACTLINES(S)
. . . I $D(@C@(RTN,TAG,LN)) K ^(LN) ; if present in cohort, kill off W !!
QUIT W "ORIG: "_ORIGLINES,!
; W "LEFT: "_LEFTLINES,!
COVRPT(C,S,R,V) ; [Private] - Coverage Report W "COVERAGE PERCENTAGE: "_$S(ORIGLINES:$J(ORIGLINES-LEFTLINES/ORIGLINES*100,"",2),1:100.00),!
; C = COHORT - Global name W !!
; S = SURVIVORS - Global name W "BY ROUTINE:",!
; R = RESULT - Global name I V=0 QUIT ; No verbosity. Don't print routine detail
; V = Verbosity - Scalar from -1 to 3 N RTN S RTN=""
N ORIGLINES S ORIGLINES=$$ACTLINES(C) F S RTN=$O(@C@(RTN)) Q:RTN="" D
N LEFTLINES S LEFTLINES=$$ACTLINES(S) . N O S O=$$ACTLINES($NA(@C@(RTN)))
W !! . N L S L=$$ACTLINES($NA(@S@(RTN)))
W "ORIG: "_ORIGLINES,! . W ?3,RTN,?21,$S(O:$J(O-L/O*100,"",2),1:"100.00"),!
W "LEFT: "_LEFTLINES,! . I V=1 QUIT ; Just print the routine coverage for V=1
W "COVERAGE PERCENTAGE: "_$S(ORIGLINES:$J(ORIGLINES-LEFTLINES/ORIGLINES*100,"",2),1:100.00),! . N TAG S TAG=""
W !! . F S TAG=$O(@C@(RTN,TAG)) Q:TAG="" D
W "BY ROUTINE:",! . . N O S O=$$ACTLINES($NA(@C@(RTN,TAG)))
I V=0 QUIT ; No verbosity. Don't print routine detail . . N L S L=$$ACTLINES($NA(@S@(RTN,TAG)))
N RTN S RTN="" . . W ?5,TAG,?21,$S(O:$J(O-L/O*100,"",2),1:"100.00"),!
F S RTN=$O(@C@(RTN)) Q:RTN="" D . . I V=2 QUIT ; Just print routine/tags coverage for V=2; V=3 print uncovered lines
. N O S O=$$ACTLINES($NA(@C@(RTN))) . . N LN S LN=""
. N L S L=$$ACTLINES($NA(@S@(RTN))) . . F S LN=$O(@S@(RTN,TAG,LN)) Q:LN="" W TAG_"+"_LN_": "_^(LN),!
. W ?3,RTN,?21,$S(O:$J(O-L/O*100,"",2),1:"100.00"),! QUIT
. I V=1 QUIT ; Just print the routine coverage for V=1 ;
. N TAG S TAG="" COVRPTGL(C,S,R,OUT) ; [Private] - Coverage Global for silent invokers
. F S TAG=$O(@C@(RTN,TAG)) Q:TAG="" D ; C = COHORT - Global name
. . N O S O=$$ACTLINES($NA(@C@(RTN,TAG))) ; S = SURVIVORS - Global name
. . N L S L=$$ACTLINES($NA(@S@(RTN,TAG))) ; R = RESULT - Global name
. . W ?5,TAG,?21,$S(O:$J(O-L/O*100,"",2),1:"100.00"),! ; OUT = OUTPUT - Global name
. . I V=2 QUIT ; Just print routine/tags coverage for V=2; V=3 print uncovered lines ;
. . N LN S LN="" N O S O=$$ACTLINES(C)
. . F S LN=$O(@S@(RTN,TAG,LN)) Q:LN="" W TAG_"+"_LN_": "_^(LN),! N L S L=$$ACTLINES(S)
QUIT S @OUT=(O-L)_"/"_O
; N RTN,TAG,LN S (RTN,TAG,LN)=""
COVRPTGL(C,S,R,OUT) ; [Private] - Coverage Global for silent invokers F S RTN=$O(@C@(RTN)) Q:RTN="" D
; C = COHORT - Global name . N O S O=$$ACTLINES($NA(@C@(RTN)))
; S = SURVIVORS - Global name . N L S L=$$ACTLINES($NA(@S@(RTN)))
; R = RESULT - Global name . S @OUT@(RTN)=(O-L)_"/"_O
; OUT = OUTPUT - Global name . F S TAG=$O(@C@(RTN,TAG)) Q:TAG="" D
; . . N O S O=$$ACTLINES($NA(@C@(RTN,TAG)))
N O S O=$$ACTLINES(C) . . N L S L=$$ACTLINES($NA(@S@(RTN,TAG)))
N L S L=$$ACTLINES(S) . . S @OUT@(RTN,TAG)=(O-L)_"/"_O
S @OUT=(O-L)_"/"_O . . F S LN=$O(@S@(RTN,TAG,LN)) Q:LN="" S @OUT@(RTN,TAG,LN)=@S@(RTN,TAG,LN)
N RTN,TAG,LN S (RTN,TAG,LN)="" QUIT
F S RTN=$O(@C@(RTN)) Q:RTN="" D ;
. N O S O=$$ACTLINES($NA(@C@(RTN))) TESTCOVR ; entry under coverage analysis
. N L S L=$$ACTLINES($NA(@S@(RTN))) D ENTRY^%uttcovr ; does analysis while running various unit tests
. S @OUT@(RTN)=(O-L)_"/"_O Q
. F S TAG=$O(@C@(RTN,TAG)) Q:TAG="" D ;
. . N O S O=$$ACTLINES($NA(@C@(RTN,TAG)))
. . N L S L=$$ACTLINES($NA(@S@(RTN,TAG)))
. . S @OUT@(RTN,TAG)=(O-L)_"/"_O
. . F S LN=$O(@S@(RTN,TAG,LN)) Q:LN="" S @OUT@(RTN,TAG,LN)=@S@(RTN,TAG,LN)
QUIT
;
TESTCOVR ; entry under coverage analysis
D ENTRY^%uttcovr ; does analysis while running various unit tests
Q
;

138
Routines/%utcover.m Normal file
View File

@ -0,0 +1,138 @@
%utcover ;JLI - generic coverage and unit test runner ;07/02/15 09:56
;;1.0;MASH UTILITIES;;
;
Q
;
TESTONLY(TESTROUS) ; RUN TESTS FOR SPECIFIED ROUTINES
; input TESTROUS - passed by reference - array of routine names to run tests for
; specify those to be called directly by including ^ as part of
; TAG^ROUTINE or ^ROUTINE.
; ROUTINE names without a ^ will be called as EN^%ut("ROUTINE")
; Sometimes to get complete coverage, different entry points may
; need to be called (e.g., at top and for VERBOSE), these should each
; be included.
; If the subscript is a number, it will take the list of comma separated
; values as the routines. If the the subscript is not a number, it will
; take it as a routine to be added to the list, then if the value of the
; contains a comma separated list of routines, they will be added as well.
; Thus a value of
; TESTROUS(1)="A^ROU1,^ROU1,^ROU2,ROU3"
; or a value of
; TESTROUS("A^ROU1")="^ROU1,^ROU2,ROU3"
; will both result in tests for
; D A^ROU1,^ROU1,^ROU2,EN^%ut("ROU3")
K ^TMP("%utCOVER",$J,"TESTROUS")
M ^TMP("%utCOVER",$J,"TESTROUS")=TESTROUS
;
COVENTRY ; setup of COVERAGE NEWs most variables, so TESTROUS passed by global
;
N I,ROU,VAL,VALS,UTDATA,TESTS,TESTROUS
M TESTROUS=^TMP("%utCOVER",$J,"TESTROUS")
S ROU="" F S ROU=$O(TESTROUS(ROU)) Q:ROU="" D
. I ROU'=+ROU S TESTS(ROU)=""
. F I=1:1 S VAL=$P(TESTROUS(ROU),",",I) Q:VAL="" S TESTS(VAL)=""
. Q
S ROU="" F S ROU=$O(TESTS(ROU)) Q:ROU="" D
. W !!,"RUNNING ",ROU
. I ROU[U D @ROU
. I ROU'[U D @("EN^%ut("""_ROU_""")")
. S VALS=$G(^TMP("%ut",$J,"UTVALS")) I VALS="" Q
. F I=1:1 S VAL=$P(VALS,U,I) Q:VAL="" S UTDATA(I)=$G(UTDATA(I))+VAL
. K ^TMP("%ut",$J,"UTVALS")
. Q
I $D(UTDATA) D
. W !!!,"------------ SUMMARY ------------"
. W !,"Ran ",UTDATA(1)," Routine",$S(UTDATA(1)>1:"s",1:""),", ",UTDATA(2)," Entry Tag",$S(UTDATA(2)>1:"s",1:"")
. W !,"Checked ",UTDATA(3)," test",$S(UTDATA(3)>1:"s",1:""),", with ",UTDATA(4)," failure",$S(UTDATA(4)'=1:"s",1:"")," and encountered ",UTDATA(5)," error",$S(UTDATA(5)'=1:"s",1:""),"."
. Q
K ^TMP("%utCOVER",$J,"TESTROUS")
Q
;
COVERAGE(ROUNMSP,TESTROUS,XCLDROUS,RESLTLVL) ; run coverage analysis
; input ROUNMSP - Namespace for routine(s) to be analyzed
; ROUNAME will result in only the routine ROUNAME being analyzed
; ROUN* will result in all routines beginning with ROUN being analyzed
; input TESTROUS - passed by reference - see TESTROUS description for JUSTTEST
; input XCLDROUS - passed by reference - routines passed in a manner similar to TESTROUS,
; but only the routine names, whether as arguments or a comma separated
; list of routines, will be excluded from the analysis of coverage. These
; would normally be names of routines which are only for unit tests, or
; others which should not be included in the analysis for some reason.
; input RESLTLVL - This value determines the amount of information to be generated for the
; analysis. A missing or null value will be considered to be level 1
; 1 - Listing of analysis only for routine overall
; 2 - Listing of analysis for routine overall and for each TAG
; 3 - Full analysis for each tag, and lists out those lines which were
; not executed during the analysis
;
N I,ROU,TYPE,VAL,XCLUDE
S RESLTLVL=$G(RESLTLVL,1)
I RESLTLVL<1 S RESLTLVL=1
I RESLTLVL>3 S RESLTLVL=3
M ^TMP("%utCOVER",$J,"TESTROUS")=TESTROUS ;
D COV^%ut(ROUNMSP,"D COVENTRY^%utCOVER",-1)
K ^TMP("%utCOVER",$J,"TESTROUS")
S ROU="" F S ROU=$O(XCLDROUS(ROU)) Q:ROU="" D
. I ROU'=+ROU S XCLUDE(ROU)=""
. F I=1:1 S VAL=$P(XCLDROUS(ROU),",",I) Q:VAL="" S XCLUDE(VAL)=""
. Q
D LIST(.XCLUDE,RESLTLVL)
Q
;
LIST(XCLDROUS,TYPE) ;
; ZEXCEPT: TYPE1 - NEWed and set below for recursion
; input - ROULIST - a comma separated list of routine names that will
; be used to identify desired routines. Any name
; that begins with one of the specified values will
; be included
; input - TYPE - value indicating amount of detail desired
; 1=summary with listing by routine
; 2=moderate with listing by tags
; 3=full with listing of untouched lines
;
N CURRCOV,CURRLIN,LINCOV,LINE,LINTOT,ROULIST,ROUNAME,TAG,TOTCOV,TOTLIN,XVAL
;
D TRIMDATA(.XCLDROUS) ; remove undesired routines from data
;
N JOB,NAME,BASE,GLOB
S GLOB=$NA(^TMP("%utCOVREPORT",$J))
S TOTCOV=0,TOTLIN=0
; F NAME="%utCOVREPORT","%utCOVRESULT","%utCOVCOHORT","%utCOVCOHORTSAV" D
I TYPE>1 S ROUNAME="" F S ROUNAME=$O(@GLOB@(ROUNAME)) Q:ROUNAME="" S XVAL=^(ROUNAME) D
. S CURRCOV=$P(XVAL,"/"),CURRLIN=$P(XVAL,"/",2)
. W !!,"Routine ",ROUNAME," ",CURRCOV," out of ",CURRLIN," lines covered"
. I CURRLIN>0 W " (",$P((100*CURRCOV)/CURRLIN,"."),"%)"
. I TYPE=2 W " - Summary"
. S TAG="" F S TAG=$O(@GLOB@(ROUNAME,TAG)) Q:TAG="" S XVAL=^(TAG) D
. . S LINCOV=$P(XVAL,"/"),LINTOT=$P(XVAL,"/",2)
. . W !," Tag ",TAG,"^",ROUNAME," ",LINCOV," out of ",LINTOT," lines covered"
. . I TYPE=2 Q
. . I LINCOV=LINTOT Q
. . W !," the following is a list of lines NOT covered"
. . S LINE="" F S LINE=$O(@GLOB@(ROUNAME,TAG,LINE)) Q:LINE="" D
. . . I LINE=0 W !," ",TAG," ",@GLOB@(ROUNAME,TAG,LINE) Q
. . . W !," ",TAG,"+",LINE," ",@GLOB@(ROUNAME,TAG,LINE)
. . . Q
. . Q
. Q
; for type=3 generate a summary at bottom after detail
I TYPE=3 N TYPE1 S TYPE1=2 D LIST(.XCLDROUS,2) K TYPE1
I TYPE=2,$G(TYPE1) Q ; CAME IN FROM ABOVE LINE
; summarize by just routine name
W !!
S ROUNAME="" F S ROUNAME=$O(@GLOB@(ROUNAME)) Q:ROUNAME="" S XVAL=^(ROUNAME) D
. S CURRCOV=$P(XVAL,"/"),CURRLIN=$P(XVAL,"/",2)
. S TOTCOV=TOTCOV+CURRCOV,TOTLIN=TOTLIN+CURRLIN
. W !,"Routine ",ROUNAME," ",CURRCOV," out of ",CURRLIN," lines covered"
. I CURRLIN>0 W " (",$P((100*CURRCOV)/CURRLIN,"."),"%)"
W !!,"Overall Analysis ",TOTCOV," out of ",TOTLIN," lines covered"
I TOTLIN>0 W " (",$P((100*TOTCOV)/TOTLIN,"."),"% coverage)"
Q
;
TRIMDATA(ROULIST) ;
N TYPNAME,ROUNAME
F TYPNAME="%utCOVREPORT","%utCOVRESULT","%utCOVCOHORT","%utCOVCOHORTSAV" D
. S ROUNAME="" F S ROUNAME=$O(ROULIST(ROUNAME)) Q:ROUNAME="" K ^TMP(TYPNAME,$J,ROUNAME)
. Q
Q
;

View File

@ -1,149 +1,150 @@
%utt1 ; VEN/SMH - Testing routines for M-Unit;08/28/14 11:42 %utt1 ; VEN/SMH - Testing routines for M-Unit;08/29/14 11:35
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
%utNITT ; VEN/SMH - Testing routines for M-Unit;2014-04-01 2:04 PM %utNITT ; VEN/SMH - Testing routines for M-Unit;2014-04-01 2:04 PM
; ;
; THIS ROUTINE IS THE UNIFIED UNIT TESTER FOR ALL OF M-UNIT. ; THIS ROUTINE IS THE UNIFIED UNIT TESTER FOR ALL OF M-UNIT.
; ;
; Dear Users, ; Dear Users,
; ;
; I know about about the irony of a test suite for the testing suite, ; I know about about the irony of a test suite for the testing suite,
; so stop snikering. Aside from that, it's actually going to be hard. ; so stop snikering. Aside from that, it's actually going to be hard.
; ;
; Truly yours, ; Truly yours,
; ;
; Sam H ; Sam H
; ;
D EN^%ut($T(+0),1) ; Run tests here, be verbose. D EN^%ut($T(+0),1) ; Run tests here, be verbose.
QUIT QUIT
; ;
STARTUP ; M-Unit Start-Up - This runs before anything else. STARTUP ; M-Unit Start-Up - This runs before anything else.
S ^TMP($J,"%ut","STARTUP")="" S ^TMP($J,"%ut","STARTUP")=""
S KBANCOUNT=1 S KBANCOUNT=1
QUIT QUIT
; ;
SHUTDOWN ; M-Unit Shutdown - This runs after everything else is done. SHUTDOWN ; M-Unit Shutdown - This runs after everything else is done.
K ^TMP($J,"%ut","STARTUP") K ^TMP($J,"%ut","STARTUP")
K KBANCOUNT K KBANCOUNT
QUIT QUIT
; ;
; ;
; ;
SETUP ; This runs before every test. SETUP ; This runs before every test.
S KBANCOUNT=KBANCOUNT+1 S KBANCOUNT=KBANCOUNT+1
QUIT QUIT
; ;
TEARDOWN ; This runs after every test TEARDOWN ; This runs after every test
S KBANCOUNT=KBANCOUNT-1 S KBANCOUNT=KBANCOUNT-1
QUIT QUIT
; ;
; ;
; ;
T1 ; @TEST - Make sure Start-up Ran T1 ; @TEST - Make sure Start-up Ran
D CHKTF($D(^TMP($J,"%ut","STARTUP")),"Start-up node on ^TMP must exist") D CHKTF($D(^TMP($J,"%ut","STARTUP")),"Start-up node on ^TMP must exist")
QUIT QUIT
; ;
T2 ; @TEST - Make sure Set-up runs T2 ; @TEST - Make sure Set-up runs
D CHKEQ(KBANCOUNT,2,"KBANCount not incremented properly at SETUP") D CHKEQ(KBANCOUNT,2,"KBANCount not incremented properly at SETUP")
QUIT QUIT
; ;
T3 ; @TEST - Make sure Teardown runs T3 ; @TEST - Make sure Teardown runs
D CHKEQ(KBANCOUNT,2,"KBANCount not decremented properly at TEARDOWN") D CHKEQ(KBANCOUNT,2,"KBANCount not decremented properly at TEARDOWN")
QUIT QUIT
; ;
T4 ; Specified in XTMTAG T4 ; Specified in XTMTAG
; 140731 JLI - note that this will fail when run from the GUI runner, since it calls each tag separately ; 140731 JLI - note that this will fail when run from the GUI runner, since it calls each tag separately
I $G(%utGUI) D CHKEQ(%utETRY,"T4","T4 should be the value for %utETRY in the GUI Runner") I $G(%utGUI) D CHKEQ(%utETRY,"T4","T4 should be the value for %utETRY in the GUI Runner")
I '$G(%utGUI) D CHKEQ(%utETRY(4),"T4","T4 should be the collected as the fourth entry in %utETRY") I '$G(%utGUI) D CHKEQ(%utETRY(4),"T4","T4 should be the collected as the fourth entry in %utETRY")
QUIT QUIT
; ;
T5 ; ditto T5 ; ditto
D CHKTF(0,"This is an intentional failure.") D CHKTF(0,"This is an intentional failure.")
D CHKEQ(%ut("FAIL"),1,"By this point, we should have failed one test") D CHKEQ(%ut("FAIL"),1,"By this point, we should have failed one test")
D FAIL^%ut("Intentionally throwing a failure") D FAIL^%ut("Intentionally throwing a failure")
D CHKEQ(%ut("FAIL"),2,"By this point, we should have failed two tests") D CHKEQ(%ut("FAIL"),2,"By this point, we should have failed two tests")
; S %ut("FAIL")=0 ; Okay... Boy's and Girls... as the developer I can do that. ; S %ut("FAIL")=0 ; Okay... Boy's and Girls... as the developer I can do that.
QUIT QUIT
; ;
T6 ; ditto T6 ; ditto
N TESTCOUNT S TESTCOUNT=%ut("CHK") N TESTCOUNT S TESTCOUNT=%ut("CHK")
D SUCCEED^%ut D SUCCEED^%ut
D SUCCEED^%ut D SUCCEED^%ut
D CHKEQ(%ut("CHK"),TESTCOUNT+2,"Succeed should increment the number of tests") D CHKEQ(%ut("CHK"),TESTCOUNT+2,"Succeed should increment the number of tests")
QUIT QUIT
; ;
T7 ; Make sure we write to principal even though we are on another device T7 ; Make sure we write to principal even though we are on another device
; This is a rather difficult test to carry out for GT.M and Cache... ; This is a rather difficult test to carry out for GT.M and Cache...
N D N D
I +$SY=47 S D="/tmp/test.txt" ; All GT.M ; VMS not supported. I +$SY=47 S D="/tmp/test.txt" ; All GT.M ; VMS not supported.
I +$SY=0 D ; All Cache I +$SY=0 D ; All Cache
. I $ZVERSION(1)=2 S D=$SYSTEM.Util.GetEnviron("temp")_"\test.txt" I 1 ; Windows . I $ZVERSION(1)=2 S D=$SYSTEM.Util.GetEnviron("temp")_"\test.txt" I 1 ; Windows
. E S D="/tmp/test.txt" ; not windows; VMS not supported. . E S D="/tmp/test.txt" ; not windows; VMS not supported.
I +$SY=0 O D:"NWS" ; Cache new file I +$SY=0 O D:"NWS" ; Cache new file
I +$SY=47 O D:(newversion) ; GT.M new file I +$SY=47 O D:(newversion) ; GT.M new file
U D U D
WRITE "HELLO",! WRITE "HELLO",!
WRITE "HELLO",! WRITE "HELLO",!
C D C D
; ;
; Now open back the file, and read the hello, but open in read only so ; Now open back the file, and read the hello, but open in read only so
; M-Unit will error out if it will write something out there. ; M-Unit will error out if it will write something out there.
; ;
; Per VISTA conventions, current IO device should be IO, old is IO(0). ; Per VISTA conventions, current IO device should be IO, old is IO(0).
; ;
I +$SY=0 O D:"R" I +$SY=0 O D:"R"
I +$SY=47 O D:(readonly) I +$SY=47 O D:(readonly)
U D U D
N X READ X:1 N X READ X:1
D CHKTF(X="HELLO") ; This should write to the screen the dot not to the file. D CHKTF(X="HELLO") ; This should write to the screen the dot not to the file.
D CHKTF(($$LO($IO)=$$LO(D)),"IO device didn't get reset back") ; $$LO is b/c of a bug in Cache/Windows. $IO is not the same cas D. D CHKTF(($$LO($IO)=$$LO(D)),"IO device didn't get reset back") ; $$LO is b/c of a bug in Cache/Windows. $IO is not the same cas D.
I +$SY=0 C D:"D" I +$SY=0 C D:"D"
I +$SY=47 C D:(delete) I +$SY=47 C D:(delete)
U $P U $P
S IO=$IO S IO=$IO
QUIT QUIT
; ;
; At the moment T8^%utt1 throws a fail, with no message ; At the moment T8^%utt1 throws a fail, with no message
; in the GUI runner. For some reason, both X and Y ; in the GUI runner. For some reason, both X and Y
; variables are returned as null strings, while in the ; variables are returned as null strings, while in the
; command line runner, Y has a value containing the ; command line runner, Y has a value containing the
; word being sought ; word being sought
; ;
T8 ; If IO starts with another device, write to that device as if it's the pricipal device T8 ; If IO starts with another device, write to that device as if it's the pricipal device
N D N D
I +$SY=47 S D="/tmp/test.txt" ; All GT.M ; VMS not supported. I +$SY=47 S D="/tmp/test.txt" ; All GT.M ; VMS not supported.
I +$SY=0 D ; All Cache I +$SY=0 D ; All Cache
. I $ZVERSION(1)=2 S D=$SYSTEM.Util.GetEnviron("temp")_"\test.txt" I 1 ; Windows . I $ZVERSION(1)=2 S D=$SYSTEM.Util.GetEnviron("temp")_"\test.txt" I 1 ; Windows
. E S D="/tmp/test.txt" ; not windows; VMS not supported. . E S D="/tmp/test.txt" ; not windows; VMS not supported.
I +$SY=0 O D:"NWS" ; Cache new file I +$SY=0 O D:"NWS" ; Cache new file
I +$SY=47 O D:(newversion) ; GT.M new file I +$SY=47 O D:(newversion) ; GT.M new file
S IO=D S IO=D
U D U D
D ^%utt4 ; Run some Unit Tests D ^%utt4 ; Run some Unit Tests
C D C D
I +$SY=0 O D:"R" ; Cache read only I +$SY=0 O D:"R" ; Cache read only
I +$SY=47 O D:(readonly) ; GT.M read only I +$SY=47 O D:(readonly) ; GT.M read only
U D U D
N X,Y R X:1,Y:1 N X,Y,Z R X:1,Y:1,Z:1
I +$SY=0 C D:"D" I +$SY=0 C D:"D"
I +$SY=47 C D:(delete) I +$SY=47 C D:(delete)
D CHKTF(Y["MAIN") ;D CHKTF(Y["MAIN") ; JLI 140829 commented out, gui doesn't run verbose
S IO=$P D CHKTF((Y["MAIN")!(Z["Ran 1 Routine"),"Write to system during test didn't work")
QUIT S IO=$P
; QUIT
LO(X) Q $TR(X,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz") ;
; Shortcut methods for M-Unit LO(X) Q $TR(X,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")
CHKTF(X,Y) D CHKTF^%ut(X,$G(Y)) QUIT ; Shortcut methods for M-Unit
CHKEQ(A,B,M) D CHKEQ^%ut(A,B,$G(M)) QUIT CHKTF(X,Y) D CHKTF^%ut(X,$G(Y)) QUIT
; CHKEQ(A,B,M) D CHKEQ^%ut(A,B,$G(M)) QUIT
XTENT ; Entry points ;
;;T4;Entry point using XTMENT XTENT ; Entry points
;;T5;Error count check ;;T4;Entry point using XTMENT
;;T6;Succeed Entry Point ;;T5;Error count check
;;T7;Make sure we write to principal even though we are on another device ;;T6;Succeed Entry Point
;;T8;If IO starts with another device, write to that device as if it's the pricipal device ;;T7;Make sure we write to principal even though we are on another device
; ;;T8;If IO starts with another device, write to that device as if it's the pricipal device
XTROU ; Routines containing additional tests ;
;;%utt2; old %utNITU XTROU ; Routines containing additional tests
;;%utt4; old %utNITW ;;%utt2; old %utNITU
;;%utt5; ;;%utt4; old %utNITW
;;%utt6; ;;%utt5;
;;%utt6;

View File

@ -1,12 +1,12 @@
%utt2 ; VEN/SMH - Bad Ass Continuation of Unit Tests;08/04/14 09:12 %utt2 ; VEN/SMH - Bad Ass Continuation of Unit Tests;08/04/14 09:12
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
XTMUNITU ; VEN/SMH - Bad Ass Continuation of Unit Tests;2014-04-01 1:03 PM XTMUNITU ; VEN/SMH - Bad Ass Continuation of Unit Tests;2014-04-01 1:03 PM
; ;
T11 ; @TEST An @TEST Entry point in Another Routine invoked through XTROU offsets T11 ; @TEST An @TEST Entry point in Another Routine invoked through XTROU offsets
D CHKTF^%ut(1) D CHKTF^%ut(1)
QUIT QUIT
T12 ; T12 ;
D CHKTF^%ut(1) D CHKTF^%ut(1)
QUIT QUIT
XTENT ; XTENT ;
;;T12;An XTENT offset entry point in Another Routine invoked through XTROU offsets ;;T12;An XTENT offset entry point in Another Routine invoked through XTROU offsets

View File

@ -1,43 +1,43 @@
%utt3 ; VEN/SMH - Unit Tests Coverage Tests;08/14/14 14:02 %utt3 ; VEN/SMH - Unit Tests Coverage Tests;08/14/14 14:02
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
XTMUNITV ; VEN/SMH - Unit Tests Coverage Tests;2014-04-16 7:14 PM XTMUNITV ; VEN/SMH - Unit Tests Coverage Tests;2014-04-16 7:14 PM
; ;
; *** BE VERY CAREFUL IN MODIFIYING THIS ROUTINE *** ; *** BE VERY CAREFUL IN MODIFIYING THIS ROUTINE ***
; *** THE UNIT TEST COUNTS ACTIVE AND INACTIVE LINES OF CODE *** ; *** THE UNIT TEST COUNTS ACTIVE AND INACTIVE LINES OF CODE ***
; *** IF YOU MODIFY THIS, MODIFY XTMUNITW AS WELL *** ; *** IF YOU MODIFY THIS, MODIFY XTMUNITW AS WELL ***
; ;
; Coverage tester in %utt4 ; Coverage tester in %utt4
; 20 Lines of code ; 20 Lines of code
; 5 do not run as they are dead code ; 5 do not run as they are dead code
; Expected Coverage: 15/20 = 75% ; Expected Coverage: 15/20 = 75%
; ;
STARTUP ; Doesn't count STARTUP ; Doesn't count
N X ; Counts N X ; Counts
S X=1 ; Counts S X=1 ; Counts
QUIT ; Counts QUIT ; Counts
; ;
SHUTDOWN K X,Y QUIT ; Counts; ZEXCEPT: X,Y SHUTDOWN K X,Y QUIT ; Counts; ZEXCEPT: X,Y
; ;
SETUP S Y=$G(Y)+1 QUIT ; Counts SETUP S Y=$G(Y)+1 QUIT ; Counts
; ;
TEARDOWN ; Doesn't count TEARDOWN ; Doesn't count
S Y=Y-1 ; Counts S Y=Y-1 ; Counts
QUIT ; Counts QUIT ; Counts
; ;
T1 ; @TEST Test 1 T1 ; @TEST Test 1
D CHKTF^%ut($D(Y)) ; Counts D CHKTF^%ut($D(Y)) ; Counts
QUIT ; Counts QUIT ; Counts
; ;
T2 ; @TEST Test 2 T2 ; @TEST Test 2
D INTERNAL(1) ; Counts D INTERNAL(1) ; Counts
D CHKTF^%ut(1) ; Counts D CHKTF^%ut(1) ; Counts
QUIT ; Counts QUIT ; Counts
S X=1 ; Dead code S X=1 ; Dead code
QUIT ; Dead code QUIT ; Dead code
; ;
INTERNAL(A) ; Counts INTERNAL(A) ; Counts
S A=A+1 ; Counts S A=A+1 ; Counts
QUIT ; Counts QUIT ; Counts
S A=2 ; Dead code S A=2 ; Dead code
S Y=2 ; Dead code S Y=2 ; Dead code
QUIT ; Dead code QUIT ; Dead code

View File

@ -1,22 +1,21 @@
%utt4 ; VEN/SMH - Coverage Test Runner;2014-08-28 8:37 PM %utt4 ; VEN/SMH - Coverage Test Runner;08/23/14 08:33
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
XTMUNITW ; VEN/SMH - Coverage Test Runner;2014-04-17 3:30 PM XTMUNITW ; VEN/SMH - Coverage Test Runner;2014-04-17 3:30 PM
;;7.3;KERNEL TOOLKIT;; ;;7.3;KERNEL TOOLKIT;;
; ;
; This tests code in XTMUNITV for coverage ; This tests code in XTMUNITV for coverage
D EN^%ut($T(+0),1) QUIT D EN^%ut($T(+0),1) QUIT
; ;
MAIN ; @TEST - Test coverage calculations MAIN ; @TEST - Test coverage calculations
Q:$D(^TMP("%uttcovr",$J)) ; already running coverage analysis from %uttcovr Q:$D(^TMP("%uttcovr",$J)) ; already running coverage analysis from %uttcovr
Q:$$ISUTEST^%ut ; already running a unit test Q:'(+$SY=47) ; GT.M ONLY
Q:'(+$SY=47) ; GT.M ONLY ;D COV^%ut1("XTMUNITV","D EN^%ut(""XTMUNITV"",1)",-1) ; Only produce output global.
;D COV^%ut1("XTMUNITV","D EN^%ut(""XTMUNITV"",1)",-1) ; Only produce output global. D COV^%ut1("%utt3","D EN^%ut(""%utt3"",1)",-1) ; Only produce output global.
D COV^%ut1("%utt3","D EN^%ut(""%utt3"",1)",-1) ; Only produce output global. D CHKEQ^%ut(^TMP("%utCOVREPORT",$J),"15/20")
D CHKEQ^%ut(^TMP("%utCOVREPORT",$J),"15/20") ;D CHKEQ^%ut(^TMP("XTMCOVREPORT",$J,"XTMUNITV","INTERNAL"),"3/6")
;D CHKEQ^%ut(^TMP("XTMCOVREPORT",$J,"XTMUNITV","INTERNAL"),"3/6") D CHKEQ^%ut(^TMP("%utCOVREPORT",$J,"%utt3","INTERNAL"),"3/6")
D CHKEQ^%ut(^TMP("%utCOVREPORT",$J,"%utt3","INTERNAL"),"3/6") ;D CHKTF^%ut($D(^TMP("XTMCOVREPORT",$J,"XTMUNITV","T2",4)))
;D CHKTF^%ut($D(^TMP("XTMCOVREPORT",$J,"XTMUNITV","T2",4))) D CHKTF^%ut($D(^TMP("%utCOVREPORT",$J,"%utt3","T2",4)))
D CHKTF^%ut($D(^TMP("%utCOVREPORT",$J,"%utt3","T2",4))) ;D CHKEQ^%ut(^TMP("XTMCOVREPORT",$J,"XTMUNITV","SETUP"),"1/1")
;D CHKEQ^%ut(^TMP("XTMCOVREPORT",$J,"XTMUNITV","SETUP"),"1/1") D CHKEQ^%ut(^TMP("%utCOVREPORT",$J,"%utt3","SETUP"),"1/1")
D CHKEQ^%ut(^TMP("%utCOVREPORT",$J,"%utt3","SETUP"),"1/1") QUIT
QUIT

View File

@ -1,123 +1,135 @@
%utt5 ;JLI - test for aspects of MUnit functionality ;08/24/14 21:31 %utt5 ;JLI - test for aspects of MUnit functionality ;08/29/14 11:23
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
Q Q
; ;
OLDSTYLE ; OLDSTYLE ;
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
I $D(%utt6var) S %ut("ENT")="OLDSTYLE",%utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"OLDSTYLE")="" I $D(%utt6var) S %ut("ENT")="OLDSTYLE",%utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"OLDSTYLE")=""
D CHKEQ^%ut(5,5,"SET EQUAL ON PURPOSE - OLDSTYLE DONE") D CHKEQ^%ut(5,5,"SET EQUAL ON PURPOSE - OLDSTYLE DONE")
D CHKTF^%ut(4=4,"MY EQUAL VALUE") D CHKTF^%ut(4=4,"MY EQUAL VALUE")
Q Q
; ;
OLDSTYL1 ; OLDSTYL1 ;
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
I $D(%utt6var) S %ut("ENT")="OLDSTYL1",%utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"OLDSTYL1")="" I $D(%utt6var) S %ut("ENT")="OLDSTYL1",%utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"OLDSTYL1")=""
D CHKEQ^%ut(4,4,"SET EQUAL ON PURPOSE - OLDSTYL1 DONE") D CHKEQ^%ut(4,4,"SET EQUAL ON PURPOSE - OLDSTYL1 DONE")
Q Q
; ;
NEWSTYLE ; @TEST identify new style test indicator functionality NEWSTYLE ; @TEST identify new style test indicator functionality
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
I $D(%utt6var) S %ut("ENT")="NEWSTYLE" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"NEWSTYLE")="" I $D(%utt6var) S %ut("ENT")="NEWSTYLE" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"NEWSTYLE")=""
D CHKEQ^%ut(4,4,"SET EQUAL ON PURPOSE - NEWSTYLE DONE") D CHKEQ^%ut(4,4,"SET EQUAL ON PURPOSE - NEWSTYLE DONE")
Q Q
; ;
BADCHKEQ ; BADCHKEQ ;
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
I $D(%utt6var) S %ut("ENT")="BADCHKEQ" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADCHKEQ")="" I $D(%utt6var) S %ut("ENT")="BADCHKEQ" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADCHKEQ")=""
D CHKEQ^%ut(4,3,"SET UNEQUAL ON PURPOSE - SHOULD FAIL") D CHKEQ^%ut(4,3,"SET UNEQUAL ON PURPOSE - SHOULD FAIL")
Q Q
; ;
BADCHKTF ; BADCHKTF ;
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
I $D(%utt6var) S %ut("ENT")="BADCHKTF" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADCHKTF")="" I $D(%utt6var) S %ut("ENT")="BADCHKTF" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADCHKTF")=""
D CHKTF^%ut(0,"SET FALSE (0) ON PURPOSE - SHOULD FAIL") D CHKTF^%ut(0,"SET FALSE (0) ON PURPOSE - SHOULD FAIL")
Q Q
; ;
BADERROR ; BADERROR ;
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
N X N X
I $D(%utt6var) S %ut("ENT")="BADERROR" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADERROR")="" I $D(%utt6var) S %ut("ENT")="BADERROR" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADERROR")=""
; following syntax error is on purpose to throw an error ; following syntax error is on purpose to throw an error
S X= ; syntax error on purpose S X= ; syntax error on purpose
Q Q
; ;
CALLFAIL ; CALLFAIL ;
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
N X N X
I $D(%utt6var) S %ut("ENT")="CALLFAIL" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"CALLFAIL")="" I $D(%utt6var) S %ut("ENT")="CALLFAIL" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"CALLFAIL")=""
D FAIL^%ut("Called FAIL to test it") D FAIL^%ut("Called FAIL to test it")
Q Q
; ;
LEAKSOK ; LEAKSOK ;
N CODE,LOCATN,MYVALS,X N CODE,LOCATN,MYVALS,X
S CODE="S X=$$NOW^XLFDT()",LOCATN="LEAKSOK TEST",MYVALS("X")="" S CODE="S X=$$NOW^XLFDT()",LOCATN="LEAKSOK TEST",MYVALS("X")=""
D CHKLEAKS^%ut(CODE,LOCATN,.MYVALS) ; should find no leaks D CHKLEAKS^%ut(CODE,LOCATN,.MYVALS) ; should find no leaks
Q Q
; ;
LEAKSBAD ; LEAKSBAD ;
N CODE,LOCATN,MYVALS,X N CODE,LOCATN,MYVALS,X
S CODE="S X=$$NOW^XLFDT()",LOCATN="LEAKSBAD TEST - X NOT SPECIFIED" S CODE="S X=$$NOW^XLFDT()",LOCATN="LEAKSBAD TEST - X NOT SPECIFIED"
D CHKLEAKS^%ut(CODE,LOCATN,.MYVALS) ; should find X since it isn't indicated D CHKLEAKS^%ut(CODE,LOCATN,.MYVALS) ; should find X since it isn't indicated
Q Q
; ;
NVLDARG1 ; NVLDARG1 ;
D CHKEQ^%ut(1) D CHKEQ^%ut(1)
Q Q
; ;
ISUTEST ; ISUTEST ;
D CHKTF^%ut($$ISUTEST^%ut,"ISUTEST returned FALSE!") D CHKTF^%ut($$ISUTEST^%ut,"ISUTEST returned FALSE!")
Q Q
; ;
BADFORM1(X) ; @TEST should not be selected - arguments BADFORM1(X) ; @TEST should not be selected - arguments
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
I $D(%utt6var) S %ut("ENT")="NEWSTYLE" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADFORM1")="" I $D(%utt6var) S %ut("ENT")="NEWSTYLE" S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADFORM1")=""
D CHKEQ^%ut(4,3,"SHOULD NOT BE SELECTED - ARGUMENTS - BADFORM1") D CHKEQ^%ut(4,3,"SHOULD NOT BE SELECTED - ARGUMENTS - BADFORM1")
Q Q
; ;
BADFORM2 ; ABC @TEST should not be selected - @TEST NOT FIRST BADFORM2 ; ABC @TEST should not be selected - @TEST NOT FIRST
; ZEXCEPT: %ut - Newed in EN^%zu ; ZEXCEPT: %ut - Newed in EN^%zu
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADFORM2")="" I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"BADFORM2")=""
D CHKEQ^%ut(4,3,"SHOULD NOT BE SELECTED - @TEST NOT FIRST - BADFORM2") D CHKEQ^%ut(4,3,"SHOULD NOT BE SELECTED - @TEST NOT FIRST - BADFORM2")
Q Q
; ;
STARTUP ; STARTUP ;
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
I $D(%utt6var),$D(^TMP("%utt5",$J)) K ^TMP("%utt5",$J) ; ZEXCEPT: KBANCOUNT created here, killed in SHUTDOWN
I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"STARTUP")="" I $D(%utt6var),$D(^TMP("%utt5",$J)) K ^TMP("%utt5",$J)
Q I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"STARTUP")=""
; ; following brought from %utt1, since only one STARTUP can RUN in a set
SHUTDOWN ; I '$D(%utt6var) D
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 . S ^TMP($J,"%ut","STARTUP")=""
I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"SHUTDOWN")="" . S KBANCOUNT=1
Q . Q
; Q
SETUP ; ;
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 SHUTDOWN ;
I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"SETUP")="" ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
Q ; ZEXCEPT: KBANCOUNT created in STARTUP, killed here
; I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"SHUTDOWN")=""
TEARDOWN ; ; following brought from %utt1, since only one SHUTDOWN can RUN in a set
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6 I '$D(%utt6var) D
I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"TEARDOWN")="" . K ^TMP($J,"%ut","STARTUP")
Q . K KBANCOUNT
; . Q
XTENT ; Q
;;OLDSTYLE; identify old style test indicator functionality ;
;;OLDSTYL1; identify old style test indicator 2 SETUP ;
;;BADCHKEQ; CHKEQ should fail on unequal value ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
;;BADCHKTF; CHKTF should fail on false value I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"SETUP")=""
;;BADERROR; throws an error on purpose Q
;;CALLFAIL; called FAIL to test it ;
;;LEAKSOK;check leaks should be ok TEARDOWN ;
;;LEAKSBAD;check leaks with leak ; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
;;NVLDARG1;check invalid arg in CHKEQ I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"TEARDOWN")=""
;;ISUTEST;check ISUTEST inside unit test Q
;
XTENT ;
;;OLDSTYLE; identify old style test indicator functionality
;;OLDSTYL1; identify old style test indicator 2
;;BADCHKEQ; CHKEQ should fail on unequal value
;;BADCHKTF; CHKTF should fail on false value
;;BADERROR; throws an error on purpose
;;CALLFAIL; called FAIL to test it
;;LEAKSOK;check leaks should be ok
;;LEAKSBAD;check leaks with leak
;;NVLDARG1;check invalid arg in CHKEQ
;;ISUTEST;check ISUTEST inside unit test

View File

@ -1,110 +1,112 @@
%utt6 ;JLI - Unit tests for MUnit functionality ;08/28/14 11:52 %utt6 ;JLI - Unit tests for MUnit functionality ;08/29/14 11:43
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
; ;
; This routine uses ZZUTJLI2 as a test routine, it does not include the routine as an extension, ; This routine uses ZZUTJLI2 as a test routine, it does not include the routine as an extension,
; since it uses it for tests. ; since it uses it for tests.
; ;
; ZZUTJLI2 currently contains 3 tests (2 old style, 1 new style), it also specifies STARTUP and ; ZZUTJLI2 currently contains 3 tests (2 old style, 1 new style), it also specifies STARTUP and
; SHUTDOWN (should be 1 each) and SETUP and TEARDOWN (should be 3 each, 1 for each test) enteries, each of these ; SHUTDOWN (should be 1 each) and SETUP and TEARDOWN (should be 3 each, 1 for each test) enteries, each of these
; creates an entry under the ^TMP("ZZUTJLI2" global node, indicating function then continues the process. ; creates an entry under the ^TMP("ZZUTJLI2" global node, indicating function then continues the process.
; Should be 2+3n entries (1+1 for STARTUP and SHUTDOWN, then 3 for each of the tests (SETUP, test, ; Should be 2+3n entries (1+1 for STARTUP and SHUTDOWN, then 3 for each of the tests (SETUP, test,
; and TEARDOWN). ; and TEARDOWN).
; ;
; This first section is more of a functional test, since it checks the full unit test processing from both ; This first section is more of a functional test, since it checks the full unit test processing from both
; a command line and a GUI call approach. Data for analysis is saved under ^TMP("ZZUTJLI2_C", for command ; a command line and a GUI call approach. Data for analysis is saved under ^TMP("ZZUTJLI2_C", for command
; line and ^TMP("ZZUTJLI2_G", for gui processing. ; line and ^TMP("ZZUTJLI2_G", for gui processing.
; ;
; The counts for the command line processing are based on the number of unit test tags ; The counts for the command line processing are based on the number of unit test tags
; determined for the GUI processing as well. The numbers are 2 (startup and shutdown) ; determined for the GUI processing as well. The numbers are 2 (startup and shutdown)
; + 3 x the number of tests present. ; + 3 x the number of tests present.
; ;
; run unit tests by command line ; run unit tests by command line
N VERBOSE N VERBOSE
S VERBOSE=0 S VERBOSE=0
VERBOSE ; VERBOSE ;
I '$D(VERBOSE) N VERBOSE S VERBOSE=1 I '$D(VERBOSE) N VERBOSE S VERBOSE=1
N ZZUTCNT,JLICNT,JLIEXPCT,JLII,JLIX,ZZUTRSLT,%utt5,%utt6,%utt6var N ZZUTCNT,JLICNT,JLIEXPCT,JLII,JLIX,ZZUTRSLT,%utt5,%utt6,%utt6var
W !!,"RUNNING COMMAND LINE TESTS VIA DOSET^%ut",! W !!,"RUNNING COMMAND LINE TESTS VIA DOSET^%ut",!
D DOSET^%ut(1,VERBOSE) ; run `1 in M-UNIT TEST GROUP file D DOSET^%ut(1,VERBOSE) ; run `1 in M-UNIT TEST GROUP file
; ;
W !!!,"Running command line tests by RUNSET^%ut",! W !!!,"Running command line tests by RUNSET^%ut",!
D RUNSET^%ut("TESTS FOR UNIT TEST ROUTINES") D RUNSET^%ut("TESTS FOR UNIT TEST ROUTINES")
; ;
; Call GUISET to obtain list of tags via entry in M-UNIT TEST GROUP file ; Call GUISET to obtain list of tags via entry in M-UNIT TEST GROUP file
; silent to the user ; silent to the user
D GUISET^%ut(.%utt6,1) D GUISET^%ut(.%utt6,1)
K ^TMP("%utt6_GUISET",$J) M ^TMP("%utt6_GUISET",$J)=@%utt6 K ^TMP("%utt6_GUISET",$J) M ^TMP("%utt6_GUISET",$J)=@%utt6
; ;
W !!!,"RUNNING COMMAND LINE UNIT TESTS FOR %utt5",! W !!!,"RUNNING COMMAND LINE UNIT TESTS FOR %utt5",!
N ZZUTCNT,JLICNT,JLIEXPCT,JLII,JLIX,ZZUTRSLT N ZZUTCNT,JLICNT,JLIEXPCT,JLII,JLIX,ZZUTRSLT
S ZZUTCNT=0 S ZZUTCNT=0
K ^TMP("%utt5",$J) ; kill any contents of data storage K ^TMP("%utt5",$J) ; kill any contents of data storage
D EN^%ut("%utt5",VERBOSE) ; should do STARTUP(1x), then SETUP, test, TEARDOWN (each together 3x) and SHUTDOWN (1x) D EN^%ut("%utt5",VERBOSE) ; should do STARTUP(1x), then SETUP, test, TEARDOWN (each together 3x) and SHUTDOWN (1x)
K ^TMP("%utt5_C",$J) M ^TMP("%utt5_C",$J)=^TMP("%utt5",$J) K ^TMP("%utt5_C",$J) M ^TMP("%utt5_C",$J)=^TMP("%utt5",$J)
; ;
; now run unit tests by GUI - first determines unit test tags ; now run unit tests by GUI - first determines unit test tags
W !!!,"RUNNING UNIT TESTS FOR %utt5 VIA GUI CALLS - Silent",! W !!!,"RUNNING UNIT TESTS FOR %utt5 VIA GUI CALLS - Silent",!
S ZZUTCNT=0 S ZZUTCNT=0
K ^TMP("%utt5",$J),^TMP("%utt6",$J) K ^TMP("%utt5",$J),^TMP("%utt6",$J)
D GUILOAD^%ut(.%utt6,"%utt5") D GUILOAD^%ut(.%utt6,"%utt5")
M ^TMP("%utt6",$J)=@%utt6 M ^TMP("%utt6",$J)=@%utt6
S %utt6=$NA(^TMP("%utt6",$J)) S %utt6=$NA(^TMP("%utt6",$J))
; then run each tag separately ; then run each tag separately
; JLICNT is count of unit test tags, which can be determined for GUI call for each unit test tag ; JLICNT is count of unit test tags, which can be determined for GUI call for each unit test tag
S JLICNT=0 F JLII=1:1 S JLIX=$G(@%utt6@(JLII)) Q:JLIX="" I $P(JLIX,U,2)'="" S JLICNT=JLICNT+1 D GUINEXT^%ut(.ZZUTRSLT,$P(JLIX,U,2)_U_$P(JLIX,U)) S JLICNT=0 F JLII=1:1 S JLIX=$G(@%utt6@(JLII)) Q:JLIX="" I $P(JLIX,U,2)'="" S JLICNT=JLICNT+1 D GUINEXT^%ut(.ZZUTRSLT,$P(JLIX,U,2)_U_$P(JLIX,U))
; and close it with a null routine name ; and close it with a null routine name
D GUINEXT^%ut(.ZZUTRSLT,"") D GUINEXT^%ut(.ZZUTRSLT,"")
K ^TMP("%utt5_G",$J) M ^TMP("%utt5_G",$J)=^TMP("%utt5",$J) K ^TMP("%utt5_G",$J) M ^TMP("%utt5_G",$J)=^TMP("%utt5",$J)
S JLIEXPCT=2+(3*JLICNT) ; number of lines that should be in the global nodes for command line and GUI S JLIEXPCT=2+(3*JLICNT) ; number of lines that should be in the global nodes for command line and GUI
; ;
; now run the unit tests in this routine ; now run the unit tests in this routine
W !!,"NOW RUNNING UNIT TESTS FOR %utt6",!! W !!,"NOW RUNNING UNIT TESTS FOR %utt6",!!
D EN^%ut("%utt6",VERBOSE) D EN^%ut("%utt6",VERBOSE)
K ^TMP("%utt5",$J),^TMP("%utt5_C",$J),^TMP("%utt5_G",$J),^TMP("%utt6",$J),^TMP("%utt6_GUISET",$J) K ^TMP("%utt5",$J),^TMP("%utt5_C",$J),^TMP("%utt5_G",$J),^TMP("%utt6",$J),^TMP("%utt6_GUISET",$J)
Q ; clean up after GUI calls as well
; K ^TMP("GUI-MUNIT",$J),^TMP("GUINEXT",$J),^TMP("MUNIT-%utRSLT",$J)
; Q
; WARNING -- WARNING -- WARNING ;
; If the number of NEW STYLE tests in %utt5 is increased (it is currently 1), then the following ;
; test will need to be updated to reflect the change(s) ; WARNING -- WARNING -- WARNING
; END OF WARNING -- END OF WARNING -- END OF WARNING ; If the number of NEW STYLE tests in %utt5 is increased (it is currently 1), then the following
; ; test will need to be updated to reflect the change(s)
NEWSTYLE ; tests return of valid new style or @TEST indicators ; END OF WARNING -- END OF WARNING -- END OF WARNING
N LIST ;
D NEWSTYLE^%ut1(.LIST,"%utt5") NEWSTYLE ; tests return of valid new style or @TEST indicators
D CHKEQ^%ut(LIST,1,"Returned an incorrect number ("_LIST_") of New Style indicators - should be one") N LIST
I LIST>0 D CHKEQ^%ut(LIST(1),"NEWSTYLE^identify new style test indicator functionality","Returned incorrect TAG^reason "_LIST(1)) D NEWSTYLE^%ut1(.LIST,"%utt5")
I LIST>0 D CHKEQ^%ut($G(LIST(2)),"","Returned a value for LIST(2) - should not have any value (i.e., null)") D CHKEQ^%ut(LIST,1,"Returned an incorrect number ("_LIST_") of New Style indicators - should be one")
Q I LIST>0 D CHKEQ^%ut(LIST(1),"NEWSTYLE^identify new style test indicator functionality","Returned incorrect TAG^reason "_LIST(1))
; I LIST>0 D CHKEQ^%ut($G(LIST(2)),"","Returned a value for LIST(2) - should not have any value (i.e., null)")
CKGUISET ; Q
; ZEXCEPT: %utt6var - if present, is NEWed and created in code following VERBOSE ;
I '$D(%utt6var) Q CKGUISET ;
N MAX ; ZEXCEPT: %utt6var - if present, is NEWed and created in code following VERBOSE
S MAX=$O(^TMP("%utt6_GUISET",$J,""),-1) I '$D(%utt6var) Q
D CHKTF^%ut(^TMP("%utt6_GUISET",$J,MAX)["%utt6^NEWSTYLE","GUISET returned incorrect list") N MAX
Q S MAX=$O(^TMP("%utt6_GUISET",$J,""),-1)
; D CHKTF^%ut(^TMP("%utt6_GUISET",$J,MAX)["%utt6^NEWSTYLE","GUISET returned incorrect list")
CHKCMDLN ; check command line processing of %utt5 Q
; ZEXCEPT: JLIEXPCT,%utt6var - if present NEWed and created in code following VERBOSE tag ;
I '$D(%utt6var) Q CHKCMDLN ; check command line processing of %utt5
D CHKTF^%ut($D(^TMP("%utt5_C",$J,JLIEXPCT))=10,"Not enough entries in %utt5 expected "_JLIEXPCT) ; ZEXCEPT: JLIEXPCT,%utt6var - if present NEWed and created in code following VERBOSE tag
D CHKTF^%ut($D(^TMP("%utt5_C",$J,JLIEXPCT+1))=0,"Too many entries in %utt5 expected "_JLIEXPCT) I '$D(%utt6var) Q
D CHKTF^%ut($O(^TMP("%utt5_C",$J,1,""))="STARTUP","Incorrect function for entry 1,'"_$O(^TMP("%utt5_C",$J,1,""))_"' should be 'STARTUP'") D CHKTF^%ut($D(^TMP("%utt5_C",$J,JLIEXPCT))=10,"Not enough entries in %utt5 expected "_JLIEXPCT)
D CHKTF^%ut($O(^TMP("%utt5_C",$J,JLIEXPCT,""))="SHUTDOWN","Incorrect function for entry "_JLIEXPCT_", '"_$O(^TMP("%utt5_C",$J,JLIEXPCT,""))_"' should be 'SHUTDOWN'") D CHKTF^%ut($D(^TMP("%utt5_C",$J,JLIEXPCT+1))=0,"Too many entries in %utt5 expected "_JLIEXPCT)
Q D CHKTF^%ut($O(^TMP("%utt5_C",$J,1,""))="STARTUP","Incorrect function for entry 1,'"_$O(^TMP("%utt5_C",$J,1,""))_"' should be 'STARTUP'")
; D CHKTF^%ut($O(^TMP("%utt5_C",$J,JLIEXPCT,""))="SHUTDOWN","Incorrect function for entry "_JLIEXPCT_", '"_$O(^TMP("%utt5_C",$J,JLIEXPCT,""))_"' should be 'SHUTDOWN'")
CHKGUI ; check GUI processing of %utt5 Q
; ZEXCEPT: JLIEXPCT,%utt6var - if present NEWed and created in code following VERBOSE tag ;
I '$D(%utt6var) Q CHKGUI ; check GUI processing of %utt5
D CHKTF^%ut($D(^TMP("%utt5_G",$J,JLIEXPCT))=10,"Not enough entries in %utt5 expected "_JLIEXPCT) ; ZEXCEPT: JLIEXPCT,%utt6var - if present NEWed and created in code following VERBOSE tag
D CHKTF^%ut($D(^TMP("%utt5_G",$J,JLIEXPCT+1))=0,"Too many entries in %utt5 expected "_JLIEXPCT) I '$D(%utt6var) Q
D CHKTF^%ut($O(^TMP("%utt5_G",$J,1,""))="STARTUP","Incorrect function for entry 1,'"_$O(^TMP("%utt5Z_G",1,""))_"' should be 'STARTUP'") D CHKTF^%ut($D(^TMP("%utt5_G",$J,JLIEXPCT))=10,"Not enough entries in %utt5 expected "_JLIEXPCT)
D CHKTF^%ut($O(^TMP("%utt5_G",$J,JLIEXPCT,""))="SHUTDOWN","Incorrect function for entry "_JLIEXPCT_", '"_$O(^TMP("%utt5_G",$J,JLIEXPCT,""))_"' should be 'SHUTDOWN'") D CHKTF^%ut($D(^TMP("%utt5_G",$J,JLIEXPCT+1))=0,"Too many entries in %utt5 expected "_JLIEXPCT)
Q D CHKTF^%ut($O(^TMP("%utt5_G",$J,1,""))="STARTUP","Incorrect function for entry 1,'"_$O(^TMP("%utt5Z_G",1,""))_"' should be 'STARTUP'")
; D CHKTF^%ut($O(^TMP("%utt5_G",$J,JLIEXPCT,""))="SHUTDOWN","Incorrect function for entry "_JLIEXPCT_", '"_$O(^TMP("%utt5_G",$J,JLIEXPCT,""))_"' should be 'SHUTDOWN'")
XTENT ; Q
;;CHKCMDLN;check command line processing of %utt5 ;
;;CHKGUI;check GUI processing of %utt5 XTENT ;
;;CKGUISET;check list of tests returned by GUISET ;;CHKCMDLN;check command line processing of %utt5
;;NEWSTYLE;test return of valid new style or @TEST indicators ;;CHKGUI;check GUI processing of %utt5
;;CKGUISET;check list of tests returned by GUISET
;;NEWSTYLE;test return of valid new style or @TEST indicators

View File

@ -1,46 +1,46 @@
%uttcovr ;JLI/JIVEYSOFT - runs coverage tests on %ut and %ut1 routines via unit tests ;2014-09-10 5:19 PM %uttcovr ;JLI/JIVEYSOFT - runs coverage tests on %ut and %ut1 routines via unit tests ;09/10/14 14:34
;;0.1;MASH UTILITIES; ;;0.1;MASH UTILITIES;;
; ;
I '(+$SY=47) W !,"This coverage analysis is currently only available in GT.M" Q ; GT.M only! I '(+$SY=47) W !,"This coverage analysis is currently only available in GT.M" Q ; GT.M only!
; ;
; if SHOWALL is true (1) all coverage globals data are listed ; if SHOWALL is true (1) all coverage globals data are listed
; if SHOWALL is false (0), only the %utCOVREPORT global is listed ; if SHOWALL is false (0), only the %utCOVREPORT global is listed
I '$D(SHOWALL) N SHOWALL S SHOWALL=0 I '$D(SHOWALL) N SHOWALL S SHOWALL=0
; set global node so %utt4 doesn't run its own analysis ; set global node so %utt4 doesn't run its own analysis
S ^TMP("%uttcovr",$J)=1 S ^TMP("%uttcovr",$J)=1
; start analysis of %ut - it calls entry below ; start analysis of %ut - it calls entry below
D COV^%ut1("%ut","D TESTCOVR^%ut",3) D COV^%ut1("%ut","D TESTCOVR^%ut",-1)
D LIST("%ut") ; output results of analysis D LIST("%ut") ; output results of analysis
; start analysis of %ut1 ; start analysis of %ut1
D COV^%ut1("%ut1","D TESTCOVR^%ut1",3) D COV^%ut1("%ut1","D TESTCOVR^%ut1",3)
D LIST("%ut1") D LIST("%ut1")
K ^TMP("%uttcovr",$J) K ^TMP("%uttcovr",$J)
Q Q
; ;
SHOWALL ; Entry to get all coverage globals listed SHOWALL ; Entry to get all coverage globals listed
N SHOWALL N SHOWALL
S SHOWALL=1 S SHOWALL=1
D ^%uttcovr D ^%uttcovr
Q Q
; ;
ENTRY ; ENTRY ;
D ^%utt1 ; verbose D ^%utt1 ; verbose
D EN^%ut("%utt1") ; non-verbose D EN^%ut("%utt1") ; non-verbose
; run tests from top of %utt6, runs both command line and gui analyses ; run tests from top of %utt6, runs both command line and gui analyses
D ^%utt6 ; non-verbose D ^%utt6 ; non-verbose
D VERBOSE^%utt6 ; verbose D VERBOSE^%utt6 ; verbose
Q Q
; ;
LIST(ROU) ; LIST(ROU) ;
; ZEXCEPT: SHOWALL - NEWed and set in SHOWALL or entering at %uttcovr ; ZEXCEPT: SHOWALL - NEWed and set in SHOWALL or entering at %uttcovr
N JOB,NAME,BASE,GLOB N JOB,NAME,BASE,GLOB
S JOB=$J S JOB=$J
W !!!,ROU_" COVERAGE ANALYSIS" W !!!,ROU_" COVERAGE ANALYSIS"
F NAME="%utCOVREPORT","%utCOVRESULT","%utCOVCOHORT","%utCOVCOHORTSAV" D F NAME="%utCOVREPORT","%utCOVRESULT","%utCOVCOHORT","%utCOVCOHORTSAV" D
. I 'SHOWALL,NAME'="%utCOVREPORT" Q . I 'SHOWALL,NAME'="%utCOVREPORT" Q
. W !!!,NAME," GLOBAL DATA",! . W !!!,NAME," GLOBAL DATA",!
. S BASE="^TMP("""_NAME_""","_JOB,GLOB=BASE_")" . S BASE="^TMP("""_NAME_""","_JOB,GLOB=BASE_")"
. I $D(GLOB)#2 W !,GLOB,"=",$G(@GLOB) . I $D(GLOB)#2 W !,GLOB,"=",$G(@GLOB)
. F S GLOB=$Q(@GLOB) Q:GLOB'[BASE I $D(GLOB)#2 W !,GLOB,"=",@GLOB . F S GLOB=$Q(@GLOB) Q:GLOB'[BASE I $D(GLOB)#2 W !,GLOB,"=",@GLOB
. Q . Q
Q Q

148
Routines/ZZUTPOST.m Normal file
View File

@ -0,0 +1,148 @@
ut01POST ;VEN-SMH/JLI - post install for M-Unit Test software ;08/28/14 12:29
;;0.1;MASH UTILITIES;;
N X,I
I +$SY=47 D R X:$G(DTIME,300) D MES^XPDUTL(" ")
. S X(1)=" "
. S X(2)="In the next section, as it tries to copy the ut* routines"
. S X(3)="to %ut* routines watch for text that indicates the following:"
. S X(4)=" "
. S X(5)="cp: cannot create regular file `/_ut.m': Permission denied"
. S X(6)=" "
. S X(7)="If this is seen, respond Yes at the prompt after the attempt:"
. S X(8)=" Press ENTER to continue: "
. F I=1:1:18 D MES^XPDUTL(" ") ; create a blank screen for text
. D MES^XPDUTL(.X)
. Q
D RENAME
I +$SY=47 D R X:$G(DTIME,300) I "Yy"[$E($G(X)) D GTMPROB
. K X
. S X(1)=" "
. S X(2)=" Your entry on the next line may not echo"
. S X(3)="If error text was seen enter Y (and RETURN): NO// "
. D MES^XPDUTL(.X)
. Q
Q
;
RENAME ;
N %S,%D ; Source, destination
S U="^"
S %S="ut^ut1^utt1^utt2^utt3^utt4^utt5^utt6^uttcovr"
S %D="%ut^%ut1^%utt1^%utt2^%utt3^%utt4^%utt5^%utt6^%uttcovr"
;
MOVE ; rename % routines
N %,X,Y,M
F %=1:1:$L(%D,"^") D D MES(M) I +$SY=47 D MES(" ")
. S M="",X=$P(%S,U,%) ; from
. S Y=$P(%D,U,%) ; to
. Q:X=""
. S M="Routine: "_$J(X,8)
. Q:Y="" I $T(^@X)="" S M=M_" Missing" Q
. S M=M_" Loaded, "
. D COPY(X,Y)
. S M=M_"Saved as "_$J(Y,8)
;
QUIT ; END
;
COPY(FROM,TO) ;
N XVAL
I +$SYSTEM=0 S XVAL="ZL @FROM ZS @TO" X XVAL QUIT
I +$SYSTEM=47 DO QUIT
. S FROM=$$PATH(FROM)
. S TO=$$PATH(TO,"WRITE")
. N CMD S CMD="cp "_FROM_" "_TO
. O "cp":(shell="/bin/sh":command=CMD:WRITEONLY)::"PIPE"
. U "cp" C "cp"
QUIT
;
PATH(ROUTINE,MODE) ; for GT.M return source file with path for a routine
;input: ROUTINE=Name of routine
; MODE="READ" or "WRITE" defaults to READ
;output: Full filename
;
S MODE=$G(MODE,"READ") ;set MODE to default value
N FILE S FILE=$TR(ROUTINE,"%","_")_".m" ;convert rtn name to filename
N ZRO S ZRO=$ZRO
;
; Get source routine
N %ZR
I MODE="READ" D SILENT^%RSEL(ROUTINE,"SRC") Q %ZR(ROUTINE)_FILE
;
; We are writing. Parse directories and get 1st routine directory
N DIRS
D PARSEZRO(.DIRS,ZRO)
N PATH S PATH=$$ZRO1ST(.DIRS)
;
QUIT PATH_FILE ;end of PATH return directory and filename
;
;
PARSEZRO(DIRS,ZRO) ; Parse $zroutines properly into an array
N PIECE
N I
F I=1:1:$L(ZRO," ") S PIECE(I)=$P(ZRO," ",I)
N CNT S CNT=1
F I=0:0 S I=$O(PIECE(I)) Q:'I D
. S DIRS(CNT)=$G(DIRS(CNT))_PIECE(I)
. I DIRS(CNT)["("&(DIRS(CNT)[")") S CNT=CNT+1 QUIT
. I DIRS(CNT)'["("&(DIRS(CNT)'[")") S CNT=CNT+1 QUIT
. S DIRS(CNT)=DIRS(CNT)_" " ; prep for next piece
QUIT
;
ZRO1ST(DIRS) ; $$ Get first routine directory
N OUT ; $$ return
N %1 S %1=DIRS(1) ; 1st directory
; Parse with (...)
I %1["(" DO
. S OUT=$P(%1,"(",2)
. I OUT[" " S OUT=$P(OUT," ")
. E S OUT=$P(OUT,")")
; no parens
E S OUT=%1
;
; Add trailing slash
I $E(OUT,$L(OUT))'="/" S OUT=OUT_"/"
QUIT OUT
;
MES(T,B) ;Write message.
S B=$G(B)
I $L($T(BMES^XPDUTL)) D BMES^XPDUTL(T):B,MES^XPDUTL(T):'B Q
W:B ! W !,T
Q
;
TEST ; @TEST - TESTING TESTING
;
N ZR S ZR="o(p r) /var/abc(/var/abc/r/) /abc/def $gtm_dist/libgtmutl.so vista.so"
N DIRS D PARSEZRO(.DIRS,ZR)
N FIRSTDIR S FIRSTDIR=$$ZRO1ST(.DIRS)
I FIRSTDIR'="p" S $EC=",U1,"
;
N ZR S ZR="/var/abc(/var/abc/r/) o(p r) /abc/def $gtm_dist/libgtmutl.so vista.so"
N DIRS D PARSEZRO(.DIRS,ZR)
N FIRSTDIR S FIRSTDIR=$$ZRO1ST(.DIRS)
I FIRSTDIR'="/var/abc/r/" S $EC=",U1,"
;
N ZR S ZR="/abc/def /var/abc(/var/abc/r/) o(p r) $gtm_dist/libgtmutl.so vista.so"
N DIRS D PARSEZRO(.DIRS,ZR)
N FIRSTDIR S FIRSTDIR=$$ZRO1ST(.DIRS)
I FIRSTDIR'="/abc/def" S $EC=",U1,"
;
WRITE "All tests have run successfully!",!
QUIT
;
GTMPROB ; come here in case of error trying to run unit tests - checks whether renaming worked
N X
S X(1)=" "
S X(2)="*** An error occurred during renaming of routines to %ut*."
S X(3)="*** The renaming has been seen to fail on one type of Linux system."
S X(4)="*** In this case, at the Linux command line copy each ut*.m routine"
S X(5)="*** (ut.m, ut1.m, utt1.m, utt2.m, utt3.m, utt4.m, utt5.m, utt6.m, and "
S X(6)="*** uttcovr.m) to _ut*.m (e.g., 'cp ut.m _ut.m', 'cp ut1.m _ut1.m',"
S X(7)="*** 'cp utt1.m _utt1.m', etc., to 'cp uttcovr.m _uttcovr.m'). Then in GT.M"
S X(8)="*** use the command 'ZLINK %ut', then 'ZLINK %ut1', etc., these may"
S X(9)="*** indicate an undefined local variable error, but continue doing it."
S X(10)="*** When complete, use the M command 'DO ^%utt1' to run the unit tests on"
S X(11)="*** the %ut and %ut1 routines to confirm they are working"
S X(12)=" "
S X(13)=" Press Enter to continue: "
D MES^XPDUTL(.X)
R X:$G(DTIME,300)
Q

42
Routines/ZZUTPRE.m Normal file
View File

@ -0,0 +1,42 @@
ut01PRE ;VEN/JLI - pre installation routine to set up MASH UTILITIES package and assign %ut routines and globals ;08/22/14 13:02
;;0.1;MASH UTILITIES;;
;
; The following is used to create, if it does not exist, the MASH UTILITIES
; package, and to assign the %u namespace to this package. This special
; processing is necessary, since the input transform currently will not accept a
; % or lower case character in the namespace.
I '$D(^DIC(9.4,"B","MASH UTILITIES")) N DIC,X S DIC="^DIC(9.4,",DIC(0)="",X="MASH UTILITIES",DIC("DR")="1////%u;2///Utilities associated with the M Advanced Shell" D FILE^DICN
; and if necessary, as in CACHE, map %ut routine and namespace in the current account.
I +$SY=0 D CACHEMAP ; This routine is CACHE specific
Q
; The following code was provided by Sam Habiel to map %
CACHEMAP ; Map %ut* Globals and Routines away from %SYS in Cache
; Get current namespace
N NMSP
I $P($P($ZV,") ",2),"(")<2012 S NMSP=$ZU(5)
I $P($P($ZV,") ",2),"(")>2011 S NMSP=$NAMESPACE
;
N $ET S $ET="ZN NMSP D ^%ZTER S $EC="""""
;
ZN "%SYS" ; Go to SYS
;
; Props
N % S %=##Class(Config.Namespaces).Get(NMSP,.PROP) ; Get all namespace properties
I '% W !,"Error="_$SYSTEM.Status.GetErrorText(%) S $EC=",U-CONFIG-FAIL," QUIT
;
N DBG S DBG=PROP("Globals") ; get the database globals location
N DBR S DBR=PROP("Routines") ; get the database routines location
;
; Map %ut globals away from %SYS
N % S %=##class(Config.Configuration).GetGlobalMapping(NMSP,"%ut*","",DBG,DBG)
I '% S %=##class(Config.Configuration).AddGlobalMapping(NMSP,"%ut*","",DBG,DBG)
I '% W !,"Error="_$SYSTEM.Status.GetErrorText(%) S $EC=",U-CONFIG-FAIL," QUIT
;
; Map %ut routines away from %SYS
N PROPRTN S PROPRTN("Database")=DBR
N % S %=##Class(Config.MapRoutines).Get(NMSP,"%ut*",.PROPRTN)
N PROPRTN S PROPRTN("Database")=DBR ; Cache seems to like deleting this
I '% S %=##Class(Config.MapRoutines).Create(NMSP,"%ut*",.PROPRTN)
I '% W !,"Error="_$SYSTEM.Status.GetErrorText(%) S $EC=",U-CONFIG-FAIL," QUIT
ZN NMSP ; Go back
QUIT