Skip to content

Commit

Permalink
Fix kdoc lint checks and TestBazelWorkspace Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rd4dev committed Jun 20, 2024
1 parent 8e28f1d commit 92bf266
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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.TestFileExemptions
import java.util.concurrent.TimeUnit
import java.io.File
import java.io.FileInputStream
import java.util.concurrent.TimeUnit

/**
* Entry point function for running coverage analysis for a source file.
Expand Down Expand Up @@ -40,7 +40,7 @@ fun main(vararg args: String) {
scriptBgDispatcher, processTimeout = processTimeout, processTimeoutUnit = TimeUnit.MINUTES
)

RunCoverage(repoRoot, filePath, commandExecutor, scriptBgDispatcher).execute()
RunCoverage(repoRoot, filePath, commandExecutor, scriptBgDispatcher).execute()
}
}

Expand All @@ -63,7 +63,6 @@ class RunCoverage(
private val rootDirectory = File(repoRoot).absoluteFile
private val testFileExemptionTextProto = "scripts/assets/test_file_exemptions"
var coverageDataList = mutableListOf<String>()
// var covdat: String = ""

/**
* Executes coverage analysis for the specified file.
Expand Down Expand Up @@ -98,6 +97,13 @@ class RunCoverage(
return coverageDataList
}

/**
* Finds potential test file paths corresponding to a given source file path within a repository.
*
* @param repoRoot the root directory of the repository
* @param filePath The file path of the source file for which the test files are to be found.
* @return A list of potential test file paths that exist in the repository.
*/
fun findTestFile(repoRoot: String, filePath: String): List<String> {
val file = File(filePath)
val parts = file.parent.split(File.separator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import org.junit.rules.TemporaryFolder
import org.oppia.android.scripts.common.CommandExecutorImpl
import org.oppia.android.scripts.common.ScriptBackgroundCoroutineDispatcher
import org.oppia.android.scripts.testing.TestBazelWorkspace
import org.oppia.android.testing.assertThrows
import java.util.concurrent.TimeUnit
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.PrintStream
import java.util.concurrent.TimeUnit

/** Tests for [RunCoverage]. */
class RunCoverageTest {
Expand Down Expand Up @@ -51,9 +50,11 @@ class RunCoverageTest {
"${tempFolder.root}",
exemptedFilePath,
commandExecutor,
scriptBgDispatcher).execute()
scriptBgDispatcher
).execute()

assertThat(outContent.toString()).isEqualTo("This file is exempted from having a test file. Hence No coverage!\n")
assertThat(outContent.toString())
.isEqualTo("This file is exempted from having a test file. Hence No coverage!\n")
}

@Test
Expand Down Expand Up @@ -220,30 +221,31 @@ class RunCoverageTest {
"${tempFolder.root}",
"coverage/main/java/com/example/TwoSum.kt",
longCommandExecutor,
scriptBgDispatcher).execute()

val expectedResultList = listOf(
"SF:coverage/main/java/com/example/TwoSum.kt\n"+
"FN:7,com/example/TwoSum${'$'}Companion::sumNumbers (II)Ljava/lang/Object;\n"+
"FN:3,com/example/TwoSum::<init> ()V\n"+
"FNDA:1,com/example/TwoSum${'$'}Companion::sumNumbers (II)Ljava/lang/Object;\n"+
"FNDA:0,com/example/TwoSum::<init> ()V\n"+
"FNF:2\n"+
"FNH:1\n"+
"BRDA:7,0,0,1\n"+
"BRDA:7,0,1,1\n"+
"BRDA:7,0,2,1\n"+
"BRDA:7,0,3,1\n"+
"BRF:4\n"+
"BRH:4\n"+
"DA:3,0\n"+
"DA:7,1\n"+
"DA:8,1\n"+
"DA:10,1\n"+
"LH:3\n"+
"LF:4\n"+
"end_of_record\n"
)
scriptBgDispatcher
).execute()

val expectedResultList = listOf(
"SF:coverage/main/java/com/example/TwoSum.kt\n" +
"FN:7,com/example/TwoSum${'$'}Companion::sumNumbers (II)Ljava/lang/Object;\n" +
"FN:3,com/example/TwoSum::<init> ()V\n" +
"FNDA:1,com/example/TwoSum${'$'}Companion::sumNumbers (II)Ljava/lang/Object;\n" +
"FNDA:0,com/example/TwoSum::<init> ()V\n" +
"FNF:2\n" +
"FNH:1\n" +
"BRDA:7,0,0,1\n" +
"BRDA:7,0,1,1\n" +
"BRDA:7,0,2,1\n" +
"BRDA:7,0,3,1\n" +
"BRF:4\n" +
"BRH:4\n" +
"DA:3,0\n" +
"DA:7,1\n" +
"DA:8,1\n" +
"DA:10,1\n" +
"LH:3\n" +
"LF:4\n" +
"end_of_record\n"
)

assertThat(result).isEqualTo(expectedResultList)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class TestBazelWorkspaceTest {
"""
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test")
kt_jvm_test(
name = "test",
name = "MainTest",
srcs = ["MainTest.kt"],
deps = [
"//coverage/main/java/com/example:main",
Expand Down Expand Up @@ -406,7 +406,7 @@ class TestBazelWorkspaceTest {
"""
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test")
kt_jvm_test(
name = "test",
name = "MainTest",
srcs = ["MainTest.kt"],
deps = [
"//coverage/main/java/com/example:main",
Expand Down

0 comments on commit 92bf266

Please sign in to comment.