Skip to content

Commit

Permalink
Merge pull request #505 from codacy/path-fixing-ignore-case
Browse files Browse the repository at this point in the history
use toLowerCase to compare all files and paths
  • Loading branch information
DMarinhoCodacy authored Jun 3, 2024
2 parents 9992245 + f377b8c commit 5cad31b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ object FileNameMatcher {

def matchAndReturnName(filename: String, fileNames: Seq[String]): Option[String] = {
fileNames
.filter(name => isTheSameFile(filename, name))
.filter(name => isTheSameFile(filename.toLowerCase, name.toLowerCase))
.sortBy(name => Math.abs(filename.length - name.length))
.headOption
}

def getFilenameFromPath(filename: String): String = {
Try(Paths.get(filename).getFileName.toString).getOrElse(filename)
Try(Paths.get(filename).getFileName.toString.toLowerCase).getOrElse(filename.toLowerCase)
}

private def haveSameName(file: String, covFile: String): Boolean =
getFilenameFromPath(file).equalsIgnoreCase(getFilenameFromPath(covFile))
getFilenameFromPath(file) == getFilenameFromPath(covFile)

private def haveSamePath(file: String, covFile: String): Boolean =
file.equalsIgnoreCase(covFile)
file == covFile

private def fileEndsWithReportPath(file: String, covFile: String): Boolean =
file.endsWith(covFile)
Expand Down
25 changes: 25 additions & 0 deletions src/test/resources/test-paths-with-different-paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<coverage line-rate="0.87">
<packages>
<package line-rate="0.87" name="com.github.theon.coveralls">
<classes>
<class line-rate="0.87" name="TestSourceFile" filename="coverage-parser\src\test\resources\TESTSOURCEFile.scala">
<methods/>
<lines>
<line number="3" hits="0"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="2"/>
</lines>
</class>
<class line-rate="0.87" name="TestSourceFile2" filename="coverage-parser\src\test\resources\TeStSOuRcEfIle2.scala">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
24 changes: 24 additions & 0 deletions src/test/scala/com/codacy/rules/ReportRulesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ class ReportRulesSpec extends WordSpec with Matchers with PrivateMethodTester wi
)
}

"succeed even if the provider paths and the report paths have different cases" in {
val coverageServices = mock[CoverageServices]
val gitFileFetcher = mock[GitFileFetcher]

gitFileFetcher.forCommit(any[String]).shouldReturn(Left("The report has files with different cases"))

coverageServices.sendReport(
any[String],
any[String],
any[CoverageReport],
anyBoolean,
Some(RequestTimeout(1000, 10000)),
Some(10000),
Some(3)
) returns SuccessfulResponse(RequestSuccess("Success"))

assertCodacyCoverage(
coverageServices,
gitFileFetcher,
List("src/test/resources/test-paths-with-different-paths.xml"),
success = true
)
}

"succeed even if one of the parsed reports ends up empty" in {
val coverageServices = mock[CoverageServices]
val gitFileFetcher = mock[GitFileFetcher]
Expand Down

0 comments on commit 5cad31b

Please sign in to comment.