Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix part of #5343: Building proto with coverage results for data processing #5439

Merged
merged 107 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
6ec35a7
Fix lint new line and kdoc checks
Rd4dev Jun 4, 2024
1ec224a
Execute Bazel Command to run coverage on the test target
Rd4dev Jun 5, 2024
ee92168
Parse the coverage execution result to acquire the generated coverage…
Rd4dev Jun 5, 2024
075c77c
Implemented functionality to TestBazelWorkspace utility to add source…
Rd4dev Jun 7, 2024
d0519d6
Sample Test data and Listing all contents
Rd4dev Jun 9, 2024
b15b7bb
Added Test for BazelClient - for sample target and non target executions
Rd4dev Jun 9, 2024
f441d11
Added Coverage Runner functionality tests
Rd4dev Jun 10, 2024
cc86309
Added tests for the RunCoverageForTestTarget utility
Rd4dev Jun 11, 2024
4a6073b
Replaced Java Test Sources with Kotlin Sources
Rd4dev Jun 13, 2024
13534a1
Fix Static Checks / Lint warnings
Rd4dev Jun 13, 2024
fc52d82
Fix Buildifier Lint checks
Rd4dev Jun 13, 2024
0226baa
Added tests for TestBazelWorkspaceTest to check addition of source an…
Rd4dev Jun 13, 2024
2fe7485
Fix Lint warnings with TestBazelWorkspaceTest
Rd4dev Jun 13, 2024
bd683b5
Fix Regex Pattern checks
Rd4dev Jun 13, 2024
d410d17
Prototyped parsing and reading the extracted file data as byte array
Rd4dev Jun 15, 2024
ece147a
Updated the runCoverageForTestTarget to parse the data file and read …
Rd4dev Jun 15, 2024
b101ec8
Updated Bazel Client Tests with updated execution to return byte array
Rd4dev Jun 15, 2024
5db0650
Updated BazelClientTest for ParseCoverageDataFile and readDatFileAsBi…
Rd4dev Jun 17, 2024
87be114
Updated CoverageRunnerTest to check with updated getCoverage result r…
Rd4dev Jun 17, 2024
456e81b
Updated RunCoverageForTestTargetTest to check the returned coverage data
Rd4dev Jun 17, 2024
2c65524
Update kdoc to match the function paramaters
Rd4dev Jun 17, 2024
62f9e1d
Removing suspend while keeping the async operations
Rd4dev Jun 17, 2024
5e6d2ef
Updated RunCoverageForTestTarget to take in custom process timeout as…
Rd4dev Jun 17, 2024
31b6401
Initialized bazelClient using lazy field
Rd4dev Jun 17, 2024
81d6855
Adjusted visibility and removed unnecessary documentation for private…
Rd4dev Jun 17, 2024
6cb1da7
Revoking visibility of bazelClient functions as that is called outsid…
Rd4dev Jun 17, 2024
b41fb01
Fix Lint Check issues
Rd4dev Jun 17, 2024
e66ac12
Merge branch 'develop' of https://github.com/Rd4dev/oppia-android int…
Rd4dev Jun 17, 2024
c646840
Merge branch 'develop' of https://github.com/Rd4dev/oppia-android int…
Rd4dev Jun 18, 2024
1ffc83d
Introduce new script RunCoverage.kt to later take in source filename …
Rd4dev Jun 18, 2024
248a20a
Merge branch 'develop' of https://github.com/Rd4dev/oppia-android int…
Rd4dev Jun 19, 2024
d817c85
Map file names to appropriate test and localTest names
Rd4dev Jun 19, 2024
7f1be37
Running Multiple test targets using hardcoded test target names
Rd4dev Jun 19, 2024
9e78d1a
Added Kdoc and processTimeout custom argument with basic clean up
Rd4dev Jun 19, 2024
cc5e981
Seperated logic as class and functions, introduced test file with set…
Rd4dev Jun 20, 2024
5075a1a
Added tests for findTestFile()
Rd4dev Jun 20, 2024
fdaf9cb
Added tests case for RunCoverage to check execution of coverage and f…
Rd4dev Jun 20, 2024
8e28f1d
Cleanup of RunCoverageTest
Rd4dev Jun 20, 2024
92bf266
Fix kdoc lint checks and TestBazelWorkspace Tests
Rd4dev Jun 20, 2024
eb7cdc2
Fix Lint Checks on indentation
Rd4dev Jun 20, 2024
ee078e2
Refactored BazelClient coverage execution to return data as list of s…
Rd4dev Jun 21, 2024
f15e087
Fix Lint checks
Rd4dev Jun 21, 2024
506916d
Removed ending periods in KDoc Strings
Rd4dev Jun 21, 2024
c68487d
Merge branch 'develop' of https://github.com/Rd4dev/oppia-android int…
Rd4dev Jun 21, 2024
0f5cffd
Resolved with conflicts to the code_coverage_bazel_command_execution …
Rd4dev Jun 21, 2024
87d34ad
Update the script to align with changes in BazelClient PR 1.1 to retu…
Rd4dev Jun 21, 2024
0735c64
Introduced coverage.proto and parsed the coverage data and store them…
Rd4dev Jun 21, 2024
307214a
Added sha hash and hit count for branches
Rd4dev Jun 21, 2024
bb2cbb2
Isolate the coverage data to only contain the target coverage data
Rd4dev Jun 21, 2024
653ec68
Fix Lint Checks
Rd4dev Jun 21, 2024
46cc3ff
Include coverage data to proto for any related tests - LocalTest and …
Rd4dev Jun 21, 2024
25a064e
Updated the tests to now check with the CoverageReport proto result
Rd4dev Jun 22, 2024
ba1c66a
Fix KDoc String punctuations, more clearer variable names and simplif…
Rd4dev Jun 22, 2024
438476c
Removed unused Paths import
Rd4dev Jun 22, 2024
ac30ca7
Merge branch 'develop' of https://github.com/Rd4dev/oppia-android int…
Rd4dev Jun 22, 2024
c7c2f2f
Fixed indentation and line spaces for better readability
Rd4dev Jun 22, 2024
1eac413
Merge branch 'code_coverage_bazel_command_execution' of https://githu…
Rd4dev Jun 22, 2024
6a2a029
For Reference: Multiple test cases with LocalTest and Test works but …
Rd4dev Jun 22, 2024
e4ede82
For Reference: Added package group for sharedTest and Test, yet multi…
Rd4dev Jun 22, 2024
9e0189d
Added implementation for script module test content files (to be refa…
Rd4dev Jun 22, 2024
d477d20
Refactored the addSourceAndTestFileWithContent to be suitable for mul…
Rd4dev Jun 22, 2024
6720de7
For Reference: Added App cases, but just having sharedTest in package…
Rd4dev Jun 22, 2024
04243f1
KDoC and reverting sharedTest to test, this passes test
Rd4dev Jun 22, 2024
985e861
For Reference: Even doing app/test fails with NPE
Rd4dev Jun 22, 2024
33f9a0b
Made findTestFile private and removed related tests
Rd4dev Jun 22, 2024
5229ecd
Used kotlin patterns to simplify the and make it more readable
Rd4dev Jun 22, 2024
d9ad634
Returning the coverageDataList as immutable list
Rd4dev Jun 22, 2024
ac4c82b
Fix Lint Checks
Rd4dev Jun 23, 2024
6eb90c7
Fixed Multi Level Source and Test File coverage execution by adding t…
Rd4dev Jun 23, 2024
68c714b
Fix Lint Check
Rd4dev Jun 23, 2024
e0be83a
Removed RunCoverageForTestTarget as it is redundant
Rd4dev Jun 23, 2024
c834aa7
Removed the RunCoverageForTestTarget as the functionality will be re-…
Rd4dev Jun 23, 2024
47a6197
Resolved merge conflicts with upstream code_coverage_bazel_command_ex…
Rd4dev Jun 23, 2024
c654eed
Removed the RunCoverageForTestTarget Build inclusions
Rd4dev Jun 23, 2024
3ab4e1e
Resolved merge conflict while syncing with upstream
Rd4dev Jun 23, 2024
0306258
Refactor execute to use separate helper functions
Rd4dev Jun 23, 2024
6179699
Used mapNotNull to avoid mutability
Rd4dev Jun 23, 2024
0c79e4d
Updated with upstream and removed all the optional declarations to ju…
Rd4dev Jun 24, 2024
73f553d
Merge branch 'develop' into code_coverage_bazel_command_execution
BenHenning Jun 24, 2024
0f63469
Merge branch 'develop' into code_coverage_bazel_command_execution
BenHenning Jun 24, 2024
83eb035
Updated with the revised proto structure and added docs
Rd4dev Jun 24, 2024
bc9a5c0
Throw runtime exception when no coverage result is retrieved
Rd4dev Jun 24, 2024
1b9426d
Fix instrumentation and throw error on invalid path
Rd4dev Jun 26, 2024
85b4bcd
Throw error on missing test files
Rd4dev Jun 26, 2024
356e4fb
Removed accidentally added coverage_reports folder
Rd4dev Jun 26, 2024
b4abdde
Restructuring coverage proto to just compute line coverage
Rd4dev Jun 26, 2024
8e07f50
Updated with upstream
Rd4dev Jun 26, 2024
9734a84
Lint fix and Fix failing Test
Rd4dev Jun 26, 2024
f36eb83
Merge branch 'develop' of https://github.com/Rd4dev/oppia-android int…
Rd4dev Jun 26, 2024
6488d53
Merge branch 'code_coverage_bazel_command_execution' of https://githu…
Rd4dev Jun 26, 2024
6f4b76f
Merge branch 'code_coverage_bazel_command_execution' of https://githu…
Rd4dev Jun 26, 2024
7a020a1
Update the test file exemption list retrieval
Rd4dev Jun 26, 2024
4d8b250
Updated from upstream code_coverage_using_filename
Rd4dev Jun 26, 2024
c123365
Updated tests with the proto structure, multi test cases are still fa…
Rd4dev Jun 26, 2024
d6c1f33
Changed mutable lists to lists
Rd4dev Jun 26, 2024
3b6b049
Removed print statement and refactored same package deps
Rd4dev Jun 26, 2024
d88edf6
Fixed improper dep assignment
Rd4dev Jun 26, 2024
4e89da1
Updated with upstream code_coverage_using_filename
Rd4dev Jun 26, 2024
7a837ea
Refactor runCoverageForTarget to return non-nullable CoverageReport
Rd4dev Jun 26, 2024
cba0815
Fix tests in CoverageRunner and Lint checks
Rd4dev Jun 26, 2024
f6b4620
Fix Lint checks
Rd4dev Jun 26, 2024
cf405c6
Added tests for local and sharedTests separately
Rd4dev Jun 26, 2024
88f286b
Fix Lint check, missed separator
Rd4dev Jun 26, 2024
32d9ae4
Fix Coverage Runner Test
Rd4dev Jun 26, 2024
266d0f4
Resolved conflicts with develop branch
Rd4dev Jun 26, 2024
a0bc41c
Resolved conflicting overloads
Rd4dev Jun 26, 2024
a781919
Merge branch 'develop' into code_coverage_store_as_proto
adhiamboperes Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix instrumentation and throw error on invalid path
  • Loading branch information
Rd4dev committed Jun 26, 2024
commit 1b9426d196a1d790fc31e70721be88c52506a0b1
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coverage Report</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
padding: 20px;
}
.covered-line, .not-covered-line, .uncovered-line {
display: inline-block;
width: auto;
padding: 2px 4px;
margin: 0;
}
.covered-line {
background-color: #c8e6c9; /* Light green */
}
.not-covered-line {
background-color: #ffcdd2; /* Light red */
}
.uncovered-line {
background-color: #ffffff; /* White */
}
.coverage-summary {
margin-bottom: 20px;
}
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<h1>Coverage Report</h1>
<div class="coverage-summary">
<h2>Total coverage:</h2>
<ul>
<li><strong>Files covered:</strong> 1</li>
<li><strong>Covered File:</strong> utility/src/main/java/org/oppia/android/util/parser/math/MathModel.kt</li>
<li><strong>Coverage percentage:</strong> 87.50% covered</li>
<li><strong>Line coverage:</strong> 0 covered / 0 found</li>
<li><strong>Function coverage:</strong> 0 covered / 0 found</li>
<li><strong>Branch coverage:</strong> 0 covered / 0 found</li>
</ul>
</div>
<pre><div class="uncovered-line"> 1: package org.oppia.android.util.parser.math</div>
<div class="uncovered-line"> 2: </div>
<div class="uncovered-line"> 3: import com.bumptech.glide.load.Key</div>
<div class="uncovered-line"> 4: import java.nio.ByteBuffer</div>
<div class="uncovered-line"> 5: import java.security.MessageDigest</div>
<div class="uncovered-line"> 6: </div>
<div class="uncovered-line"> 7: /**</div>
<div class="uncovered-line"> 8: * Represents a set of LaTeX that can be rendered as a single bitmap.</div>
<div class="uncovered-line"> 9: *</div>
<div class="uncovered-line"> 10: * @property rawLatex the LaTeX to render</div>
<div class="uncovered-line"> 11: * @property lineHeight the height (in pixels) of a text line (to help scale the LaTeX)</div>
<div class="uncovered-line"> 12: * @property useInlineRendering whether the LaTeX will be inlined with text</div>
<div class="uncovered-line"> 13: */</div>
<div class="covered-line"> 14: data class MathModel(</div>
<div class="covered-line"> 15: val rawLatex: String,</div>
<div class="covered-line"> 16: val lineHeight: Float,</div>
<div class="covered-line"> 17: val useInlineRendering: Boolean</div>
<div class="uncovered-line"> 18: ) {</div>
<div class="uncovered-line"> 19: /** Returns a Glide [Key] signature (see [MathModelSignature] for specifics). */</div>
<div class="uncovered-line"> 20: fun toKeySignature(): MathModelSignature =</div>
<div class="covered-line"> 21: MathModelSignature.createSignature(rawLatex, lineHeight, useInlineRendering)</div>
<div class="uncovered-line"> 22: </div>
<div class="uncovered-line"> 23: /**</div>
<div class="uncovered-line"> 24: * Glide [Key] that provides caching support by allowing individual renderable math scenarios to</div>
<div class="uncovered-line"> 25: * be comparable based on select parameters.</div>
<div class="uncovered-line"> 26: *</div>
<div class="uncovered-line"> 27: * @property rawLatex the raw LaTeX string used to render a cached bitmap</div>
<div class="uncovered-line"> 28: * @property lineHeightHundredX an [Int] representation of the 100x scaled line height from</div>
<div class="uncovered-line"> 29: * [MathModel] (this is used to preserve up to 2 digits of the height, but any past that will</div>
<div class="uncovered-line"> 30: * be truncated to reduce cache size for highly reusable cached renders)</div>
<div class="uncovered-line"> 31: * @property useInlineRendering whether the render is formatted to be displayed in-line with text</div>
<div class="uncovered-line"> 32: */</div>
<div class="covered-line"> 33: data class MathModelSignature(</div>
<div class="covered-line"> 34: val rawLatex: String,</div>
<div class="covered-line"> 35: val lineHeightHundredX: Int,</div>
<div class="covered-line"> 36: val useInlineRendering: Boolean</div>
<div class="uncovered-line"> 37: ) : Key {</div>
<div class="uncovered-line"> 38: // Impl reference: http:https://bumptech.github.io/glide/doc/caching.html#custom-cache-invalidation.</div>
<div class="uncovered-line"> 39: </div>
<div class="uncovered-line"> 40: override fun updateDiskCacheKey(messageDigest: MessageDigest) {</div>
<div class="covered-line"> 41: val rawLatexBytes = rawLatex.encodeToByteArray()</div>
<div class="covered-line"> 42: messageDigest.update(</div>
<div class="covered-line"> 43: ByteBuffer.allocate(rawLatexBytes.size + Int.SIZE_BYTES + 1).apply {</div>
<div class="covered-line"> 44: put(rawLatexBytes)</div>
<div class="covered-line"> 45: putInt(lineHeightHundredX)</div>
<div class="covered-line"> 46: put(if (useInlineRendering) 1 else 0)</div>
<div class="covered-line"> 47: }.array()</div>
<div class="uncovered-line"> 48: )</div>
<div class="covered-line"> 49: }</div>
<div class="uncovered-line"> 50: </div>
<div class="uncovered-line"> 51: internal companion object {</div>
<div class="uncovered-line"> 52: /** Returns a new [MathModelSignature] for the specified [MathModel] properties. */</div>
<div class="uncovered-line"> 53: internal fun createSignature(</div>
<div class="uncovered-line"> 54: rawLatex: String,</div>
<div class="uncovered-line"> 55: lineHeight: Float,</div>
<div class="uncovered-line"> 56: useInlineRendering: Boolean</div>
<div class="uncovered-line"> 57: ): MathModelSignature {</div>
<div class="covered-line"> 58: val lineHeightHundredX = (lineHeight * 100f).toInt()</div>
<div class="covered-line"> 59: return MathModelSignature(rawLatex, lineHeightHundredX, useInlineRendering)</div>
<div class="uncovered-line"> 60: }</div>
<div class="uncovered-line"> 61: }</div>
<div class="uncovered-line"> 62: }</div>
<div class="uncovered-line"> 63: }</div>
</pre>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Coverage Report

**Total coverage:**
- **Files covered:** 1
- **Covered File:** utility/src/main/java/org/oppia/android/util/parser/math/MathModel.kt
- **Coverage percentage:** 87.50% covered
- **Line coverage:** 19 covered / 19 found
- **Function coverage:** 7 covered / 11 found
- **Branch coverage:** 2 covered / 2 found
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coverage Report</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
padding: 20px;
}
.covered-line, .not-covered-line, .uncovered-line {
display: inline-block;
width: auto;
padding: 2px 4px;
margin: 0;
}
.covered-line {
background-color: #c8e6c9; /* Light green */
}
.not-covered-line {
background-color: #ffcdd2; /* Light red */
}
.uncovered-line {
background-color: #ffffff; /* White */
}
.coverage-summary {
margin-bottom: 20px;
}
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<h1>Coverage Report</h1>
<div class="coverage-summary">
<h2>Total coverage:</h2>
<ul>
<li><strong>Files covered:</strong> 1</li>
<li><strong>Covered File:</strong> utility/src/main/java/org/oppia/android/util/math/FloatExtensions.kt</li>
<li><strong>Coverage percentage:</strong> 80.00% covered</li>
<li><strong>Line coverage:</strong> 0 covered / 0 found</li>
<li><strong>Function coverage:</strong> 0 covered / 0 found</li>
<li><strong>Branch coverage:</strong> 0 covered / 0 found</li>
</ul>
</div>
<pre><div class="uncovered-line"> 1: package org.oppia.android.util.math</div>
<div class="uncovered-line"> 2: </div>
<div class="uncovered-line"> 3: import kotlin.math.abs</div>
<div class="uncovered-line"> 4: </div>
<div class="uncovered-line"> 5: /**</div>
<div class="uncovered-line"> 6: * The error margin used for approximately [Float] equality checking, that is, the largest distance</div>
<div class="uncovered-line"> 7: * from any particular number before a new value will be considered unequal (i.e. all values between</div>
<div class="uncovered-line"> 8: * a float and (float-interval, float+interval) will be considered equal to the float).</div>
<div class="uncovered-line"> 9: *</div>
<div class="uncovered-line"> 10: * Note that the machine epsilon value from https://en.wikipedia.org/wiki/Machine_epsilon is defined</div>
<div class="uncovered-line"> 11: * defined as the smallest value that, when added to, or subtract from, 1, will result in a value</div>
<div class="uncovered-line"> 12: * that is exactly equal to 1. A larger value is picked here for more allowance in variance.</div>
<div class="uncovered-line"> 13: */</div>
<div class="uncovered-line"> 14: const val FLOAT_EQUALITY_EPSILON: Float = 1e-6f</div>
<div class="uncovered-line"> 15: </div>
<div class="uncovered-line"> 16: /**</div>
<div class="uncovered-line"> 17: * The error margin used for approximately [Double] equality checking.</div>
<div class="uncovered-line"> 18: *</div>
<div class="uncovered-line"> 19: * See [FLOAT_EQUALITY_EPSILON] for an explanation of this value.</div>
<div class="uncovered-line"> 20: */</div>
<div class="uncovered-line"> 21: const val DOUBLE_EQUALITY_EPSILON: Double = 1e-13</div>
<div class="uncovered-line"> 22: </div>
<div class="uncovered-line"> 23: /**</div>
<div class="uncovered-line"> 24: * Returns whether this float approximately equals another based on a consistent epsilon value</div>
<div class="uncovered-line"> 25: * ([FLOAT_EQUALITY_EPSILON]).</div>
<div class="uncovered-line"> 26: */</div>
<div class="uncovered-line"> 27: fun Float.isApproximatelyEqualTo(other: Float): Boolean {</div>
<div class="covered-line"> 28: return abs(this - other) < FLOAT_EQUALITY_EPSILON</div>
<div class="uncovered-line"> 29: }</div>
<div class="uncovered-line"> 30: </div>
<div class="uncovered-line"> 31: /**</div>
<div class="uncovered-line"> 32: * Returns whether this double approximately equals another based on a consistent epsilon value</div>
<div class="uncovered-line"> 33: * ([DOUBLE_EQUALITY_EPSILON]).</div>
<div class="uncovered-line"> 34: */</div>
<div class="uncovered-line"> 35: fun Double.isApproximatelyEqualTo(other: Double): Boolean {</div>
<div class="covered-line"> 36: return abs(this - other) < DOUBLE_EQUALITY_EPSILON</div>
<div class="uncovered-line"> 37: }</div>
<div class="uncovered-line"> 38: </div>
<div class="uncovered-line"> 39: /**</div>
<div class="uncovered-line"> 40: * Returns a string representation of this [Double] that keeps the double in pure decimal and never</div>
<div class="uncovered-line"> 41: * relies on scientific notation (unlike [Double.toString]).</div>
<div class="uncovered-line"> 42: */</div>
<div class="not-covered-line"> 43: fun Double.toPlainString(): String = toBigDecimal().toPlainString()</div>
</pre>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Coverage Report

**Total coverage:**
- **Files covered:** 1
- **Covered File:** utility/src/main/java/org/oppia/android/util/math/FloatExtensions.kt
- **Coverage percentage:** 80.00% covered
- **Line coverage:** 2 covered / 3 found
- **Function coverage:** 2 covered / 3 found
- **Branch coverage:** 4 covered / 4 found
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ class BazelClient(private val rootDirectory: File, private val commandExecutor:
* or null if the coverage data file could not be parsed
*/
fun runCoverageForTestTarget(bazelTestTarget: String): List<String>? {
val computeInstrumentation = bazelTestTarget.split("/").let{"//${it[2]}/..."}
val coverageCommandOutputLines = executeBazelCommand(
"coverage",
bazelTestTarget,
"--instrumentation_filter=//"
"--instrumentation_filter=$computeInstrumentation"
)
return parseCoverageDataFilePath(coverageCommandOutputLines)?.let { path ->
File(path).readLines()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ fun main(vararg args: String) {
val repoRoot = args[0]
val filePath = args[1]

if (!File(repoRoot, filePath).exists()) {
error("File doesn't exist.")
}

ScriptBackgroundCoroutineDispatcher().use { scriptBgDispatcher ->
val processTimeout: Long = args.find { it.startsWith("processTimeout=") }
?.substringAfter("=")
Expand Down Expand Up @@ -79,7 +83,7 @@ class RunCoverage(
.getExemptedFilePathList()

if (filePath in testFileExemptionList) {
println("This file is exempted from having a test file. Hence No coverage!")
println("This file is exempted from having a test file; skipping coverage check.")
return emptyList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.oppia.android.scripts.common.CommandExecutorImpl
import org.oppia.android.scripts.common.ScriptBackgroundCoroutineDispatcher
import org.oppia.android.testing.assertThrows
import org.oppia.android.scripts.testing.TestBazelWorkspace
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import java.util.concurrent.TimeUnit
import java.io.File

/** Tests for [RunCoverage]. */
class RunCoverageTest {
Expand Down Expand Up @@ -40,6 +42,24 @@ class RunCoverageTest {
scriptBgDispatcher.close()
}

@Test
fun testRunCoverage_validFile_runsCoverage() {
testBazelWorkspace.initEmptyWorkspace()
val sampleFile = File(tempFolder.root.absolutePath, "file.kt")
sampleFile.createNewFile()
main(tempFolder.root.absolutePath, "file.kt")
}

@Test
fun testRunCoverage_invalidFile_runsCoverage() {
testBazelWorkspace.initEmptyWorkspace()
val exception = assertThrows<IllegalStateException>() {
main(tempFolder.root.absolutePath, "file.kt")
}

assertThat(exception).hasMessageThat().contains("File doesn't exist")
}

@Test
fun testRunCoverage_testFileExempted_noCoverage() {
val exemptedFilePath = "app/src/main/java/org/oppia/android/app/activity/ActivityComponent.kt"
Expand All @@ -56,7 +76,7 @@ class RunCoverageTest {
}

@Test
fun testRunCoverage_validSampleTestFile_returnsCoverageData() {
fun testRunCoverage_sampleTests_returnsCoverageData() {
testBazelWorkspace.initEmptyWorkspace()

val sourceContent =
Expand Down Expand Up @@ -139,7 +159,7 @@ class RunCoverageTest {
}

@Test
fun testRunCoverage_validScriptPathSampleTestFile_returnsCoverageData() {
fun testRunCoverage_scriptTests_returnsCoverageData() {
testBazelWorkspace.initEmptyWorkspace()

val sourceContent =
Expand Down Expand Up @@ -222,7 +242,7 @@ class RunCoverageTest {
}

@Test
fun testRunCoverage_validAppPathSampleTestFile_returnsCoverageData() {
fun testRunCoverage_appTests_returnsCoverageData() {
testBazelWorkspace.initEmptyWorkspace()

val sourceContent =
Expand Down Expand Up @@ -305,7 +325,7 @@ class RunCoverageTest {
}

@Test
fun testRunCoverage_validMultiSampleTestFile_returnsCoverageData() {
fun testRunCoverage_sharedAndLocalTests_returnsCoverageData() {
testBazelWorkspace.initEmptyWorkspace()

val sourceContent =
Expand Down