Skip to content

Commit

Permalink
Trying to find the coverage path with regex pattern as they mismatch
Browse files Browse the repository at this point in the history
Pushing it to see it through CI as local wsl seems broke and runs forever
  • Loading branch information
Rd4dev committed Jul 29, 2024
1 parent 8e88c35 commit c1f012c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.oppia.android.scripts.coverage

import kotlinx.coroutines.CoroutineScope
import org.oppia.android.scripts.common.BazelClient
import org.oppia.android.scripts.common.CommandExecutor
import org.oppia.android.scripts.common.ScriptBackgroundCoroutineDispatcher
Expand Down Expand Up @@ -35,10 +34,10 @@ class CoverageRunner(
fun runCoverageForTestTarget(
bazelTestTarget: String
): CoverageReport {
val coverageResult = retrieveCoverageResult(bazelTestTarget)
?: error("Failed to retrieve coverage result for $bazelTestTarget")
val coverageResult = retrieveCoverageResult(bazelTestTarget)
?: error("Failed to retrieve coverage result for $bazelTestTarget")

return coverageDataFileLines(coverageResult, bazelTestTarget)
return coverageDataFileLines(coverageResult, bazelTestTarget)
}

private fun retrieveCoverageResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kt_jvm_test(
name = "RunCoverageTest",
size = "large",
srcs = ["RunCoverageTest.kt"],
shard_count = 4,
shard_count = 24,
deps = [
"//scripts:test_file_check_assets",
"//scripts/src/java/org/oppia/android/scripts/coverage:run_coverage_lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ class CoverageRunnerTest {

@Test
fun testRunCoverageForTestTarget_coverageRetrievalFailed_throwsException() {
val coverageFilePath = "${tempFolder.root}/bazel-out/k8-fastbuild/testlogs" +
"/coverage/test/java/com/example/AddNumsTest/coverage.dat"
// val coverageFilePath = "${tempFolder.root.absolutePath}/bazel-out/k8-fastbuild/testlogs" +
// "/coverage/test/java/com/example/AddNumsTest/coverage.dat"
val pattern = Regex(".*bazel-out/k8-fastbuild/testlogs/coverage/test/java/com/example/AddNumsTest/coverage.dat")

testBazelWorkspace.initEmptyWorkspace()
testBazelWorkspace.addSourceAndTestFileWithContent(
Expand All @@ -125,10 +126,23 @@ class CoverageRunnerTest {

launch {
do {
File(coverageFilePath).takeIf { it.exists() }?.apply {
val files = File(tempFolder.root.absolutePath).listFiles() ?: emptyArray()
val matchingFiles = files.filter { file ->
pattern.matches(file.absolutePath)
}

if (matchingFiles.isNotEmpty()) {
for (file in matchingFiles) {
file.writeText("")
println("Processed: ${file.absolutePath}")
return@launch
}
}

/*File(coverageFilePath).takeIf { it.exists() }?.apply {
writeText("")
return@launch
}
}*/
delay(1)
} while (true)
}
Expand Down

0 comments on commit c1f012c

Please sign in to comment.