From 92bf2669e776b8573fc515a8d6c3c1b84034a4c6 Mon Sep 17 00:00:00 2001 From: Rd Date: Thu, 20 Jun 2024 21:07:02 +0530 Subject: [PATCH] Fix kdoc lint checks and TestBazelWorkspace Tests --- .../android/scripts/coverage/RunCoverage.kt | 12 +++- .../scripts/coverage/RunCoverageTest.kt | 58 ++++++++++--------- .../scripts/testing/TestBazelWorkspaceTest.kt | 4 +- 3 files changed, 41 insertions(+), 33 deletions(-) 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 fb46019d694..924f29c0b33 100644 --- a/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt +++ b/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt @@ -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. @@ -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() } } @@ -63,7 +63,6 @@ class RunCoverage( private val rootDirectory = File(repoRoot).absoluteFile private val testFileExemptionTextProto = "scripts/assets/test_file_exemptions" var coverageDataList = mutableListOf() -// var covdat: String = "" /** * Executes coverage analysis for the specified file. @@ -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 { val file = File(filePath) val parts = file.parent.split(File.separator) diff --git a/scripts/src/javatests/org/oppia/android/scripts/coverage/RunCoverageTest.kt b/scripts/src/javatests/org/oppia/android/scripts/coverage/RunCoverageTest.kt index 506a9bcb1c1..1a2fd495f77 100644 --- a/scripts/src/javatests/org/oppia/android/scripts/coverage/RunCoverageTest.kt +++ b/scripts/src/javatests/org/oppia/android/scripts/coverage/RunCoverageTest.kt @@ -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 { @@ -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 @@ -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:: ()V\n"+ - "FNDA:1,com/example/TwoSum${'$'}Companion::sumNumbers (II)Ljava/lang/Object;\n"+ - "FNDA:0,com/example/TwoSum:: ()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:: ()V\n" + + "FNDA:1,com/example/TwoSum${'$'}Companion::sumNumbers (II)Ljava/lang/Object;\n" + + "FNDA:0,com/example/TwoSum:: ()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) } diff --git a/scripts/src/javatests/org/oppia/android/scripts/testing/TestBazelWorkspaceTest.kt b/scripts/src/javatests/org/oppia/android/scripts/testing/TestBazelWorkspaceTest.kt index 9d6a33378d6..d62bbf11501 100644 --- a/scripts/src/javatests/org/oppia/android/scripts/testing/TestBazelWorkspaceTest.kt +++ b/scripts/src/javatests/org/oppia/android/scripts/testing/TestBazelWorkspaceTest.kt @@ -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", @@ -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",