Skip to content

Commit 1f5cb62

Browse files
authored
Merge pull request #41 from intersystems/CoverageTargetsWhitespace
Coverage Targets Whitespace
2 parents a3392ec + 060d6a2 commit 1f5cb62

File tree

5 files changed

+113
-3
lines changed

5 files changed

+113
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
89
## [3.1.1] - Unreleased
910

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

1315
## [3.1.0] - 2024-07-05
1416

cls/TestCoverage/Manager.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ Method AddCoverageRoutine(pRoutineName As %String) [ Private ]
362362
}
363363
}
364364

365-
ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray) [ Private ]
365+
ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
366366
{
367367
Kill pTargetArray
368368

@@ -374,7 +374,7 @@ ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
374374

375375
For tLineIndex=1:1:$Get(tFileLines) {
376376
Set tLine = tFileLines(tLineIndex)
377-
377+
Set tLine = $zstrip(tLine, "<>W")
378378
// Skip blank lines
379379
If (tLine = "") {
380380
Continue
@@ -393,7 +393,7 @@ ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
393393
Set tExclude = 1
394394
Set tLine = $Extract(tLine,2,*)
395395
}
396-
396+
Set tLine = $zstrip(tLine, "<>W") // again in case there were extra spaces after the -
397397
Set tName = $Piece(tLine,".",1,*-1)
398398
Set tExtension = $ZConvert($Piece(tLine,".",*),"U")
399399

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)