Skip to content

Commit d30dcdf

Browse files
committed
Merged CoverageTargetsWhitespace branch
2 parents 3c54cd8 + 060d6a2 commit d30dcdf

File tree

6 files changed

+115
-5
lines changed

6 files changed

+115
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ 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-
## [3.2.0] - 2024-07-08
8+
## [3.2.0] - Unreleased
99

1010
### Added
1111
- #29: Track code coverage for embedded python methods in .cls files
1212

13+
1314
## [3.1.1] - Unreleased
1415

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

1820
## [3.1.0] - 2024-07-05
1921

cls/TestCoverage/Data/CodeUnit.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ ClassMethod GetCurrentByName(pInternalName As %String, pSourceNamespace As %Stri
152152
Do pCodeUnit.LineToMethodMap.SetAt(tMethod,i)
153153
}
154154
Set iterator = tMethodMapInfo."__iter__"()
155-
for i=1:1:tMethodMapInfo."__len__"() {
155+
for i=1:1:tMethodMapInfo."__len__"() { // when iterator passes the last element, it throws a Python exception: StopIteration error, so I think the current pattern is preferable over that
156156
Set tMethod = iterator."__next__"()
157157
Set tStartEnd = tMethodMapInfo."__getitem__"(tMethod)
158158
Set tStartLine = tStartEnd."__getitem__"(0)

cls/TestCoverage/Manager.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Method AddCoverageRoutine(pRoutineName As %String) [ Private ]
414414
}
415415
}
416416

417-
ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray) [ Private ]
417+
ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
418418
{
419419
Kill pTargetArray
420420

@@ -426,7 +426,7 @@ ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
426426

427427
For tLineIndex=1:1:$Get(tFileLines) {
428428
Set tLine = tFileLines(tLineIndex)
429-
429+
Set tLine = $zstrip(tLine, "<>W")
430430
// Skip blank lines
431431
If (tLine = "") {
432432
Continue
@@ -445,7 +445,7 @@ ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray)
445445
Set tExclude = 1
446446
Set tLine = $Extract(tLine,2,*)
447447
}
448-
448+
Set tLine = $zstrip(tLine, "<>W") // again in case there were extra spaces after the -
449449
Set tName = $Piece(tLine,".",1,*-1)
450450
Set tExtension = $ZConvert($Piece(tLine,".",*),"U")
451451

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)