Skip to content

Commit

Permalink
Fix Lint checks, resolved todos
Browse files Browse the repository at this point in the history
  • Loading branch information
Rd4dev committed Jul 10, 2024
1 parent b814d15 commit 4d5c21f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,15 @@ class CoverageReporter(
}

private fun logCoverageReport() {
// TODO: (remove) as this looks un even in the output log
val logReportText = listOf(
"Covered File: $filePath",
"Coverage percentage: $formattedCoveragePercentage% covered",
"Line coverage: $totalLinesHit / $totalLinesFound lines covered"
)

val maxLength = logReportText.maxOf {it.length}
val horizontalBorder = "+-${"-".repeat(maxLength)}-+"
val reportText = logReportText.joinToString(separator = "\n") { line ->
"| ${line.padEnd(maxLength)} |"
}

println("$horizontalBorder\n$reportText\n$horizontalBorder")
val logReportText =
"""
Coverage Report:
---------------
Covered File: $filePath
Coverage percentage: $formattedCoveragePercentage% covered
Line coverage: $totalLinesHit / $totalLinesFound lines covered
"""
println("$logReportText")
}
}

Expand Down
24 changes: 11 additions & 13 deletions scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.oppia.android.scripts.coverage

import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -40,7 +39,7 @@ fun main(vararg args: String) {
val filePath = args[1]
println("File Path: $filePath")

//TODO: once the file list is received (git client), it need to be filtered to just have
// TODO: once the file list is received (git client), it need to be filtered to just have
// .kt files and also not Test.kt files
val filePaths = listOf(
"utility/src/main/java/org/oppia/android/util/parser/math/MathModel.kt",
Expand All @@ -52,10 +51,9 @@ fun main(vararg args: String) {

val format = args.find { it.startsWith("format=", ignoreCase = true) }
?.substringAfter("=")
?.uppercase() ?: "MARKDOWN"
?.uppercase() ?: "HTML"

val reportFormat = when (format) {
// TODO: (default to HTML) as that would be much simpler for local development
"HTML" -> ReportFormat.HTML
"MARKDOWN" -> ReportFormat.MARKDOWN
else -> throw IllegalArgumentException("Unsupported report format: $format")
Expand Down Expand Up @@ -113,7 +111,7 @@ class RunCoverage(
.associateBy { it.exemptedFilePath }
}

private val MIN_THRESHOLD = 10 // TODO: (to be decided) min threshold, yet to be decided on a value
private val MIN_THRESHOLD = 10 // yet to be decided on a value
private var coverageCheckState = CoverageCheck.PASS

/**
Expand All @@ -139,9 +137,10 @@ class RunCoverage(
private suspend fun runCoverageForFile(filePath: String): String {
val exemption = testFileExemptionList[filePath]
if (exemption != null && exemption.testFileNotRequired) {
return "The file: $filePath is exempted from having a test file; skipping coverage check.".also {
println(it)
}
return "The file: $filePath is exempted from having a test file; skipping coverage check."
.also {
println(it)
}
} else {
val testFilePaths = findTestFile(repoRoot, filePath)

Expand All @@ -159,7 +158,6 @@ class RunCoverage(

val coverageReports = deferredCoverageReports.awaitAll()

// TODO: (yet to decide) if this too needs to be set as coverage state -> FAIL.
// Check if the coverage reports are successfully generated else return failure message.
coverageReports.firstOrNull()?.let {
if (!it.isGenerated) {
Expand All @@ -176,7 +174,7 @@ class RunCoverage(
val coverageCheckThreshold = exemption?.overrideMinCoveragePercentRequired
?: MIN_THRESHOLD

if (computedCoverageRatio*100 < coverageCheckThreshold) {
if (computedCoverageRatio * 100 < coverageCheckThreshold) {
coverageCheckState = CoverageCheck.FAIL
reportText += "|:x:|"
} else {
Expand Down Expand Up @@ -208,7 +206,7 @@ class RunCoverage(
result.contains("|") && result.split("|")[4].trim() == ":white_check_mark:"
}

val anamolyCases = coverageResults.filterNot { it.contains("|") }
val anomalyCases = coverageResults.filterNot { it.contains("|") }

val coverageFailuresRows = coverageFailures.joinToString(separator = "\n")
val coverageSuccessesRows = coverageSuccesses.joinToString(separator = "\n")
Expand All @@ -226,11 +224,11 @@ class RunCoverage(
coverageSuccessesRows +
"\n</details>"

val anamolyCasesList = anamolyCases.joinToString(separator = "\n") { "- $it" }
val anomalyCasesList = anomalyCases.joinToString(separator = "\n") { "- $it" }
val finalReportText = failureMarkdownTable +
"\n\n" + successMarkdownTable +
"\n\n" + "### Anamoly Cases\n" +
anamolyCasesList
anomalyCasesList

println(finalReportText)
}
Expand Down

0 comments on commit 4d5c21f

Please sign in to comment.