From c4531c830d5164eed6c329ffdaba836cf444127a Mon Sep 17 00:00:00 2001 From: David Marinho Date: Fri, 31 May 2024 16:34:34 +0100 Subject: [PATCH 1/5] use toLowerCase to compare all files and paths --- .../scala/com/codacy/transformation/FileNameMatcher.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/scala/com/codacy/transformation/FileNameMatcher.scala b/src/main/scala/com/codacy/transformation/FileNameMatcher.scala index 7a2c27b3..2687a25a 100644 --- a/src/main/scala/com/codacy/transformation/FileNameMatcher.scala +++ b/src/main/scala/com/codacy/transformation/FileNameMatcher.scala @@ -20,13 +20,13 @@ object FileNameMatcher { getFilenameFromPath(file).equalsIgnoreCase(getFilenameFromPath(covFile)) private def haveSamePath(file: String, covFile: String): Boolean = - file.equalsIgnoreCase(covFile) + file.toLowerCase.equalsIgnoreCase(covFile.toLowerCase) private def fileEndsWithReportPath(file: String, covFile: String): Boolean = - file.endsWith(covFile) + file.toLowerCase.endsWith(covFile.toLowerCase) private def reportEndsWithFilePath(file: String, covFile: String): Boolean = - covFile.endsWith(file) + covFile.toLowerCase.endsWith(file.toLowerCase) private def isTheSameFile(file: String, covFile: String): Boolean = { From 460d9e391a77f91e6e1a4a7aa904ec5d1d72bf39 Mon Sep 17 00:00:00 2001 From: David Marinho Date: Mon, 3 Jun 2024 09:52:00 +0100 Subject: [PATCH 2/5] refactor filenamematcher file --- .../com/codacy/transformation/FileNameMatcher.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/scala/com/codacy/transformation/FileNameMatcher.scala b/src/main/scala/com/codacy/transformation/FileNameMatcher.scala index 2687a25a..a3fca09d 100644 --- a/src/main/scala/com/codacy/transformation/FileNameMatcher.scala +++ b/src/main/scala/com/codacy/transformation/FileNameMatcher.scala @@ -7,7 +7,7 @@ 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 } @@ -17,16 +17,16 @@ object FileNameMatcher { } 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.toLowerCase.equalsIgnoreCase(covFile.toLowerCase) + file == covFile private def fileEndsWithReportPath(file: String, covFile: String): Boolean = - file.toLowerCase.endsWith(covFile.toLowerCase) + file.endsWith(covFile) private def reportEndsWithFilePath(file: String, covFile: String): Boolean = - covFile.toLowerCase.endsWith(file.toLowerCase) + covFile.endsWith(file) private def isTheSameFile(file: String, covFile: String): Boolean = { From ac67caee5ec220a7782cbe636d4a698d44b7f2b8 Mon Sep 17 00:00:00 2001 From: David Marinho Date: Mon, 3 Jun 2024 10:01:54 +0100 Subject: [PATCH 3/5] fix getFileNameFromPath --- src/main/scala/com/codacy/transformation/FileNameMatcher.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/codacy/transformation/FileNameMatcher.scala b/src/main/scala/com/codacy/transformation/FileNameMatcher.scala index a3fca09d..970b694a 100644 --- a/src/main/scala/com/codacy/transformation/FileNameMatcher.scala +++ b/src/main/scala/com/codacy/transformation/FileNameMatcher.scala @@ -13,7 +13,7 @@ object FileNameMatcher { } 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 = From 53e8ad491197b544835e3c44b4fd898c2f1656a9 Mon Sep 17 00:00:00 2001 From: David Marinho Date: Mon, 3 Jun 2024 12:09:03 +0100 Subject: [PATCH 4/5] add test to check files within reports different cases --- .../test-paths-with-different-paths.xml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 coverage-parser/src/test/resources/test-paths-with-different-paths.xml diff --git a/coverage-parser/src/test/resources/test-paths-with-different-paths.xml b/coverage-parser/src/test/resources/test-paths-with-different-paths.xml new file mode 100644 index 00000000..95d8b620 --- /dev/null +++ b/coverage-parser/src/test/resources/test-paths-with-different-paths.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From f377b8ca9ff8969b218ec91cd6d6d06f9c824b01 Mon Sep 17 00:00:00 2001 From: David Marinho Date: Mon, 3 Jun 2024 15:11:39 +0100 Subject: [PATCH 5/5] add test that checks different paths between provider and report --- .../test-paths-with-different-paths.xml | 7 ------ .../com/codacy/rules/ReportRulesSpec.scala | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) rename {coverage-parser/src => src}/test/resources/test-paths-with-different-paths.xml (75%) diff --git a/coverage-parser/src/test/resources/test-paths-with-different-paths.xml b/src/test/resources/test-paths-with-different-paths.xml similarity index 75% rename from coverage-parser/src/test/resources/test-paths-with-different-paths.xml rename to src/test/resources/test-paths-with-different-paths.xml index 95d8b620..dc072ff7 100644 --- a/coverage-parser/src/test/resources/test-paths-with-different-paths.xml +++ b/src/test/resources/test-paths-with-different-paths.xml @@ -11,13 +11,6 @@ - - - - - - - diff --git a/src/test/scala/com/codacy/rules/ReportRulesSpec.scala b/src/test/scala/com/codacy/rules/ReportRulesSpec.scala index 336824a2..6a25319a 100644 --- a/src/test/scala/com/codacy/rules/ReportRulesSpec.scala +++ b/src/test/scala/com/codacy/rules/ReportRulesSpec.scala @@ -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]