Skip to content

Commit 070e3c6

Browse files
committed
Fix case-sensitive treatment of file names in coverage reports
File names are now treated as case-insensitive on windows.
1 parent 0eec50a commit 070e3c6

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Case-sensitive treatment of file names in coverage reports on Windows.
13+
1014
## [1.12.1] - 2024-12-06
1115

1216
### Fixed

delphi-frontend/src/main/java/au/com/integradev/delphi/msbuild/DelphiProjectHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package au.com.integradev.delphi.msbuild;
2424

25+
import static au.com.integradev.delphi.utils.DelphiUtils.inputFileToPath;
2526
import static au.com.integradev.delphi.utils.DelphiUtils.inputFilesToPaths;
2627
import static org.apache.commons.lang3.ArrayUtils.nullToEmpty;
2728

@@ -366,7 +367,11 @@ public InputFile getFile(String path) {
366367
}
367368

368369
public InputFile getFileFromBasename(String basename) {
369-
return fs.inputFile(fs.predicates().hasFilename(basename));
370+
return fs.inputFile(
371+
fs.predicates()
372+
.or(
373+
fs.predicates().hasFilename(basename),
374+
inputFile -> inputFileToPath(inputFile).getFileName().equals(Path.of(basename))));
370375
}
371376

372377
public String encoding() {

delphi-frontend/src/test/java/au/com/integradev/delphi/coverage/delphicodecoveragetool/DelphiCoverageToolParserTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import org.apache.commons.io.FileUtils;
4343
import org.junit.jupiter.api.BeforeEach;
4444
import org.junit.jupiter.api.Test;
45+
import org.junit.jupiter.api.condition.EnabledOnOs;
46+
import org.junit.jupiter.api.condition.OS;
4547
import org.sonar.api.batch.fs.InputFile;
4648
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
4749
import org.sonar.api.batch.sensor.SensorContext;
@@ -56,6 +58,8 @@ class DelphiCoverageToolParserTest {
5658
private static final String INVALID_STRUCTURE = BASE_REPORT_PATH + "InvalidStructure.xml";
5759
private static final String NORMAL_COVERAGE = BASE_REPORT_PATH + "NormalCoverage.xml";
5860
private static final String NORMAL_COVERAGE_PART_2 = BASE_REPORT_PATH + "NormalCoverage2.xml";
61+
private static final String MISMATCHED_CASING_COVERAGE =
62+
BASE_REPORT_PATH + "MismatchedCasingCoverage.xml";
5963

6064
private static final String GLOBALS_FILENAME = "Globals.pas";
6165
private static final String GLOBALS_FILE_KEY = ":" + GLOBALS_FILENAME;
@@ -124,6 +128,23 @@ void testLineHitsFromDifferentReportsAreMerged() {
124128
assertThat(context.lineHits(GLOBALS_FILE_KEY, 23)).isEqualTo((Integer) 1);
125129
}
126130

131+
@Test
132+
@EnabledOnOs(OS.WINDOWS)
133+
void testMismatchedCasingAllowedOnWindows() {
134+
parser.parse(context, DelphiUtils.getResource(MISMATCHED_CASING_COVERAGE));
135+
136+
assertThat(context.lineHits(GLOBALS_FILE_KEY, 16)).isEqualTo(1);
137+
assertThat(context.lineHits(GLOBALS_FILE_KEY, 17)).isEqualTo(1);
138+
assertThat(context.lineHits(GLOBALS_FILE_KEY, 23)).isZero();
139+
140+
assertThat(context.lineHits(MAIN_WINDOW_FILE_KEY, 31)).isEqualTo(1);
141+
assertThat(context.lineHits(MAIN_WINDOW_FILE_KEY, 36)).isEqualTo(1);
142+
assertThat(context.lineHits(MAIN_WINDOW_FILE_KEY, 37)).isEqualTo(1);
143+
assertThat(context.lineHits(MAIN_WINDOW_FILE_KEY, 38)).isEqualTo(1);
144+
assertThat(context.lineHits(MAIN_WINDOW_FILE_KEY, 39)).isEqualTo(1);
145+
assertThat(context.lineHits(MAIN_WINDOW_FILE_KEY, 40)).isEqualTo(1);
146+
}
147+
127148
void testReportFileIsIgnored(File file) {
128149
SensorContext mockContext = mock(SensorContext.class);
129150
assertThatCode(() -> parser.parse(mockContext, file)).doesNotThrowAnyException();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="Windows-1252" standalone="no"?>
2+
<report>
3+
<stats>
4+
<packages value="1"/>
5+
<classes value="2"/>
6+
<methods value="3"/>
7+
<srcfiles value="4"/>
8+
<srclines value="5"/>
9+
<totallines value="6"/>
10+
<coveredlines value="7"/>
11+
<coveredpercent value="8"/>
12+
</stats>
13+
<data>
14+
<all name="all classes">
15+
<coverage type="class, %" value="41% (41/101)"/>
16+
<coverage type="method, %" value="18% (112/636)"/>
17+
<coverage type="block, %" value="12% (815/6924)"/>
18+
<coverage type="line, %" value="12% (815/6924)"/>
19+
<package name="[default]">
20+
<coverage type="class, %" value="100% (5/5)"/>
21+
<coverage type="method, %" value="74% (14/19)"/>
22+
<coverage type="block, %" value="66% (93/140)"/>
23+
<coverage type="line, %" value="66% (93/140)"/>
24+
<srcfile name="MainWindow.pas">
25+
<coverage type="class, %" value="100% (5/5)"/>
26+
<coverage type="method, %" value="74% (14/19)"/>
27+
<coverage type="block, %" value="66% (93/140)"/>
28+
<coverage type="line, %" value="66% (93/140)"/>
29+
<class name="TMainWindow">
30+
<coverage type="class, %" value="100% (1/1)"/>
31+
<coverage type="method, %" value="100% (1/1)"/>
32+
<coverage type="block, %" value="56% (5/9)"/>
33+
<coverage type="line, %" value="56% (5/9)"/>
34+
<method name="foo2">
35+
<coverage type="method, %" value="100% (1/1)"/>
36+
<coverage type="block, %" value="56% (5/9)"/>
37+
<coverage type="line, %" value="56% (5/9)"/>
38+
<line number="36" covered="True"/>
39+
<line number="37" covered="False"/>
40+
<line number="38" covered="True"/>
41+
<line number="39" covered="False"/>
42+
</method>
43+
</class>
44+
</srcfile>
45+
<srcfile name="Globals.pas">
46+
<coverage type="class, %" value="100% (5/5)"/>
47+
<coverage type="method, %" value="74% (14/19)"/>
48+
<coverage type="block, %" value="66% (93/140)"/>
49+
<coverage type="line, %" value="66% (93/140)"/>
50+
<class name="TGlobals">
51+
<coverage type="class, %" value="100% (1/1)"/>
52+
<coverage type="method, %" value="100% (1/1)"/>
53+
<coverage type="block, %" value="56% (5/9)"/>
54+
<coverage type="line, %" value="56% (5/9)"/>
55+
<method name="globalProcedure">
56+
<coverage type="method, %" value="100% (2/2)"/>
57+
<coverage type="block, %" value="100% (1/1)"/>
58+
<coverage type="line, %" value="100% (2/2)"/>
59+
<line number="19" covered="True"/>
60+
<line number="20" covered="True"/>
61+
</method>
62+
</class>
63+
</srcfile>
64+
</package>
65+
</all>
66+
<linehits>
67+
<file name="GlObAlS.pas">16=1;17=1;23=0</file>
68+
<file name="maINwInDoW.pas">31=1;36=1;37=1;38=1;39=1;40=1</file>
69+
</linehits>
70+
</data>
71+
</report>

0 commit comments

Comments
 (0)