Merge branch 'master' of github.com:shabiel/M-Unit

Conflicts:
	Routines/%ut.m
This commit is contained in:
Sam Habiel 2016-02-25 10:19:29 -08:00
commit b586ab9544
3 changed files with 101 additions and 64 deletions

View File

@ -1,8 +1,9 @@
%ut ;VEN-SMH/JLI - PRIMARY PROGRAM FOR M-UNIT TESTING ;09/14/15 09:38
;;0.2;MASH UTILITIES;;;Build 7
; Submitted to OSEHRA Sep 14, 2015 by Joel L. Ivey under the Apache 2 license (http://www.apache.org/licenses/LICENSE-2.0.html)
%ut ;VEN-SMH/JLI - PRIMARY PROGRAM FOR M-UNIT TESTING ;2015-12-31 10:46 PM
;;1.3;MASH UTILITIES;;Dec 16, 2015;Build 1
; Submitted to OSEHRA Dec 16, 2015 by Joel L. Ivey under the Apache 2 license (http://www.apache.org/licenses/LICENSE-2.0.html)
; Original routine authored by Joel L. Ivey as XTMUNIT while working for U.S. Department of Veterans Affairs 2003-2012
; Includes addition of %utVERB and %utBREAK arguments and code related to them as well as other substantial additions authored by Sam Habiel 07/2013?04/2014
; Includes addition of %utVERB and %utBREAK arguments and code related to them as well as other substantial additions authored by Sam Habiel 07/2013-04/2014
; Additional work by Joel L. Ivey 05/14-12/15
;
; 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
@ -101,17 +102,17 @@ EN1(%utROU,%utLIST) ;
. . S %ut("ENT")=%utETRY(%utI)_"^"_%utROU(%ut("CURR"))
. . I %utVERB,'$D(%utGUI) D VERBOSE1(.%utETRY,%utI) ; Say what we executed.
. . ;
. . I %utVERB=2 N %utStart D ; User Time Start
. . . I +$SY=0 S %utStart=$P($SYSTEM.Process.GetCPUTime(),",",2)
. . I %utVERB=2 N %utStart D ; Time Start
. . . I +$SY=0 S %utStart=$P($SYSTEM.Process.GetCPUTime(),",")+$P($SYSTEM.Process.GetCPUTime(),",",2)
. . . I +$SY=47 S %utStart=$ZGETJPI("","CPUTIM")*10
. . ;
. . ; Run the test!
. . D @%ut("ENT")
. . ;
. . I %utVERB=2 N %utEnd,%utElapsed D ; User Time End
. . . I +$SY=0 S %utEnd=$P($SYSTEM.Process.GetCPUTime(),",",2)
. . I %utVERB=2 N %utEnd,%utElapsed D ; Time End
. . . I +$SY=0 S %utEnd=$P($SYSTEM.Process.GetCPUTime(),",")+$P($SYSTEM.Process.GetCPUTime(),",",2)
. . . I +$SY=47 S %utEnd=$ZGETJPI("","CPUTIM")*10
. . . S %utElapsed=%utEnd-%utStart_"ms"
. . . S %utElapsed=%utEnd-%utStart_"ms"
. . ;
. . ; Run Teardown Code (only if present)
. . S %ut("ENT")=$G(%ut("TEARDOWN"))
@ -159,13 +160,44 @@ VERBOSE1(%utETRY,%utI) ; Print out the entry point info
Q
;
CHKTF(XTSTVAL,XTERMSG) ; Entry point for checking True or False values
; ZEXCEPT: %utERRL,%utGUI - CREATED IN SETUP, KILLED IN END
; ZEXCEPT: %ut - NEWED IN EN
; ZEXCEPT: XTGUISEP - newed in GUINEXT
I '$D(XTSTVAL) D NVLDARG^%ut1("CHKTF") Q
D CHKTF^%ut1(XTSTVAL,$G(XTERMSG))
I $G(XTERMSG)="" S XTERMSG="no failure message provided"
S %ut("CHK")=$G(%ut("CHK"))+1
I '$D(%utGUI) D
. D SETIO^%ut1
. 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")
. . I $D(%ut("BREAK")) BREAK ; Break upon failure
. . Q
. I XTSTVAL W "."
. D RESETIO^%ut1
. Q
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
;
CHKEQ(XTEXPECT,XTACTUAL,XTERMSG) ; Entry point for checking values to see if they are EQUAL
N FAILMSG
; ZEXCEPT: %utERRL,%utGUI -CREATED IN SETUP, KILLED IN END
; ZEXCEPT: %ut -- NEWED IN EN
; ZEXCEPT: XTGUISEP - newed in GUINEXT
I '$D(XTEXPECT)!'$D(XTACTUAL) D NVLDARG^%ut1("CHKEQ") Q
D CHKEQ^%ut1(XTEXPECT,XTACTUAL,$G(XTERMSG))
S XTACTUAL=$G(XTACTUAL),XTEXPECT=$G(XTEXPECT)
I $G(XTERMSG)="" S XTERMSG="no failure message provided"
S %ut("CHK")=%ut("CHK")+1
I XTEXPECT'=XTACTUAL S FAILMSG="<"_XTEXPECT_"> vs <"_XTACTUAL_"> - "
I '$D(%utGUI) D
. D SETIO^%ut1
. 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")
. . I $D(%ut("BREAK")) BREAK ; Break upon failure
. . Q
. E W "."
. D RESETIO^%ut1
. Q
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
;
FAIL(XTERMSG) ; Entry point for generating a failure message
@ -254,7 +286,8 @@ ISUTEST() ; .SUPPORTED API TO DETERMINE IF CURRENTLY IN UNIT TEST
Q $G(%ut)=1
;
PICKSET ; .OPT Interactive selection of MUnit Test Group
N DIC,Y,%utROU,%utLIST,DIR S DIC=17.9001,DIC(0)="AEQM" D ^DIC Q:Y'>0 W ! D GETSET(+Y,.%utROU,.%utLIST) N DIC,Y,%ut D SETUT D EN1(.%utROU,%utLIST) S DIR(0)="EA",DIR("A")="Enter RETURN to continue:" D ^DIR K DIR
N DIC,Y,%utROU,%utLIST,DIR
I '$$ISUTEST^%ut() S DIC=17.9001,DIC(0)="AEQM" D ^DIC Q:Y'>0 W ! D GETSET(+Y,.%utROU,.%utLIST) N DIC,Y,%ut D SETUT D EN1(.%utROU,%utLIST) S DIR(0)="EA",DIR("A")="Enter RETURN to continue:" D ^DIR K DIR
Q
;
RUNSET(SETNAME,VERBOSE) ; .SR Run with Specified Selection of MUnit Test Group

View File

@ -1,5 +1,5 @@
%utt1 ; VEN/SMH-JLI - Testing routines for M-Unit;12/16/15 08:43
;;1.3;MASH UTILITIES;;Dec 16, 2015;Build 1
%utt1 ; VEN/SMH-JLI - Testing routines for M-Unit;2015-12-31 10:33 PM
;;1.3;MASH UTILITIES;;Dec 16, 2015;Build 4
; Submitted to OSEHRA Dec 16, 2015 by Joel L. Ivey under the Apache 2 license (http://www.apache.org/licenses/LICENSE-2.0.html)
; Original routine authored by Sam H. Habiel 07/2013-04/2014
; Additions and modifications made by Joel L. Ivey 05/2014-12/2015
@ -16,6 +16,10 @@
; Sam H
;
D EN^%ut($T(+0),1) ; Run tests here, be verbose.
N % S $P(%,"-",80)="-"
W !!,%,!,%,!,%,!,%,!!
K %
D EN^%ut($T(+0),2) ; Run tests here, be verbose with timings for each piece of code.
QUIT
;
STARTUP ; M-Unit Start-Up - This runs before anything else.

View File

@ -1,50 +1,50 @@
%utPRE ;VEN/SMH/JLI - pre installation routine to set up MASH UTILITIES package and assign %ut routines and globals ;12/16/15 08:59
;;1.3;MASH UTILITIES;;DEC 16, ;Build 1
; Submitted to OSEHRA Dec 16, 2015 by Joel L. Ivey under the Apache 2 license (http://www.apache.org/licenses/LICENSE-2.0.html)
; Original routine authored by Sam H. Habiel 07/2013-04/2014
;
;
; 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
S PROP("Database")="VISTA" ; needed for call to MapGlobals.Create below
;
; Map %ut globals away from %SYS
N %
;S %=##class(Config.Configuration).GetGlobalMapping(NMSP,"%ut*","",DBG,DBG)
S %=##Class(Config.MapGlobals).Get(NMSP,"%ut*",.PROP)
;I '% S %=##class(Config.Configuration).AddGlobalMapping(NMSP,"%ut*","",DBG,DBG)
I '% S %=##Class(Config.MapGlobals).Create(NMSP,"%ut",.PROP) ; doesn't work with "%ut*"
;
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
%utPRE ;VEN/SMH/JLI - pre installation routine to set up MASH UTILITIES package and assign %ut routines and globals ;12/16/15 08:59
;;1.3;MASH UTILITIES;;DEC 16, ;Build 1
; Submitted to OSEHRA Dec 16, 2015 by Joel L. Ivey under the Apache 2 license (http://www.apache.org/licenses/LICENSE-2.0.html)
; Original routine authored by Sam H. Habiel 07/2013-04/2014
;
;
; 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
S PROP("Database")=DBG ; needed for call to MapGlobals.Create below
;
; Map %ut globals away from %SYS
N %
S %=##class(Config.Configuration).GetGlobalMapping(NMSP,"%ut*","",DBG,DBG)
;S %=##Class(Config.MapGlobals).Get(NMSP,"%ut*",.PROP)
I '% S %=##class(Config.Configuration).AddGlobalMapping(NMSP,"%ut*","",DBG,DBG)
;I '% S %=##Class(Config.MapGlobals).Create(NMSP,"%ut",.PROP) ; doesn't work with "%ut*"
;
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