fix: potentially correct cobertura line hits calculation

Signed-off-by: Anton Ganhammar <ganhammar@gmail.com>
This commit is contained in:
Anton Ganhammar
2023-08-22 22:16:17 +02:00
parent aa66a0bde0
commit ce9412d62b
11 changed files with 2711 additions and 2660 deletions
@@ -87,10 +87,10 @@ describe('aggregateCoverage', () => {
percentage: 81.55,
},
line: {
available: 2632,
covered: 2079,
missed: 553,
percentage: 78.99,
available: 2559,
covered: 2027,
missed: 532,
percentage: 79.21,
},
timestamp: 1234567890,
},
@@ -105,10 +105,10 @@ describe('aggregateCoverage', () => {
percentage: 67.12,
},
line: {
available: 110,
covered: 91,
missed: 19,
percentage: 82.73,
available: 95,
covered: 77,
missed: 18,
percentage: 81.05,
},
timestamp: 1234567890,
},
@@ -141,10 +141,10 @@ describe('aggregateCoverage', () => {
percentage: 55.26,
},
line: {
available: 175,
covered: 124,
available: 169,
covered: 118,
missed: 51,
percentage: 70.86,
percentage: 69.82,
},
timestamp: 1234567890,
},
@@ -1,11 +1,12 @@
[
{
"filename": "src/main/scala/com/example/Main.scala",
"branchHits": {},
"lineHits": {
"100": 4,
"103": 2,
"104": 4,
"105": 4,
"100": 2,
"103": 1,
"104": 2,
"105": 2,
"112": 2,
"114": 4,
"115": 2,
@@ -25,14 +26,14 @@
"148": 1,
"149": 1,
"150": 1,
"160": 2,
"163": 8,
"164": 4,
"166": 2,
"167": 4,
"168": 6,
"169": 6,
"170": 4,
"160": 1,
"163": 4,
"164": 2,
"166": 1,
"167": 2,
"168": 3,
"169": 3,
"170": 2,
"178": 1,
"179": 1,
"181": 1,
@@ -40,51 +41,51 @@
"183": 3,
"187": 1,
"188": 3,
"202": 4,
"203": 6,
"204": 4,
"202": 2,
"203": 3,
"204": 2,
"210": 5,
"26": 4,
"27": 4,
"28": 4,
"30": 4,
"33": 4,
"35": 2,
"36": 2,
"37": 4,
"38": 2,
"42": 2,
"44": 2,
"46": 2,
"48": 2,
"50": 2,
"52": 2,
"53": 2,
"55": 2,
"56": 2,
"58": 2,
"60": 2,
"61": 2,
"64": 2,
"65": 6,
"68": 4,
"73": 2,
"75": 10,
"77": 4,
"26": 2,
"27": 2,
"28": 2,
"30": 2,
"33": 2,
"35": 1,
"36": 1,
"37": 2,
"38": 1,
"42": 1,
"44": 1,
"46": 1,
"48": 1,
"50": 1,
"52": 1,
"53": 1,
"55": 1,
"56": 1,
"58": 1,
"60": 1,
"61": 1,
"64": 1,
"65": 3,
"68": 2,
"73": 1,
"75": 5,
"77": 2,
"83": 1,
"84": 2,
"85": 3,
"86": 3,
"87": 1,
"88": 6,
"95": 2,
"97": 8,
"99": 2
},
"branchHits": {}
"95": 1,
"97": 4,
"99": 1
}
},
{
"filename": "src/main/scala/com/example/Other.scala",
"branchHits": {},
"lineHits": {
"103": 6,
"104": 2,
@@ -100,9 +101,9 @@
"123": 3,
"124": 1,
"129": 7,
"132": 2,
"133": 4,
"134": 2,
"132": 1,
"133": 2,
"134": 1,
"138": 1,
"139": 2,
"140": 2,
@@ -125,13 +126,13 @@
"33": 2,
"34": 2,
"37": 0,
"42": 4,
"44": 2,
"45": 2,
"46": 2,
"49": 4,
"50": 10,
"52": 4,
"42": 2,
"44": 1,
"45": 1,
"46": 1,
"49": 2,
"50": 5,
"52": 2,
"59": 5,
"61": 4,
"64": 2,
@@ -151,16 +152,15 @@
"92": 4,
"93": 3,
"94": 2
},
"branchHits": {}
}
},
{
"filename": "src/main/scala/com/example/utils/Util.scala",
"branchHits": {},
"lineHits": {
"13": 2,
"8": 4,
"7": 2
},
"branchHits": {}
"7": 1,
"8": 2,
"13": 1
}
}
]
@@ -1,34 +1,13 @@
[
{
"filename": "src/atoms/BoxShadow/box-shadow.ts",
"branchHits": {},
"lineHits": {
"4": 5
},
"branchHits": {}
}
},
{
"filename": "src/atoms/Button/button.tsx",
"lineHits": {
"17": 41,
"34": 41,
"70": 82,
"72": 82,
"74": 41,
"31": 41,
"32": 41,
"35": 0,
"36": 0,
"37": 0,
"38": 0,
"39": 0,
"40": 0,
"41": 0,
"42": 0,
"43": 0,
"47": 41,
"68": 10,
"75": 41
},
"branchHits": {
"35": {
"covered": 0,
@@ -50,113 +29,55 @@
"missed": 0,
"available": 2
}
},
"lineHits": {
"31": 41,
"32": 41,
"34": 41,
"35": 0,
"36": 0,
"37": 0,
"38": 0,
"39": 0,
"40": 0,
"41": 0,
"42": 0,
"43": 0,
"47": 41,
"68": 10,
"70": 41,
"72": 41,
"75": 41
}
},
{
"filename": "src/atoms/Container/components.ts",
"branchHits": {},
"lineHits": {
"5": 70,
"19": 70,
"20": 70,
"23": 70,
"4": 13,
"13": 13
},
"branchHits": {}
"5": 35,
"13": 13,
"19": 35,
"20": 35,
"23": 35
}
},
{
"filename": "src/atoms/Container/container.tsx",
"branchHits": {},
"lineHits": {
"12": 35,
"20": 35
},
"branchHits": {}
}
},
{
"filename": "src/atoms/DownArrow/down-arrow.tsx",
"branchHits": {},
"lineHits": {
"3": 28,
"4": 28
},
"branchHits": {}
}
},
{
"filename": "src/molecules/Hero/components.ts",
"lineHits": {
"26": 20,
"28": 10,
"94": 10,
"103": 20,
"121": 10,
"182": 20,
"203": 5,
"218": 5,
"236": 10,
"241": 10,
"249": 8,
"254": 4,
"264": 4,
"277": 8,
"282": 4,
"294": 8,
"299": 6,
"25": 2,
"29": 10,
"37": 3,
"39": 3,
"40": 3,
"42": 3,
"43": 1,
"44": 1,
"45": 0,
"46": 0,
"48": 1,
"52": 0,
"53": 1,
"57": 0,
"59": 1,
"60": 1,
"63": 3,
"95": 10,
"112": 2,
"122": 10,
"125": 9,
"134": 0,
"151": 1,
"170": 2,
"181": 2,
"194": 2,
"204": 5,
"207": 3,
"209": 0,
"211": 1,
"213": 1,
"219": 5,
"222": 3,
"224": 0,
"226": 0,
"228": 1,
"230": 1,
"245": 2,
"255": 4,
"258": 3,
"260": 1,
"265": 4,
"268": 2,
"270": 1,
"272": 1,
"283": 4,
"286": 2,
"288": 1,
"290": 1,
"298": 2,
"304": 2,
"311": 2,
"319": 2,
"329": 2,
"361": 2,
"371": 2
},
"branchHits": {
"29": {
"covered": 2,
@@ -273,25 +194,89 @@
"missed": 1,
"available": 2
}
},
"lineHits": {
"25": 2,
"26": 10,
"29": 10,
"37": 3,
"39": 3,
"40": 3,
"42": 3,
"43": 1,
"44": 1,
"45": 0,
"46": 0,
"48": 1,
"52": 0,
"53": 1,
"57": 0,
"59": 1,
"60": 1,
"63": 3,
"95": 10,
"103": 10,
"112": 2,
"122": 10,
"125": 9,
"134": 0,
"151": 1,
"170": 2,
"181": 2,
"182": 10,
"194": 2,
"204": 5,
"207": 3,
"209": 0,
"211": 1,
"213": 1,
"219": 5,
"222": 3,
"224": 0,
"226": 0,
"228": 1,
"230": 1,
"236": 5,
"241": 5,
"245": 2,
"249": 4,
"255": 4,
"258": 3,
"260": 1,
"265": 4,
"268": 2,
"270": 1,
"272": 1,
"277": 4,
"283": 4,
"286": 2,
"288": 1,
"290": 1,
"294": 4,
"298": 2,
"299": 3,
"304": 2,
"311": 2,
"319": 2,
"329": 2,
"361": 2,
"371": 2
}
},
{
"filename": "src/molecules/Hero/hero.tsx",
"lineHits": {
"40": 10,
"72": 0,
"127": 3,
"56": 10,
"58": 10,
"73": 0,
"128": 3
},
"branchHits": {
"73": {
"covered": 0,
"missed": 2,
"available": 2
}
},
"lineHits": {
"56": 10,
"58": 10,
"73": 0,
"128": 3
}
}
]
@@ -1,6 +1,7 @@
[
{
"filename": "Sources/TDSOptions.m",
"branchHits": {},
"lineHits": {
"32": 0,
"33": 0,
@@ -38,11 +39,11 @@
"75": 0,
"76": 0,
"77": 0
},
"branchHits": {}
}
},
{
"filename": "Sources/TDSUserLock.m",
"branchHits": {},
"lineHits": {
"17": 0,
"18": 0,
@@ -88,11 +89,11 @@
"68": 0,
"69": 0,
"70": 0
},
"branchHits": {}
}
},
{
"filename": "Sources/TDSUserManager.m",
"branchHits": {},
"lineHits": {
"24": 0,
"25": 0,
@@ -328,11 +329,11 @@
"294": 0,
"295": 0,
"296": 0
},
"branchHits": {}
}
},
{
"filename": "Sources/TDSUtil.m",
"branchHits": {},
"lineHits": {
"8": 0,
"9": 0,
@@ -345,7 +346,6 @@
"18": 0,
"19": 0,
"20": 0
},
"branchHits": {}
}
}
]
@@ -1,6 +1,7 @@
[
{
"filename": "src/graphql/queries.ts",
"branchHits": {},
"lineHits": {
"1": 3,
"3": 3,
@@ -9,95 +10,10 @@
"80": 3,
"92": 3,
"138": 3
},
"branchHits": {}
}
},
{
"filename": "src/graphql/resolvers.ts",
"lineHits": {
"22": 17,
"28": 14,
"36": 16,
"27": 8,
"35": 8,
"43": 9,
"51": 15,
"56": 8,
"61": 8,
"50": 8,
"55": 8,
"60": 8,
"128": 7,
"139": 4,
"145": 8,
"160": 8,
"177": 7,
"185": 13,
"70": 12,
"78": 8,
"81": 8,
"84": 4,
"97": 12,
"103": 8,
"114": 8,
"144": 8,
"159": 8,
"176": 8,
"184": 8,
"1": 4,
"2": 4,
"3": 4,
"5": 4,
"6": 4,
"7": 4,
"8": 4,
"9": 4,
"10": 4,
"14": 4,
"21": 4,
"24": 17,
"32": 10,
"37": 12,
"42": 4,
"45": 9,
"47": 9,
"52": 11,
"57": 4,
"62": 4,
"67": 4,
"73": 8,
"83": 4,
"85": 4,
"86": 4,
"87": 4,
"88": 4,
"94": 4,
"95": 4,
"98": 4,
"104": 4,
"107": 4,
"115": 4,
"118": 4,
"119": 4,
"120": 0,
"124": 4,
"130": 7,
"132": 7,
"134": 7,
"136": 7,
"140": 4,
"151": 4,
"165": 4,
"166": 4,
"167": 4,
"168": 1,
"169": 4,
"178": 3,
"186": 9,
"187": 9,
"193": 2,
"194": 0
},
"branchHits": {
"86": {
"covered": 2,
@@ -124,33 +40,89 @@
"missed": 1,
"available": 2
}
},
"lineHits": {
"1": 4,
"2": 4,
"3": 4,
"5": 4,
"6": 4,
"7": 4,
"8": 4,
"9": 4,
"10": 4,
"14": 4,
"21": 4,
"24": 17,
"27": 4,
"28": 4,
"32": 10,
"35": 4,
"36": 4,
"37": 12,
"42": 4,
"45": 9,
"47": 9,
"50": 4,
"51": 4,
"52": 11,
"55": 4,
"56": 4,
"57": 4,
"60": 4,
"61": 4,
"62": 4,
"67": 4,
"70": 4,
"73": 8,
"78": 4,
"81": 4,
"83": 4,
"85": 4,
"86": 4,
"87": 4,
"88": 4,
"94": 4,
"95": 4,
"97": 4,
"98": 4,
"103": 4,
"104": 4,
"107": 4,
"114": 4,
"115": 4,
"118": 4,
"119": 4,
"120": 0,
"124": 4,
"130": 7,
"132": 7,
"134": 7,
"136": 7,
"140": 4,
"144": 4,
"145": 4,
"151": 4,
"159": 4,
"160": 4,
"165": 4,
"166": 4,
"167": 4,
"168": 1,
"169": 4,
"176": 4,
"177": 4,
"178": 3,
"184": 4,
"185": 4,
"186": 9,
"187": 9,
"193": 2,
"194": 0
}
},
{
"filename": "src/graphql/router.ts",
"lineHits": {
"21": 1,
"22": 2,
"43": 21,
"53": 40,
"12": 3,
"14": 3,
"23": 1,
"26": 0,
"32": 1,
"33": 1,
"34": 1,
"37": 0,
"54": 11,
"55": 0,
"57": 11,
"58": 11,
"63": 11,
"64": 11,
"65": 10,
"66": 10,
"68": 1
},
"branchHits": {
"23": {
"covered": 3,
@@ -177,45 +149,55 @@
"missed": 1,
"available": 2
}
},
"lineHits": {
"12": 3,
"14": 3,
"22": 1,
"23": 1,
"26": 0,
"32": 1,
"33": 1,
"34": 1,
"37": 0,
"43": 3,
"53": 18,
"54": 11,
"55": 0,
"57": 11,
"58": 11,
"63": 11,
"64": 11,
"65": 10,
"66": 10,
"68": 1
}
},
{
"filename": "src/graphql/schema.ts",
"lineHits": {
"9": 7,
"1": 3,
"2": 3,
"4": 3,
"5": 3,
"11": 0,
"13": 4,
"15": 4,
"16": 4,
"17": 4,
"19": 4
},
"branchHits": {
"11": {
"covered": 0,
"missed": 1,
"available": 1
}
},
"lineHits": {
"1": 3,
"2": 3,
"4": 3,
"5": 3,
"9": 3,
"11": 0,
"13": 4,
"15": 4,
"16": 4,
"17": 4,
"19": 4
}
},
{
"filename": "src/graphql/transforms.ts",
"lineHits": {
"9": 10,
"20": 5,
"13": 6,
"14": 2,
"15": 6,
"16": 1,
"17": 6,
"23": 1,
"24": 0,
"25": 1
},
"branchHits": {
"13": {
"covered": 2,
@@ -232,36 +214,22 @@
"missed": 1,
"available": 2
}
},
"lineHits": {
"9": 4,
"13": 6,
"14": 2,
"15": 6,
"16": 1,
"17": 6,
"20": 4,
"23": 1,
"24": 0,
"25": 1
}
},
{
"filename": "src/workers/primary-worker.js",
"lineHits": {
"16": 0,
"25": 0,
"49": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"8": 0,
"17": 0,
"21": 0,
"22": 0,
"23": 0,
"24": 0,
"27": 0,
"28": 0,
"31": 0,
"33": 0,
"34": 0,
"37": 0,
"38": 0,
"48": 0,
"51": 0,
"53": 0
},
"branchHits": {
"17": {
"covered": 0,
@@ -278,32 +246,36 @@
"missed": 2,
"available": 2
}
}
},
{
"filename": "src/workers/secondary-worker.js",
},
"lineHits": {
"4": 0,
"13": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"9": 0,
"10": 0,
"11": 0,
"12": 0,
"14": 0,
"15": 0,
"6": 0,
"8": 0,
"16": 0,
"18": 0,
"19": 0,
"17": 0,
"21": 0,
"22": 0,
"23": 0,
"24": 0,
"25": 0,
"26": 0,
"27": 0,
"29": 0
},
"28": 0,
"31": 0,
"33": 0,
"34": 0,
"37": 0,
"38": 0,
"48": 0,
"49": 0,
"51": 0,
"53": 0
}
},
{
"filename": "src/workers/secondary-worker.js",
"branchHits": {
"5": {
"covered": 0,
@@ -320,6 +292,28 @@
"missed": 2,
"available": 2
}
},
"lineHits": {
"2": 0,
"4": 0,
"5": 0,
"9": 0,
"10": 0,
"11": 0,
"12": 0,
"13": 0,
"14": 0,
"15": 0,
"16": 0,
"18": 0,
"19": 0,
"22": 0,
"23": 0,
"24": 0,
"25": 0,
"26": 0,
"27": 0,
"29": 0
}
}
]
@@ -0,0 +1,47 @@
[
{
"filename": "src/Calc/Main.cs",
"lineHits": {
"5": 4,
"6": 4,
"7": 1,
"8": 0,
"9": 2,
"10": 1,
"11": 4
},
"branchHits": {
"5": {
"covered": 5,
"missed": 1,
"available": 6
}
}
},
{
"filename": "src/Calc/Math.cs",
"lineHits": {
"5": 1,
"6": 0,
"7": 2,
"8": 2,
"9": 0,
"11": 3,
"12": 1,
"14": 1,
"15": 1
},
"branchHits": {
"8": {
"covered": 1,
"missed": 1,
"available": 2
},
"11": {
"covered": 2,
"missed": 0,
"available": 2
}
}
}
]
@@ -0,0 +1,2 @@
src/Calc/Main.cs
src/Calc/Math.cs
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="0.8125" branch-rate="0.8" version="1.9" timestamp="1692517802" lines-covered="13" lines-valid="16" branches-covered="8" branches-valid="10">
<sources>
<source>/Some/Path/src/Calc/</source>
</sources>
<packages>
<package name="Calc" line-rate="0.8125" branch-rate="0.8" complexity="12">
<classes>
<class name="Calc.Main" filename="Main.cs" line-rate="0.8571" branch-rate="0.8332999999999999" complexity="6">
<methods>
<method name="Calc" signature="(System.Int32,System.Int32,System.String)" line-rate="0.8571" branch-rate="0.8332999999999999" complexity="6">
<lines>
<line number="5" hits="4" branch="True" condition-coverage="83.33% (5/6)">
<conditions>
<condition number="15" type="jump" coverage="100%" />
<condition number="28" type="jump" coverage="50%" />
<condition number="41" type="jump" coverage="100%" />
</conditions>
</line>
<line number="6" hits="4" branch="False" />
<line number="7" hits="1" branch="False" />
<line number="8" hits="0" branch="False" />
<line number="9" hits="2" branch="False" />
<line number="10" hits="1" branch="False" />
<line number="11" hits="4" branch="False" />
</lines>
</method>
</methods>
<lines>
<line number="5" hits="4" branch="True" condition-coverage="83.33% (5/6)">
<conditions>
<condition number="15" type="jump" coverage="100%" />
<condition number="28" type="jump" coverage="50%" />
<condition number="41" type="jump" coverage="100%" />
</conditions>
</line>
<line number="6" hits="4" branch="False" />
<line number="7" hits="1" branch="False" />
<line number="8" hits="0" branch="False" />
<line number="9" hits="2" branch="False" />
<line number="10" hits="1" branch="False" />
<line number="11" hits="4" branch="False" />
</lines>
</class>
<class name="Calc.Math" filename="Math.cs" line-rate="0.7777" branch-rate="0.75" complexity="6">
<methods>
<method name="Addition" signature="(System.Int32,System.Int32)" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="5" hits="1" branch="False" />
</lines>
</method>
<method name="Subtraction" signature="(System.Int32,System.Int32)" line-rate="0" branch-rate="1" complexity="1">
<lines>
<line number="6" hits="0" branch="False" />
</lines>
</method>
<method name="Division" signature="(System.Int32,System.Int32)" line-rate="0.8571" branch-rate="0.75" complexity="4">
<lines>
<line number="7" hits="2" branch="False" />
<line number="8" hits="2" branch="True" condition-coverage="50% (1/2)">
<conditions>
<condition number="7" type="jump" coverage="50%" />
</conditions>
</line>
<line number="9" hits="0" branch="False" />
<line number="11" hits="3" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="22" type="jump" coverage="100%" />
</conditions>
</line>
<line number="12" hits="1" branch="False" />
<line number="14" hits="1" branch="False" />
<line number="15" hits="1" branch="False" />
</lines>
</method>
</methods>
<lines>
<line number="5" hits="1" branch="False" />
<line number="6" hits="0" branch="False" />
<line number="7" hits="2" branch="False" />
<line number="8" hits="2" branch="True" condition-coverage="50% (1/2)">
<conditions>
<condition number="7" type="jump" coverage="50%" />
</conditions>
</line>
<line number="9" hits="0" branch="False" />
<line number="11" hits="3" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="22" type="jump" coverage="100%" />
</conditions>
</line>
<line number="12" hits="1" branch="False" />
<line number="14" hits="1" branch="False" />
<line number="15" hits="1" branch="False" />
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
@@ -24,7 +24,7 @@ import { getVoidLogger } from '@backstage/backend-common';
describe('convert cobertura', () => {
const converter = new Cobertura(getVoidLogger());
[1, 2, 3, 4, 5].forEach(idx => {
[1, 2, 3, 4, 5, 6].forEach(idx => {
let fixture: CoberturaXML;
parseString(
fs.readFileSync(
@@ -107,14 +107,10 @@ export class Cobertura implements Converter {
* @param clz - class coverage information
*/
private extractLines(clz: InnerClass): Array<LineHit> {
const classLines = clz.lines.flatMap(l => l.line);
const methodLines = clz.methods
?.flatMap(m => m.method)
.filter(Boolean)
.flatMap(m => m.lines)
.filter(Boolean)
.flatMap(l => l.line);
const lines = [classLines, methodLines].flat().filter(Boolean);
const lines = clz.lines
.flatMap(l => l.line)
.flat()
.filter(Boolean);
const lineHits = lines.map(l => {
return {
number: parseInt(l.$.number as unknown as string, 10),