Skip to content

Commit 6733ae8

Browse files
authored
Merge pull request #7 from intersystems/coverage-aggregation-fix
Coverage aggregation fix
2 parents a3a0e1e + 3fa2acc commit 6733ae8

File tree

8 files changed

+93
-17
lines changed

8 files changed

+93
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.bak
22
readme.txt
33
.buildpath
4+
.vscode

.travis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
language: minimal
2+
3+
os: linux
4+
5+
services:
6+
- docker
7+
8+
env:
9+
- container_image="intersystemsdc/iris-community:2019.4.0.383.0-zpm"
10+
instance="iris"
11+
package="testcoverage"
12+
build_flags="-verbose"
13+
>
14+
test_flags="-verbose -DUnitTest.ManagerClass=TestCoverage.Manager -DUnitTest.JUnitOutput=/source/junit.xml
15+
-DUnitTest.FailuresAreFatal=1 -DUnitTest.Manager=TestCoverage.Manager
16+
-DUnitTest.UserParam.CoverageReportClass=TestCoverage.Report.Cobertura.ReportGenerator
17+
-DUnitTest.UserParam.CoverageReportFile=/source/coverage.xml"
18+
19+
install:
20+
# Run InterSystems IRIS instance
21+
- docker pull $container_image
22+
- docker run -d -h $instance --name $instance -v $TRAVIS_BUILD_DIR:/source --init $container_image
23+
- echo halt > wait
24+
- until docker exec --interactive $instance iris session $instance < wait; do sleep 1; done # Wait for instance to be ready
25+
# Workaround for permissions issues in TestCoverage (creating directory for source export)
26+
- chmod 777 $TRAVIS_BUILD_DIR
27+
28+
script:
29+
# Run build
30+
- >
31+
echo
32+
"set good = ##class(%ZPM.PackageManager).Shell(\"load /source $build_flags\")
33+
write !
34+
if good<1 { do \$System.Process.Terminate(\$job,1) }
35+
halt" > build
36+
# Run tests (with workaround for https://github.com/intersystems-community/zpm/pull/30 - test result will always be index 1)
37+
- >
38+
echo
39+
"set ^||%UnitTest.Manager.LastResult = 1
40+
set good = ##class(%ZPM.PackageManager).Shell(\"$package test -only $test_flags\")
41+
write !
42+
if good<1 { do \$System.Process.Terminate(\$job,1) }
43+
halt" > test
44+
- docker exec --interactive $instance iris session $instance -B < build && docker exec --interactive $instance iris session $instance -B < test
45+
46+
after_success:
47+
# Publish to codecov
48+
- bash <(curl -s https://codecov.io/bash)

cls/TestCoverage/Data/Coverage.cls

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Index MeaningfulCoverageData On (Run, Calculated, Ignore, Hash, TestPath) [ Data
1111
Property Run As TestCoverage.Data.Run [ Required ];
1212

1313
/// Path through test cases/suites
14-
Property TestPath As %String(MAXLEN = 300, TRUNCATE = 1) [ Required ];
14+
Property TestPath As %String(COLLATION = "EXACT", MAXLEN = 300, TRUNCATE = 1) [ Required ];
1515

1616
/// Target code unit, uniquely identified by hash.
1717
Property Hash As TestCoverage.Data.CodeUnit [ Required ];
@@ -118,7 +118,6 @@ ClassMethod GetAvailableMetrics() As %List [ CodeMode = objectgenerator ]
118118
Quit $$$OK
119119
}
120120

121-
/// List of
122121
Storage Default
123122
{
124123
<Data name="CoverageDefaultData">
@@ -161,13 +160,11 @@ Storage Default
161160
</Data>
162161
<DataLocation>^TestCoverage.Data.CoverageD</DataLocation>
163162
<DefaultData>CoverageDefaultData</DefaultData>
164-
<Description>
165-
<![CDATA[List of ]]></Description>
163+
<Description></Description>
166164
<IdLocation>^TestCoverage.Data.CoverageD</IdLocation>
167165
<IndexLocation>^TestCoverage.Data.CoverageI</IndexLocation>
168166
<StreamLocation>^TestCoverage.Data.CoverageS</StreamLocation>
169167
<Type>%Library.CacheStorage</Type>
170168
}
171169

172170
}
173-

cls/TestCoverage/Data/Run.cls

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Property Detail As TestCoverage.DataType.Detail;
3030
/// Given .INT code coverage for a test run, maps it to .CLS/.MAC.
3131
ClassMethod MapRunCoverage(pRunIndex As %Integer) As %Status
3232
{
33+
Set tCursorOpen = 0
3334
Set tSC = $$$OK
3435
Try {
3536
Set tRun = ##class(TestCoverage.Data.Run).%OpenId(pRunIndex,,.tSC)
@@ -57,15 +58,17 @@ ClassMethod MapRunCoverage(pRunIndex As %Integer) As %Status
5758

5859
// Here's a worse-performing approach with some extrinsic calls that ideally wouldn't be necessary:
5960
&SQL(
60-
INSERT OR UPDATE %NOLOCK %NOCHECK INTO TestCoverage_Data.Coverage
61-
(Run,Hash,TestPath,CoveredLines,Ignore)
62-
SELECT :pRunIndex,map.ToHash,%exact source.TestPath,TestCoverage.BITWISE_OR(
61+
/* INSERT OR UPDATE %NOLOCK %NOCHECK INTO TestCoverage_Data.Coverage
62+
(Run,Hash,TestPath,CoveredLines,Ignore) */
63+
DECLARE C0 CURSOR FOR
64+
SELECT map.ToHash,source.TestPath,TestCoverage.BITWISE_OR(
6365
TestCoverage.LIST_TO_BIT(%DLIST(
6466
CASE TestCoverage.BIT_VALUE(source.CoveredLines,map.FromLine)
6567
WHEN 1 THEN map.ToLine
6668
ELSE NULL END)),oldCoverage.CoveredLines),
6769
map.ToHash->Generated
68-
FROM TestCoverage_Data.Coverage source
70+
INTO :hToHash, :hTestPath, :hCoveredLines, :hIgnore
71+
FROM %NOPARALLEL TestCoverage_Data.Coverage source
6972
JOIN TestCoverage_Data.CodeUnitMap map
7073
ON source.Hash = map.FromHash
7174
LEFT JOIN TestCoverage_Data.Coverage oldCoverage
@@ -76,9 +79,33 @@ ClassMethod MapRunCoverage(pRunIndex As %Integer) As %Status
7679
AND source.Ignore = 0
7780
AND source.Calculated = 0
7881
GROUP BY map.ToHash,source.TestPath)
82+
83+
&sql(OPEN C0)
7984
If (SQLCODE < 0) {
8085
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
8186
}
87+
Set tCursorOpen = 1
88+
89+
For {
90+
&SQL(FETCH C0)
91+
If (SQLCODE < 0) {
92+
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
93+
} ElseIf (SQLCODE) {
94+
Quit
95+
}
96+
If ##class(TestCoverage.Data.Coverage).UniqueCoverageDataExists(pRunIndex,hToHash,hTestPath,.tID) {
97+
Set tCoverage = ##class(TestCoverage.Data.Coverage).%OpenId(tID,,.tSC)
98+
$$$ThrowOnError(tSC)
99+
} Else {
100+
Set tCoverage = ##class(TestCoverage.Data.Coverage).%New()
101+
Do tCoverage.RunSetObjectId(pRunIndex)
102+
Do tCoverage.HashSetObjectId(hToHash)
103+
Set tCoverage.TestPath = hTestPath
104+
}
105+
Set tCoverage.Ignore = hIgnore
106+
Set tCoverage.CoveredLines = $BitLogic(tCoverage.CoveredLines|hCoveredLines)
107+
$$$ThrowOnError(tCoverage.%Save())
108+
}
82109

83110
// Copy any other metrics captured/requested as well.
84111
For i=1:1:tRun.Metrics.Count() {
@@ -117,6 +144,9 @@ ClassMethod MapRunCoverage(pRunIndex As %Integer) As %Status
117144
} Catch e {
118145
Set tSC = e.AsStatus()
119146
}
147+
If tCursorOpen {
148+
&sql(CLOSE C0)
149+
}
120150
Quit tSC
121151
}
122152

@@ -161,4 +191,3 @@ Storage Default
161191
}
162192

163193
}
164-

cls/TestCoverage/UI/ResultDetailViewer.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
1717
<vgroup width="80%" align="center">
1818
<hgroup align="left" enclosingClass="box" cellAlign="even">
1919
<vgroup labelPosition="left">
20-
<tc:select id="testPath" label="Test Path" sql="select distinct %exact TestPath from TestCoverage_Data.Coverage where Run = ? and Hash = ?" onchange="zenPage.testFilterChanged(zenThis)">
20+
<tc:select id="testPath" label="Test Path" sql="select distinct TestPath from TestCoverage_Data.Coverage where Run = ? and Hash = ?" onchange="zenPage.testFilterChanged(zenThis)">
2121
<parameter value="#(%page.testIndex)#" />
2222
<parameter value="#(%page.codeUnit)#" />
2323
</tc:select>
@@ -65,4 +65,3 @@ ClientMethod onloadHandler() [ Language = javascript ]
6565
}
6666

6767
}
68-

cls/TestCoverage/UI/SimpleResultViewer.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
1818
<hgroup align="left" enclosingClass="box" cellAlign="even">
1919
<vgroup labelPosition="left">
2020
<tc:select id="testIndex" label="Test Index" sql="select distinct Run from TestCoverage_Data.Coverage order by Run desc" onchange="zenPage.testFilterChanged(zenThis)" />
21-
<tc:select id="testPath" label="Test Path" sql="select distinct %exact TestPath from TestCoverage_Data.Coverage where Run = ?" onchange="zenPage.testFilterChanged(zenThis)">
21+
<tc:select id="testPath" label="Test Path" sql="select distinct TestPath from TestCoverage_Data.Coverage where Run = ?" onchange="zenPage.testFilterChanged(zenThis)">
2222
<parameter value="#(%page.testIndex)#" />
2323
</tc:select>
2424

2525
<spacer height="25px" />
2626

2727
<tc:select id="codeCovered" label="Code Unit"
28-
sql="select distinct %exact Hash,Hash->Name||'.'||Hash->Type
28+
sql="select distinct Hash,Hash->Name||'.'||Hash->Type
2929
from TestCoverage_Data.Coverage d,(select ? as Run, ? as TestPath) params
3030
where d.Run = params.Run
3131
and (params.TestPath is null or params.TestPath = d.TestPath)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TestCoverage.PKG
2+
-TestCoverage.UI.PKG

module.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<Export generator="Cache" version="25">
33
<Document name="TestCoverage.ZPM"><Module>
44
<Name>TestCoverage</Name>
5-
<Version>2.1.0</Version>
5+
<Version>2.1.1</Version>
66
<Packaging>module</Packaging>
77
<Resources>
88
<Resource Name="TestCoverage.PKG">
99
</Resource>
10-
<Resource Name="TestCoverage.DataType.PKG" Deploy="false">
10+
<Resource Name="TestCoverage.DataType.PKG">
1111
</Resource>
12-
<Resource Name="TestCoverage.Utils.LineByLineMonitor.CLS" Deploy="true">
12+
<Resource Name="TestCoverage.Utils.LineByLineMonitor.CLS">
1313
</Resource>
1414
<Resource Name="TestCoverage.INC">
1515
</Resource>

0 commit comments

Comments
 (0)