Skip to content

Commit 359ad9a

Browse files
authored
Merge pull request #12 from intersystems/fix-missing-obj-code
Fail gracefully if nothing to monitor
2 parents 5b9f9fb + 368ae22 commit 359ad9a

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

cls/TestCoverage/Manager.cls

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ Method StartCoverageTracking() As %Status [ Private ]
203203
}
204204
}
205205

206+
If (tRelevantTargets = "") {
207+
Write !,"WARNING: Nothing found to monitor for routine(s): "_$ListToString(tNewTargets)
208+
}
209+
206210
// If we are to monitor all process IDs, actually use all except for the SuperServer (Routine = '%SYS.SERVER')
207211
// Workaround for versions without RFD1682
208212
Set tProcessIDs = ..ProcessIDs
@@ -474,6 +478,8 @@ Method EndCoverageTracking(pTestSuite As %String = "", pTestClass As %String = "
474478
Method OnAfterSaveResult(ByRef userparam)
475479
{
476480
Try {
481+
Quit:'$IsObject(..Run)
482+
477483
// Associate to unit test results.
478484
Do ..Run.TestResultsSetObjectId(..LogIndex)
479485
$$$ThrowOnError(..Run.%Save())
@@ -710,12 +716,14 @@ Method PrintURL()
710716
{
711717
Do ##super()
712718

713-
Set tURL = ..GetURL(..Run.%Id())
714-
If (tURL '= "") {
715-
Do ..PrintLine("Use the following URL to view test coverage data:")
716-
Do ..PrintLine(tURL)
717-
} Else {
718-
Do ..PrintLine("WARNING: No default web application found for namespace '"_$Namespace_"' - test coverage results cannot be viewed.")
719+
If $IsObject(..Run) {
720+
Set tURL = ..GetURL(..Run.%Id())
721+
If (tURL '= "") {
722+
Do ..PrintLine("Use the following URL to view test coverage data:")
723+
Do ..PrintLine(tURL)
724+
} Else {
725+
Do ..PrintLine("WARNING: No default web application found for namespace '"_$Namespace_"' - test coverage results cannot be viewed.")
726+
}
719727
}
720728
Quit
721729
}

cls/TestCoverage/ManagerBase.cls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ ClassMethod RunTestSuites(testspec As %String, qspec, ByRef userparam) As %Statu
216216
Do manager.LogStateBegin(tDummySuite)
217217
Do manager.LogStateStatus(sc,tDummySuite)
218218
Do manager.LogStateEnd(0)
219+
Set status(" "_tDummySuite)=""
219220
} Else {
220221
For {
221222
Set suite=$order(testspec(suite)) Quit:suite=""
@@ -265,6 +266,7 @@ ClassMethod RunTestSuites(testspec As %String, qspec, ByRef userparam) As %Statu
265266
Do manager.LogStateBegin(tDummySuite)
266267
Do manager.LogStateStatus(sc,tDummySuite)
267268
Do manager.LogStateEnd(0)
269+
Set status(" "_tDummySuite)=""
268270
}
269271
;
270272
#; Need to make a list of suites that failed and report these at the end. Is this logged under suite or testsuite from the loop above?

cls/TestCoverage/Utils/LineByLineMonitor.cls

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Include %occErrors
2+
13
/// Wrapper around %Monitor.System.LineByLine to ensure that the monitor is stopped when it should be, and also
24
/// to wrap the decision about whether to stop/start the monitor or to just clear counters.
35
Class TestCoverage.Utils.LineByLineMonitor Extends %Monitor.System.LineByLine
@@ -120,5 +122,40 @@ ClassMethod IsRunning() As %Boolean [ CodeMode = expression ]
120122
$zu(84,8) && $zu(84,1)
121123
}
122124

125+
/// Overridden and minimally modified from parent implementation
126+
ClassMethod Start(Routine As %List, Metric As %List, Process As %List) As %Status
127+
{
128+
// Before attempting to start monitor, ensure we actually have object code for at least some element of Routine
129+
Set pointer = 0
130+
Set found = 0
131+
While $ListNext(Routine,pointer,routine) {
132+
Set rtnname = routine_".obj"
133+
For {
134+
Set data = ""
135+
Set more = $$LIST^%R(rtnname,32767,0,.data,.ctx)
136+
If (data '= "") {
137+
Set found = 1
138+
Quit
139+
}
140+
}
141+
If (found = 1) {
142+
Quit
143+
}
144+
}
145+
If 'found {
146+
Quit ..GetError("NoObjFound")
147+
}
148+
149+
Quit ##super(.Routine,.Metric,.Process)
150+
}
151+
152+
ClassMethod GetError(key As %String, args...)
153+
{
154+
Quit $Case(key,
155+
"NoObjFound":$System.Status.Error($$$GeneralError,"Unable to start monitor: no object code exists for selected classes/routines. "_
156+
"Possible remediations: ensure that at least some class/routine is selected; ""view other"" for the routine and make sure that the "_
157+
".INT code actually has some content that could be covered."))
158+
}
159+
123160
}
124161

internal/testing/unit_tests/UnitTest/TestCoverage/Unit/CodeUnit.cls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Method TestCodeUnitCreation()
1010
If (tResult.%SQLCODE < 0) {
1111
Throw ##class(%Exception.SQL).CreateFromSQLCODE(tResult.%SQLCODE,tResult.%Message)
1212
}
13+
14+
Do $$$AssertStatusOK($System.OBJ.Compile($classname(),"ck-d"))
1315

1416
#dim tCodeUnit As TestCoverage.Data.CodeUnit
1517
Set tClsName = $classname()_".CLS"

internal/testing/unit_tests/UnitTest/TestCoverage/Unit/TestComplexity.cls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Method TestMethodsInThisClass()
77
Set tClass = $classname()
88
&sql(delete from TestCoverage_Data.CodeUnit where Name %STARTSWITH :tClass)
99
Do $$$AssertTrue(SQLCODE>=0)
10+
Do $$$AssertStatusOK($System.OBJ.Compile($classname(),"ck-d"))
1011
Do $$$AssertStatusOK(##class(TestCoverage.Data.CodeUnit).GetCurrentByName(tClass_".1.INT"))
1112
If $$$AssertStatusOK(##class(TestCoverage.Data.CodeUnit).GetCurrentByName(tClass_".CLS",,.tCodeUnit)) {
1213
Set tKey = ""
@@ -224,7 +225,8 @@ Method FunctionWithAppropriateScope(pArgument As %String)
224225
Quit tSC
225226
}
226227

227-
/// Complexity: 2 (1 + If)
228+
/// Complexity: 7 (1 + UCQ)
229+
/// Was 2 on earlier IRIS versions; UCQ adds a bit.
228230
Method MethodWithEmbeddedSQL()
229231
{
230232
&sql(select top 1 1 into :foo)

module.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
<Export generator="Cache" version="25">
33
<Document name="TestCoverage.ZPM"><Module>
44
<Name>TestCoverage</Name>
5-
<Version>2.1.2</Version>
5+
<Version>2.1.3</Version>
66
<Description>Run your typical ObjectScript %UnitTest tests and see which lines of your code are executed. Includes Cobertura-style reporting for use in continuous integration tools.</Description>
77
<Packaging>module</Packaging>
88
<Resources>
99
<Resource Name="TestCoverage.PKG">
1010
</Resource>
1111
<Resource Name="TestCoverage.DataType.PKG">
1212
</Resource>
13-
<Resource Name="TestCoverage.Utils.LineByLineMonitor.CLS">
14-
</Resource>
1513
<Resource Name="TestCoverage.INC">
1614
</Resource>
1715
<Resource Name="/internal/testing/unit_tests/" ProcessorClass="UnitTest">

0 commit comments

Comments
 (0)