From 46cc3ff9276ea63130474aa0bd54392c1e7204de Mon Sep 17 00:00:00 2001 From: Rd Date: Sat, 22 Jun 2024 05:04:05 +0530 Subject: [PATCH] Include coverage data to proto for any related tests - LocalTest and return as a list of CoverageReport --- .../oppia/android/scripts/coverage/CoverageRunner.kt | 10 ++++------ .../org/oppia/android/scripts/coverage/RunCoverage.kt | 10 ++++++++-- .../scripts/coverage/RunCoverageForTestTarget.kt | 5 +++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/src/java/org/oppia/android/scripts/coverage/CoverageRunner.kt b/scripts/src/java/org/oppia/android/scripts/coverage/CoverageRunner.kt index 11ecc08d195..5dacf330a9a 100644 --- a/scripts/src/java/org/oppia/android/scripts/coverage/CoverageRunner.kt +++ b/scripts/src/java/org/oppia/android/scripts/coverage/CoverageRunner.kt @@ -38,16 +38,14 @@ class CoverageRunner( */ fun runWithCoverageAsync( bazelTestTarget: String - ): Deferred?> { + ): Deferred { 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 } } diff --git a/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt b/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt index d0b2ce66bdc..8e267ea72c8 100644 --- a/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt +++ b/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt @@ -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 @@ -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> { - var coverageDataList = mutableListOf>() + fun execute(): MutableList { + var coverageDataList = mutableListOf() val testFileExemptionList = loadTestFileExemptionsProto(testFileExemptionTextProto) .getExemptedFilePathList() @@ -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, diff --git a/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverageForTestTarget.kt b/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverageForTestTarget.kt index f3362232aad..1c508b5e932 100644 --- a/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverageForTestTarget.kt +++ b/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverageForTestTarget.kt @@ -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 @@ -65,7 +66,7 @@ class RunCoverageForTestTarget( /** * Analyzes target file for coverage, generates chosen reports accordingly. */ - fun runCoverage(): List? { + fun runCoverage(): CoverageReport? { return runWithCoverageAnalysis() } @@ -74,7 +75,7 @@ class RunCoverageForTestTarget( * * @return the generated coverage data */ - fun runWithCoverageAnalysis(): List? { + fun runWithCoverageAnalysis(): CoverageReport? { return runBlocking { val result = CoverageRunner(repoRoot, scriptBgDispatcher, commandExecutor)