Skip to content

Commit abcd54c

Browse files
committed
Merge PR 41
2 parents 25ae6b1 + d93cab3 commit abcd54c

File tree

5 files changed

+113
-4
lines changed

5 files changed

+113
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- #42: Added a listener interface and manager with an associated user parameter, allowing the user to broadcast output on test method/case/suite completion.
1212

13-
## [3.1.1] - Unreleased
13+
## [3.1.1] - 2024-07-31
1414

1515
### Fixed
1616
- #39: Fixed bug where results viewer gave divide by zero error when there were 0 executed methods in the covered code
17+
- #41: Now the code strips leading and trailing whitespace from coverage.list, so "PackageName.PKG " will still be loaded properly
1718

1819
## [3.1.0] - 2024-07-05
1920

cls/TestCoverage/Manager.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ Method AddCoverageRoutine(pRoutineName As %String) [ Private ]
365365
}
366366
}
367367

368-
ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray) [ Private ]
368+
ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
369369
{
370370
Kill pTargetArray
371371

@@ -377,7 +377,7 @@ ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
377377

378378
For tLineIndex=1:1:$Get(tFileLines) {
379379
Set tLine = tFileLines(tLineIndex)
380-
380+
Set tLine = $zstrip(tLine, "<>W")
381381
// Skip blank lines
382382
If (tLine = "") {
383383
Continue
@@ -396,7 +396,7 @@ ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
396396
Set tExclude = 1
397397
Set tLine = $Extract(tLine,2,*)
398398
}
399-
399+
Set tLine = $zstrip(tLine, "<>W") // again in case there were extra spaces after the -
400400
Set tName = $Piece(tLine,".",1,*-1)
401401
Set tExtension = $ZConvert($Piece(tLine,".",*),"U")
402402

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Class UnitTest.TestCoverage.Unit.TestCoverageList Extends %UnitTest.TestCase
2+
{
3+
4+
/// helper function to find the samplecovlist.list's path
5+
ClassMethod FindCoverageList(directory As %String = "") As %String
6+
{
7+
set stmt = ##class(%SQL.Statement).%New()
8+
set status = stmt.%PrepareClassQuery("%File", "FileSet")
9+
if $$$ISERR(status) {write "%Prepare failed:" do $SYSTEM.Status.DisplayError(status) quit}
10+
11+
set rset = stmt.%Execute(directory)
12+
if (rset.%SQLCODE '= 0) {write "%Execute failed:", !, "SQLCODE ", rset.%SQLCODE, ": ", rset.%Message quit}
13+
14+
while rset.%Next()
15+
{
16+
set name = rset.%Get("Name")
17+
set type = rset.%Get("Type")
18+
19+
if (type = "F") {
20+
do ##class(%File).Deconstruct(name, .dirs)
21+
if (dirs(dirs) = "samplecovlist.list") {
22+
return name
23+
}
24+
} elseif (type = "D"){
25+
do ..FindCoverageList(name)
26+
}
27+
}
28+
if (rset.%SQLCODE < 0) {write "%Next failed:", !, "SQLCODE ", rset.%SQLCODE, ": ", rset.%Message quit}
29+
}
30+
31+
Method TestGettingCoverageList()
32+
{
33+
set tFile = ..FindCoverageList(^UnitTestRoot) // finds the samplecovlist.list
34+
do ##class(TestCoverage.Manager).GetCoverageTargetsForFile(tFile, .tTargetArray)
35+
36+
Set CorrectCoverageTargets("CLS", "TestCoverage.Data.CodeSubUnit") = ""
37+
Set CorrectCoverageTargets("CLS", "TestCoverage.Data.CodeSubUnit.Method") = ""
38+
Set CorrectCoverageTargets("CLS","TestCoverage.Data.CodeUnit")=""
39+
Set CorrectCoverageTargets("CLS","TestCoverage.Data.CodeUnitMap")=""
40+
Set CorrectCoverageTargets("CLS","TestCoverage.Data.Coverage")=""
41+
Set CorrectCoverageTargets("CLS","TestCoverage.Data.Run")=""
42+
Set CorrectCoverageTargets("CLS","TestCoverage.Manager")=""
43+
Set CorrectCoverageTargets("MAC","UnitTest.TestCoverage.Unit.CodeUnit.G1")=""
44+
Set CorrectCoverageTargets("MAC","UnitTest.TestCoverage.Unit.sampleRoutine")=""
45+
Do $$$AssertEquals(..CompareArrays(.tTargetArray, .CorrectCoverageTargets, .pMessage), 1, "tTargetarray equals CorrectCoverageTargets")
46+
Do $$$LogMessage(pMessage)
47+
}
48+
49+
/// Taken from Tim's Developer Community post
50+
/// Returns true if arrays <var>first</var> and <var>second</var> have all the same subscripts and all
51+
/// the same values at those subscripts. <br />
52+
/// If <var>first</var> and <var>second</var> both happen to be either undefined or unsubscripted variables,
53+
/// returns true if they're both undefined or have the same value.<br />
54+
/// <var>pMessage</var> has details of the first difference found, if any.
55+
ClassMethod CompareArrays(ByRef first, ByRef second, Output pMessage) As %Boolean [ ProcedureBlock = 0 ]
56+
{
57+
New tEqual,tRef1,tRef2,tRef1Data,tRef1Value,tRef2Data,tRef2Value
58+
59+
Set pMessage = ""
60+
Set tEqual = 1
61+
Set tRef1 = "first"
62+
Set tRef2 = "second"
63+
While (tRef1 '= "") || (tRef2 '= "") {
64+
#; See if the subscript is the same for both arrays.
65+
#; If not, one of them has a subscript the other doesn't, and they're not equal.
66+
If ($Piece(tRef1,"first",2) '= $Piece(tRef2,"second",2)) {
67+
Set tEqual = 0
68+
Set pMessage = "Different subscripts encountered by $Query: "_
69+
$Case(tRef1,"":"<end>",:tRef1)_"; "_$Case(tRef2,"":"<end>",:tRef2)
70+
Quit
71+
}
72+
73+
Kill tRef1Value,tRef2Value
74+
Set tRef1Data = $Data(@tRef1,tRef1Value)
75+
Set tRef2Data = $Data(@tRef2,tRef2Value)
76+
#; See if the $Data values are the same for the two.
77+
#; This is really only useful to detect if one of the arrays is undefined on the first pass;
78+
#; $Query only returns subscripts with data.
79+
#; This will catch only one being defined, or one being an array and
80+
#; ​the other being a regular variable.
81+
If (tRef1Data '= tRef2Data) {
82+
Set tEqual = 0
83+
Set pMessage = "$Data("_tRef1_")="_tRef1Data_"; $Data("_tRef2_")="_tRef2Data
84+
Quit
85+
} ElseIf (tRef1Data#2) && (tRef2Data#2) {
86+
#; See if the value at the subscript is the same for both arrays.
87+
#; If not, they're not equal.
88+
If (tRef1Value '= tRef2Value) {
89+
Set tEqual = 0
90+
Set pMessage = tRef1_"="_@tRef1_"; "_tRef2_"="_@tRef2
91+
Quit
92+
}
93+
}
94+
95+
Set tRef1 = $Query(@tRef1)
96+
Set tRef2 = $Query(@tRef2)
97+
}
98+
Quit tEqual
99+
}
100+
101+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ROUTINE UnitTest.TestCoverage.Unit.sampleRoutine
2+
UnitTestTestCoverageUnitsampleRoutine ;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
TestCoverage.Data.PKG
2+
- TestCoverage.Data.Aggregate.PKG
3+
// this is a comment
4+
UnitTest*.mac
5+
TestCoverage.Manager.cls

0 commit comments

Comments
 (0)