Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 851f827

Browse files
committed
bug fixes in publish cc
1 parent a490104 commit 851f827

File tree

6 files changed

+287
-23
lines changed

6 files changed

+287
-23
lines changed

src/agent/codecoveragesummaryreader.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,18 @@ export class JacocoSummaryReader implements ccp.ICodeCoverageReader {
7070
var counterNode = reportNode.counter.at(i);
7171
var attributes = counterNode.attributes();
7272
if (attributes && attributes.type && attributes.covered && attributes.missed) {
73-
var total = Number(attributes.covered) + Number(attributes.missed);
74-
this.command.info(attributes.type + " : " + attributes.covered + "/" + total + " covered.");
75-
var coverageStat = SummaryReaderUtilities.getCodeCoverageStatistics(attributes.type, attributes.covered, total, attributes.type);
76-
coverageStats.push(coverageStat);
73+
var covered = parseInt(attributes.covered);
74+
var missed = parseInt(attributes.missed);
75+
if (!isNaN(covered) && !isNaN(missed)) {
76+
var total = covered + missed;
77+
this.command.info(attributes.type + " : " + covered + "/" + total + " covered.");
78+
var coverageStat = SummaryReaderUtilities.getCodeCoverageStatistics(utilities.toTitleCase(attributes.type), covered, total, attributes.type);
79+
coverageStats.push(coverageStat);
80+
}
81+
else {
82+
defer.reject(new Error("Unable to retreive value for '" + attributes.type + "' from summary file. Verify the summary file is well formed and try again."));
83+
return defer.promise;
84+
}
7785
}
7886
}
7987
coverage.addResults(coverageStats);
@@ -144,15 +152,31 @@ export class CoberturaSummaryReader implements ccp.ICodeCoverageReader {
144152
var branchesTotal = attributes['branches-valid'];
145153

146154
if (linesTotal && linesCovered) {
147-
this.command.info("Lines : " + linesCovered + "/" + linesTotal + " covered.");
148-
var coverageStat = SummaryReaderUtilities.getCodeCoverageStatistics("Lines", linesCovered, linesTotal, "line");
149-
coverageStats.push(coverageStat);
155+
linesTotal = parseInt(linesTotal);
156+
linesCovered = parseInt(linesCovered);
157+
if (!isNaN(linesTotal) && !isNaN(linesCovered)) {
158+
this.command.info("Lines : " + linesCovered + "/" + linesTotal + " covered.");
159+
var coverageStat = SummaryReaderUtilities.getCodeCoverageStatistics("Lines", linesCovered, linesTotal, "line");
160+
coverageStats.push(coverageStat);
161+
}
162+
else {
163+
defer.reject(new Error("Unable to retreive value for 'lines' from summary file. Verify the summary file is well formed and try again."));
164+
return defer.promise;
165+
}
150166
}
151167

152168
if (branchesCovered && branchesTotal) {
153-
this.command.info("Branches : " + branchesCovered + "/" + branchesTotal + " covered.");
154-
var coverageStat = SummaryReaderUtilities.getCodeCoverageStatistics("Branches", branchesCovered, branchesTotal, "branch");
155-
coverageStats.push(coverageStat);
169+
branchesCovered = parseInt(branchesCovered);
170+
branchesTotal = parseInt(branchesTotal);
171+
if (!isNaN(branchesCovered) && !isNaN(branchesTotal)) {
172+
this.command.info("Branches : " + branchesCovered + "/" + branchesTotal + " covered.");
173+
var coverageStat = SummaryReaderUtilities.getCodeCoverageStatistics("Branches", branchesCovered, branchesTotal, "branch");
174+
coverageStats.push(coverageStat);
175+
}
176+
else {
177+
defer.reject(new Error("Unable to retreive value for 'branches' from summary file. Verify the summary file is well formed and try again."));
178+
return defer.promise;
179+
}
156180
}
157181

158182
coverage.addResults(coverageStats);

src/agent/utilities.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export interface GetOrCreateResult<T> {
1515
created: boolean;
1616
result: T;
1717
}
18+
19+
//converts inputString to titleCase string. For example, "abc def" is converted to "Abc Def"
20+
export function toTitleCase(inputString: string): string {
21+
if (inputString) {
22+
return inputString.replace(/\w\S*/g, function(str) { return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase(); });
23+
}
24+
return inputString;
25+
}
1826

1927
// returns a substring that is common from first. For example, for "abcd" and "abdf", "ab" is returned.
2028
export function sharedSubString(string1: string, string2: string): string {
@@ -45,7 +53,7 @@ export function sortStringArray(list): string[] {
4553

4654
// returns true if path exists and it is a directory else false.
4755
export function isDirectoryExists(path: string): boolean {
48-
try {
56+
try {
4957
return fs.lstatSync(path).isDirectory();
5058
}
5159
catch (error) {
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
3+
4+
<coverage line-rate="0.5" branch-rate="1.0" lines-covered="lines" lines-valid="22" branches-covered="2.4" branches-valid="8.8" complexity="1.0" version="2.1.1" timestamp="1444371063012">
5+
<sources>
6+
<source>F:/Test/ant/TestCode/Ant/src</source>
7+
</sources>
8+
<packages>
9+
<package name="" line-rate="0.5" branch-rate="1.0" complexity="1.0">
10+
<classes>
11+
<class name="SampleUtil" filename="SampleUtil.java" line-rate="0.6666666666666666" branch-rate="1.0" complexity="1.0">
12+
<methods>
13+
<method name="&lt;init&gt;" signature="(Ljava/lang/String;)V" line-rate="1.0" branch-rate="1.0" complexity="0">
14+
<lines>
15+
<line number="6" hits="2" branch="false"/>
16+
<line number="7" hits="2" branch="false"/>
17+
<line number="8" hits="2" branch="false"/>
18+
</lines>
19+
</method>
20+
<method name="GetMessage" signature="()Ljava/lang/String;" line-rate="1.0" branch-rate="1.0" complexity="0">
21+
<lines>
22+
<line number="18" hits="1" branch="false"/>
23+
</lines>
24+
</method>
25+
<method name="printMessage" signature="()Ljava/lang/String;" line-rate="0.0" branch-rate="1.0" complexity="0">
26+
<lines>
27+
<line number="12" hits="0" branch="false"/>
28+
<line number="13" hits="0" branch="false"/>
29+
</lines>
30+
</method>
31+
</methods>
32+
<lines>
33+
<line number="6" hits="2" branch="false"/>
34+
<line number="7" hits="2" branch="false"/>
35+
<line number="8" hits="2" branch="false"/>
36+
<line number="12" hits="0" branch="false"/>
37+
<line number="13" hits="0" branch="false"/>
38+
<line number="18" hits="1" branch="false"/>
39+
</lines>
40+
</class>
41+
<class name="UtilTest" filename="UtilTest.java" line-rate="0.875" branch-rate="1.0" complexity="1.0">
42+
<methods>
43+
<method name="&lt;init&gt;" signature="()V" line-rate="1.0" branch-rate="1.0" complexity="0">
44+
<lines>
45+
<line number="5" hits="2" branch="false"/>
46+
<line number="6" hits="2" branch="false"/>
47+
<line number="7" hits="2" branch="false"/>
48+
</lines>
49+
</method>
50+
<method name="testMethod1" signature="()V" line-rate="1.0" branch-rate="1.0" complexity="0">
51+
<lines>
52+
<line number="11" hits="1" branch="false"/>
53+
<line number="12" hits="1" branch="false"/>
54+
</lines>
55+
</method>
56+
<method name="testMethod2" signature="()V" line-rate="0.6666666666666666" branch-rate="1.0" complexity="0">
57+
<lines>
58+
<line number="16" hits="1" branch="false"/>
59+
<line number="17" hits="1" branch="false"/>
60+
<line number="18" hits="0" branch="false"/>
61+
</lines>
62+
</method>
63+
</methods>
64+
<lines>
65+
<line number="5" hits="2" branch="false"/>
66+
<line number="6" hits="2" branch="false"/>
67+
<line number="7" hits="2" branch="false"/>
68+
<line number="11" hits="1" branch="false"/>
69+
<line number="12" hits="1" branch="false"/>
70+
<line number="16" hits="1" branch="false"/>
71+
<line number="17" hits="1" branch="false"/>
72+
<line number="18" hits="0" branch="false"/>
73+
</lines>
74+
</class>
75+
<class name="UtilTest2" filename="UtilTest2.java" line-rate="0.0" branch-rate="1.0" complexity="1.0">
76+
<methods>
77+
<method name="&lt;init&gt;" signature="()V" line-rate="0.0" branch-rate="1.0" complexity="0">
78+
<lines>
79+
<line number="5" hits="0" branch="false"/>
80+
<line number="6" hits="0" branch="false"/>
81+
<line number="7" hits="0" branch="false"/>
82+
</lines>
83+
</method>
84+
<method name="testMethod1" signature="()V" line-rate="0.0" branch-rate="1.0" complexity="0">
85+
<lines>
86+
<line number="11" hits="0" branch="false"/>
87+
<line number="12" hits="0" branch="false"/>
88+
</lines>
89+
</method>
90+
<method name="testMethod2" signature="()V" line-rate="0.0" branch-rate="1.0" complexity="0">
91+
<lines>
92+
<line number="16" hits="0" branch="false"/>
93+
<line number="17" hits="0" branch="false"/>
94+
<line number="18" hits="0" branch="false"/>
95+
</lines>
96+
</method>
97+
</methods>
98+
<lines>
99+
<line number="5" hits="0" branch="false"/>
100+
<line number="6" hits="0" branch="false"/>
101+
<line number="7" hits="0" branch="false"/>
102+
<line number="11" hits="0" branch="false"/>
103+
<line number="12" hits="0" branch="false"/>
104+
<line number="16" hits="0" branch="false"/>
105+
<line number="17" hits="0" branch="false"/>
106+
<line number="18" hits="0" branch="false"/>
107+
</lines>
108+
</class>
109+
</classes>
110+
</package>
111+
</packages>
112+
</coverage>

src/test/codecoveragefiles/jacoco.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<counter type="METHOD" missed="4" covered="2"/>
8181
<counter type="CLASS" missed="0" covered="2"/>
8282
</package>
83-
<counter type="INSTRUCTION" missed="14" covered="8"/>
83+
<counter type="INSTRUCTION" missed="14.6" covered="8.2"/>
8484
<counter type="LINE" missed="5" covered="2"/>
8585
<counter type="COMPLEXITY" missed="4" covered="2"/>
8686
<counter type="METHOD" missed="4" covered="2"/>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.0//EN" "report.dtd">
3+
<report name="my-app">
4+
<sessioninfo id="sgupta-dev-62e7c9fb" start="1437729720597" dump="1437729720957"/>
5+
<package name="com/mycompany/app">
6+
<class name="com/mycompany/app/App2">
7+
<method name="&lt;init&gt;" desc="()V" line="7">
8+
<counter type="INSTRUCTION" missed="3" covered="0"/>
9+
<counter type="LINE" missed="1" covered="0"/>
10+
<counter type="COMPLEXITY" missed="1" covered="0"/>
11+
<counter type="METHOD" missed="1" covered="0"/>
12+
</method>
13+
<method name="sub" desc="(II)I" line="12">
14+
<counter type="INSTRUCTION" missed="0" covered="4"/>
15+
<counter type="LINE" missed="0" covered="1"/>
16+
<counter type="COMPLEXITY" missed="0" covered="1"/>
17+
<counter type="METHOD" missed="0" covered="1"/>
18+
</method>
19+
<method name="mul" desc="(II)I" line="16">
20+
<counter type="INSTRUCTION" missed="4" covered="0"/>
21+
<counter type="LINE" missed="1" covered="0"/>
22+
<counter type="COMPLEXITY" missed="1" covered="0"/>
23+
<counter type="METHOD" missed="1" covered="0"/>
24+
</method>
25+
<counter type="INSTRUCTION" missed="7" covered="4"/>
26+
<counter type="LINE" missed="2" covered="1"/>
27+
<counter type="COMPLEXITY" missed="2" covered="1"/>
28+
<counter type="METHOD" missed="2" covered="1"/>
29+
<counter type="CLASS" missed="0" covered="1"/>
30+
</class>
31+
<class name="com/mycompany/app/App">
32+
<method name="&lt;init&gt;" desc="()V" line="7">
33+
<counter type="INSTRUCTION" missed="3" covered="0"/>
34+
<counter type="LINE" missed="1" covered="0"/>
35+
<counter type="COMPLEXITY" missed="1" covered="0"/>
36+
<counter type="METHOD" missed="1" covered="0"/>
37+
</method>
38+
<method name="main" desc="([Ljava/lang/String;)V" line="11">
39+
<counter type="INSTRUCTION" missed="4" covered="0"/>
40+
<counter type="LINE" missed="2" covered="0"/>
41+
<counter type="COMPLEXITY" missed="1" covered="0"/>
42+
<counter type="METHOD" missed="1" covered="0"/>
43+
</method>
44+
<method name="add" desc="(II)I" line="16">
45+
<counter type="INSTRUCTION" missed="0" covered="4"/>
46+
<counter type="LINE" missed="0" covered="1"/>
47+
<counter type="COMPLEXITY" missed="0" covered="1"/>
48+
<counter type="METHOD" missed="0" covered="1"/>
49+
</method>
50+
<counter type="INSTRUCTION" missed="7" covered="4"/>
51+
<counter type="LINE" missed="3" covered="1"/>
52+
<counter type="COMPLEXITY" missed="2" covered="1"/>
53+
<counter type="METHOD" missed="2" covered="1"/>
54+
<counter type="CLASS" missed="0" covered="1"/>
55+
</class>
56+
<sourcefile name="App.java">
57+
<line nr="7" mi="3" ci="0" mb="0" cb="0"/>
58+
<line nr="11" mi="3" ci="0" mb="0" cb="0"/>
59+
<line nr="12" mi="1" ci="0" mb="0" cb="0"/>
60+
<line nr="16" mi="0" ci="4" mb="0" cb="0"/>
61+
<counter type="INSTRUCTION" missed="7" covered="4"/>
62+
<counter type="LINE" missed="3" covered="1"/>
63+
<counter type="COMPLEXITY" missed="2" covered="1"/>
64+
<counter type="METHOD" missed="2" covered="1"/>
65+
<counter type="CLASS" missed="0" covered="1"/>
66+
</sourcefile>
67+
<sourcefile name="App2.java">
68+
<line nr="7" mi="3" ci="0" mb="0" cb="0"/>
69+
<line nr="12" mi="0" ci="4" mb="0" cb="0"/>
70+
<line nr="16" mi="4" ci="0" mb="0" cb="0"/>
71+
<counter type="INSTRUCTION" missed="7" covered="4"/>
72+
<counter type="LINE" missed="2" covered="1"/>
73+
<counter type="COMPLEXITY" missed="2" covered="1"/>
74+
<counter type="METHOD" missed="2" covered="1"/>
75+
<counter type="CLASS" missed="0" covered="1"/>
76+
</sourcefile>
77+
<counter type="INSTRUCTION" missed="14" covered="8"/>
78+
<counter type="LINE" missed="5" covered="2"/>
79+
<counter type="COMPLEXITY" missed="4" covered="2"/>
80+
<counter type="METHOD" missed="4" covered="2"/>
81+
<counter type="CLASS" missed="0" covered="2"/>
82+
</package>
83+
<counter type="INSTRUCTION" missed="instr" covered="8.2"/>
84+
<counter type="LINE" missed="5" covered="2"/>
85+
<counter type="COMPLEXITY" missed="4" covered="2"/>
86+
<counter type="METHOD" missed="4" covered="2"/>
87+
<counter type="CLASS" missed="0" covered="2"/>
88+
</report>

0 commit comments

Comments
 (0)