Skip to content

Commit

Permalink
Files that have misplaced test files
Browse files Browse the repository at this point in the history
These could be refactored / moved to get back their coverage data, though most app module files wouldn't be still retrivable but around 10 of the other module stuff should be
  • Loading branch information
Rd4dev committed Aug 31, 2024
1 parent dd584ce commit 75e6219
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ class TestFileCheck(
// A list of all the prod files that do not have a corresponding test file.
val matchedFiles = prodFilesList.filter { prodFile ->
!testFilesList.any { testFile ->
testFile.name == computeExpectedTestFileName(prodFile)
testFile.toRelativeString(File(repoPath)) == computeExpectedTestFileName(prodFile, repoPath) ||
testFile.toRelativeString(File(repoPath)) == computeExpectedTestFileNameAppShared(prodFile, repoPath) ||
testFile.toRelativeString(File(repoPath)) == computeExpectedTestFileNameAppLocal(prodFile, repoPath)
}
}

println("No. of files with no test files: ${matchedFiles.size}")

logFailures(matchedFiles)

if (matchedFiles.isNotEmpty()) {
Expand All @@ -80,8 +84,35 @@ class TestFileCheck(
}
}

private fun computeExpectedTestFileName(prodFile: File): String {
return "${prodFile.nameWithoutExtension}Test.kt"
private fun computeExpectedTestFileName(prodFile: File, repoPath: String): String {
val filePath = prodFile.toRelativeString(File(repoPath))
val expectedfilepath = when {
filePath.startsWith("scripts/") -> {
filePath.replace("java", "javatests").removeSuffix(".kt")
}
else -> {
filePath.replace("/main/", "/test/").removeSuffix(".kt")
}
}
return "${expectedfilepath}Test.kt"
}

private fun computeExpectedTestFileNameAppShared(prodFile: File, repoPath: String): String {
val filePath = prodFile.toRelativeString(File(repoPath))
if(filePath.startsWith("app/")) {
val expectedfilepath = filePath.replace("/main/", "/sharedTest/").removeSuffix(".kt")
return "${expectedfilepath}Test.kt"
}
return ""
}

private fun computeExpectedTestFileNameAppLocal(prodFile: File, repoPath: String): String {
val filePath = prodFile.toRelativeString(File(repoPath))
if(filePath.startsWith("app/")) {
val expectedfilepath = filePath.replace("/main/", "/test/").removeSuffix(".kt")
return "${expectedfilepath}LocalTest.kt"
}
return ""
}

private fun logFailures(matchedFiles: List<File>) {
Expand Down

0 comments on commit 75e6219

Please sign in to comment.