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,5 +1,5 @@
%ut ;VEN-SMH/JLI - PRIMARY PROGRAM FOR M-UNIT TESTING ;08/24/14 21:45
;;0.1;MASH UTILITIES;
%ut ;VEN-SMH/JLI - PRIMARY PROGRAM FOR M-UNIT TESTING ;08/29/14 09:31
;;0.1;MASH UTILITIES;;
;
; 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
@ -195,7 +195,7 @@ CHKTF(XTSTVAL,XTERMSG) ; Entry point for checking True or False values
. I XTSTVAL W "."
. D RESETIO
. 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
;
CHKEQ(XTEXPECT,XTACTUAL,XTERMSG) ; Entry point for checking values to see if they are EQUAL
@ -217,7 +217,7 @@ CHKEQ(XTEXPECT,XTACTUAL,XTERMSG) ; Entry point for checking values to see if the
. E W "."
. D RESETIO
. 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
;
FAIL(XTERMSG) ; Entry point for generating a failure message
@ -234,7 +234,7 @@ FAIL(XTERMSG) ; Entry point for generating a failure message
. . Q
. D RESETIO
. 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
SUCCEED ; Entry point for forcing a success (Thx David Whitten)
; ZEXCEPT: %utERRL,%utGUI - CREATED IN SETUP, KILLED IN END
@ -270,7 +270,7 @@ CHKLEAKS(%utCODE,%utLOC,%utINPT) ; functionality to check for variable leaks on
; If called outside of a unit test, any leaked variables will be printed to the
; 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: %utVAR - handled by exclusive NEW
;
@ -280,11 +280,11 @@ CHKLEAKS(%utCODE,%utLOC,%utINPT) ; functionality to check for variable leaks on
N ZZUTVAR S ZZUTVAR="%"
I $G(%ut)=1 D
. 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
I '($G(%ut)=1) D
. 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
;
@ -301,7 +301,7 @@ NVLDARG ; generate message for invalid arguments to test
. . Q
. D RESETIO
. 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
;
ERROR ; record errors
@ -447,8 +447,10 @@ GUINEXT(%utRSLT,%utLOC,XTGUISEP) ; Entry point for GUI execute next test - calle
S %utRSLT=%ut("RSLT")
S %utETRY=$P(%utLOC,U),%utROUT=$P(%utLOC,U,2),XTOLROU=$G(@XTVALUE@("LASTROU"))
S %utGUI=1
S %ut("CHK")=0,%ut("CNT")=1,%utERR=0
; I %utROUT'=XTOLROU D I %utROUT="" S @%utRSLT@(1)="" K @XTVALUE Q ;140731 JLI - commented out
D I %utROUT="" S @%utRSLT@(1)="" K @XTVALUE Q ; 140731 JLI - replaced previous line - moves check for SHUTDOWN at end of processing
;D I %utROUT="" S @%utRSLT@(1)="" K @XTVALUE Q ; 140731 JLI - replaced previous line - moves check for SHUTDOWN at end of processing
D I %utROUT="" S @%utRSLT@(1)="" Q ; 140829 JLI - Have to leave XTVALUE intact, in case they simply run again for STARTUP, etc.
. I XTOLROU="",$D(@XTVALUE@("STARTUP")) D
. . S %ut("LOC")=@XTVALUE@("STARTUP")
. . N $ETRAP S $ETRAP="D ERROR^%ut"

View File

@ -1,5 +1,5 @@
%ut1 ;VEN/SMH/JLI - CONTINUATION OF M-UNIT PROCESSING ;2014-09-10 7:41 PM
;;0.1;MASH UTILITIES;
%ut1 ;VEN/SMH/JLI - CONTINUATION OF M-UNIT PROCESSING ;09/10/14 14:27
;;0.1;MASH UTILITIES;;
;
;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
@ -15,8 +15,6 @@
; 131218 SMH - CHEKTEST refactored to use $TEXT instead of ^%ZOSF("LOAD")
; 131218 SMH - CATCHERR now nulls out $ZS if on GT.M
;
; TODO: find this routine and add to repo.
D EN^%ut("%utt3")
Q
;
CHEKTEST(%utROU,%ut,%utUETRY) ; Collect Test list.
@ -34,7 +32,6 @@ CHEKTEST(%utROU,%ut,%utUETRY) ; Collect Test list.
; VEN/SMH - block refactored to use $TEXT instead of ^%ZOSF("LOAD")
N I,LIST
S I=$L($T(@(U_%utROU))) I I<0 Q "-1^Invalid Routine Name"
N $ETRAP S $ETRAP="D CATCHERR^%ut1"
; 140731 JLI - the following SMH code is replaced by the code below
; Complexity galore: $TEXT loops through routine
; IF tab or space isn't the first character ($C(9,32)) and line contains @TEST
@ -63,13 +60,6 @@ CHEKTEST(%utROU,%ut,%utUETRY) ; Collect Test list.
;
QUIT
;
; VEN/SMH - Is this catch needed anymore?
CATCHERR ; catch error on trying to load file if it doesn't exist ; JLI 120806
W !,"In CATCHERR",! ; JLI 140910 DEBUG
S $ZE="",$EC=""
I +$SY=47 S $ZS="" ; VEN/SMH fur GT.M.
QUIT
;
; VEN/SMH 26JUL2013 - Moved GETTREE here.
GETTREE(%utROU,%utULIST) ;
; first get any other routines this one references for running subsequently

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,5 +1,5 @@
%utt1 ; VEN/SMH - Testing routines for M-Unit;08/28/14 11:42
;;0.1;MASH UTILITIES;
%utt1 ; VEN/SMH - Testing routines for M-Unit;08/29/14 11:35
;;0.1;MASH UTILITIES;;
%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.
@ -123,10 +123,11 @@ T8 ; If IO starts with another device, write to that device as if it's the prici
I +$SY=0 O D:"R" ; Cache read only
I +$SY=47 O D:(readonly) ; GT.M read only
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=47 C D:(delete)
D CHKTF(Y["MAIN")
;D CHKTF(Y["MAIN") ; JLI 140829 commented out, gui doesn't run verbose
D CHKTF((Y["MAIN")!(Z["Ran 1 Routine"),"Write to system during test didn't work")
S IO=$P
QUIT
;

View File

@ -1,5 +1,5 @@
%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
;
T11 ; @TEST An @TEST Entry point in Another Routine invoked through XTROU offsets

View File

@ -1,5 +1,5 @@
%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
;
; *** BE VERY CAREFUL IN MODIFIYING THIS ROUTINE ***

View File

@ -1,5 +1,5 @@
%utt4 ; VEN/SMH - Coverage Test Runner;2014-08-28 8:37 PM
;;0.1;MASH UTILITIES;
%utt4 ; VEN/SMH - Coverage Test Runner;08/23/14 08:33
;;0.1;MASH UTILITIES;;
XTMUNITW ; VEN/SMH - Coverage Test Runner;2014-04-17 3:30 PM
;;7.3;KERNEL TOOLKIT;;
;
@ -8,7 +8,6 @@ XTMUNITW ; VEN/SMH - Coverage Test Runner;2014-04-17 3:30 PM
;
MAIN ; @TEST - Test coverage calculations
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
;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.

View File

@ -1,5 +1,5 @@
%utt5 ;JLI - test for aspects of MUnit functionality ;08/24/14 21:31
;;0.1;MASH UTILITIES;
%utt5 ;JLI - test for aspects of MUnit functionality ;08/29/14 11:23
;;0.1;MASH UTILITIES;;
Q
;
OLDSTYLE ;
@ -91,13 +91,25 @@ BADFORM2 ; ABC @TEST should not be selected - @TEST NOT FIRST
;
STARTUP ;
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
; ZEXCEPT: KBANCOUNT created here, killed in SHUTDOWN
I $D(%utt6var),$D(^TMP("%utt5",$J)) K ^TMP("%utt5",$J)
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
I '$D(%utt6var) D
. S ^TMP($J,"%ut","STARTUP")=""
. S KBANCOUNT=1
. Q
Q
;
SHUTDOWN ;
; ZEXCEPT: %utt6cnt,%utt6var - if present, NEWED following top entry of routine %utt6
; ZEXCEPT: KBANCOUNT created in STARTUP, killed here
I $D(%utt6var) S %utt6cnt=$G(%utt6cnt)+1,^TMP("%utt5",$J,%utt6cnt,"SHUTDOWN")=""
; following brought from %utt1, since only one SHUTDOWN can RUN in a set
I '$D(%utt6var) D
. K ^TMP($J,"%ut","STARTUP")
. K KBANCOUNT
. Q
Q
;
SETUP ;

View File

@ -1,5 +1,5 @@
%utt6 ;JLI - Unit tests for MUnit functionality ;08/28/14 11:52
;;0.1;MASH UTILITIES;
%utt6 ;JLI - Unit tests for MUnit functionality ;08/29/14 11:43
;;0.1;MASH UTILITIES;;
;
; This routine uses ZZUTJLI2 as a test routine, it does not include the routine as an extension,
; since it uses it for tests.
@ -61,6 +61,8 @@ VERBOSE ;
W !!,"NOW RUNNING UNIT TESTS FOR %utt6",!!
D EN^%ut("%utt6",VERBOSE)
K ^TMP("%utt5",$J),^TMP("%utt5_C",$J),^TMP("%utt5_G",$J),^TMP("%utt6",$J),^TMP("%utt6_GUISET",$J)
; clean up after GUI calls as well
K ^TMP("GUI-MUNIT",$J),^TMP("GUINEXT",$J),^TMP("MUNIT-%utRSLT",$J)
Q
;
;

View File

@ -1,5 +1,5 @@
%uttcovr ;JLI/JIVEYSOFT - runs coverage tests on %ut and %ut1 routines via unit tests ;2014-09-10 5:19 PM
;;0.1;MASH UTILITIES;
%uttcovr ;JLI/JIVEYSOFT - runs coverage tests on %ut and %ut1 routines via unit tests ;09/10/14 14:34
;;0.1;MASH UTILITIES;;
;
I '(+$SY=47) W !,"This coverage analysis is currently only available in GT.M" Q ; GT.M only!
;
@ -9,7 +9,7 @@
; set global node so %utt4 doesn't run its own analysis
S ^TMP("%uttcovr",$J)=1
; 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
; start analysis of %ut1
D COV^%ut1("%ut1","D TESTCOVR^%ut1",3)

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