Skip to content

Commit

Permalink
Include coverage data to proto for any related tests - LocalTest and …
Browse files Browse the repository at this point in the history
…return as a list of CoverageReport
  • Loading branch information
Rd4dev committed Jun 21, 2024
1 parent 653ec68 commit 46cc3ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ class CoverageRunner(
*/
fun runWithCoverageAsync(
bazelTestTarget: String
): Deferred<List<String>?> {
): Deferred<CoverageReport?> {
return CoroutineScope(scriptBgDispatcher).async {
val coverageDataFilePath = retrieveCoverageResult(bazelTestTarget)
val coverageResult = retrieveCoverageResult(bazelTestTarget)

val coverageReport = coverageDataFilePath?.let {
val coverageReport = coverageResult?.let {
parseCoverageData(it, bazelTestTarget)
}
println("Coverage Report: $coverageReport")

coverageDataFilePath
coverageReport
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.oppia.android.scripts.common.BazelClient
import org.oppia.android.scripts.common.CommandExecutor
import org.oppia.android.scripts.common.CommandExecutorImpl
import org.oppia.android.scripts.common.ScriptBackgroundCoroutineDispatcher
import org.oppia.android.scripts.proto.CoverageReport
import org.oppia.android.scripts.proto.TestFileExemptions
import java.io.File
import java.io.FileInputStream
Expand Down Expand Up @@ -71,8 +72,8 @@ class RunCoverage(
* a Bazel client, finds potential test file paths, retrieves Bazel targets, and initiates
* coverage analysis for each test target found.
*/
fun execute(): MutableList<List<String>> {
var coverageDataList = mutableListOf<List<String>>()
fun execute(): MutableList<CoverageReport> {
var coverageDataList = mutableListOf<CoverageReport>()
val testFileExemptionList = loadTestFileExemptionsProto(testFileExemptionTextProto)
.getExemptedFilePathList()

Expand All @@ -85,6 +86,11 @@ class RunCoverage(
val testFilePaths = findTestFile(repoRoot, filePath)
val testTargets = bazelClient.retrieveBazelTargets(testFilePaths)

/*val testResults = listOf(
"//utility/src/test/java/org/oppia/android/util/parser/math:MathModelTest",
"//utility/src/test/java/org/oppia/android/util/math:FloatExtensionsTest")*/

// for (testTarget in testResults) {
for (testTarget in testTargets) {
val coverageData = RunCoverageForTestTarget(
rootDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.runBlocking
import org.oppia.android.scripts.common.CommandExecutor
import org.oppia.android.scripts.common.CommandExecutorImpl
import org.oppia.android.scripts.common.ScriptBackgroundCoroutineDispatcher
import org.oppia.android.scripts.proto.CoverageReport
import java.io.File
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -65,7 +66,7 @@ class RunCoverageForTestTarget(
/**
* Analyzes target file for coverage, generates chosen reports accordingly.
*/
fun runCoverage(): List<String>? {
fun runCoverage(): CoverageReport? {
return runWithCoverageAnalysis()
}

Expand All @@ -74,7 +75,7 @@ class RunCoverageForTestTarget(
*
* @return the generated coverage data
*/
fun runWithCoverageAnalysis(): List<String>? {
fun runWithCoverageAnalysis(): CoverageReport? {
return runBlocking {
val result =
CoverageRunner(repoRoot, scriptBgDispatcher, commandExecutor)
Expand Down

0 comments on commit 46cc3ff

Please sign in to comment.