[Native][tests] Refactoring: Rename TestListing* to GTestListing*
^KT-50316
This commit is contained in:
+4
-4
@@ -6,13 +6,13 @@
|
|||||||
package org.jetbrains.kotlin.konan.blackboxtest
|
package org.jetbrains.kotlin.konan.blackboxtest
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.parseGTestListing
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.GTestListing
|
||||||
import org.junit.jupiter.api.Assertions.*
|
import org.junit.jupiter.api.Assertions.*
|
||||||
import org.junit.jupiter.api.Tag
|
import org.junit.jupiter.api.Tag
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
@Tag("infrastructure")
|
@Tag("infrastructure")
|
||||||
class InfrastructureTestListingTest {
|
class InfrastructureGTestListingTest {
|
||||||
@Test
|
@Test
|
||||||
fun successfullyParsed() = assertEquals(
|
fun successfullyParsed() = assertEquals(
|
||||||
listOf(
|
listOf(
|
||||||
@@ -35,7 +35,7 @@ class InfrastructureTestListingTest {
|
|||||||
"a.b.__launcher__Kt.bar",
|
"a.b.__launcher__Kt.bar",
|
||||||
"a.b.__launcher__Kt.baz",
|
"a.b.__launcher__Kt.baz",
|
||||||
).map(::TestName),
|
).map(::TestName),
|
||||||
parseGTestListing(
|
GTestListing.parse(
|
||||||
"""
|
"""
|
||||||
|Seed: 123
|
|Seed: 123
|
||||||
|Seed: 456
|
|Seed: 456
|
||||||
@@ -156,7 +156,7 @@ class InfrastructureTestListingTest {
|
|||||||
companion object {
|
companion object {
|
||||||
private fun assertCorrectParseError(expectedMessage: String, lineNumber: Int, listing: String) {
|
private fun assertCorrectParseError(expectedMessage: String, lineNumber: Int, listing: String) {
|
||||||
try {
|
try {
|
||||||
parseGTestListing(listing)
|
GTestListing.parse(listing)
|
||||||
fail { "Listing parsed without errors" }
|
fail { "Listing parsed without errors" }
|
||||||
} catch (e: AssertionError) {
|
} catch (e: AssertionError) {
|
||||||
val message = e.message.orEmpty()
|
val message = e.message.orEmpty()
|
||||||
+2
-2
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.konan.blackboxtest.support.runner
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.LoggedData
|
import org.jetbrains.kotlin.konan.blackboxtest.support.LoggedData
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
||||||
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.GTestListing
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.TestOutputFilter
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.TestOutputFilter
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.parseGTestListing
|
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
|
|
||||||
@@ -38,6 +38,6 @@ internal class LocalTestNameExtractor(
|
|||||||
runResult: RunResult.Completed
|
runResult: RunResult.Completed
|
||||||
) : AbstractLocalProcessRunner<Collection<TestName>>.ResultHandler(runResult) {
|
) : AbstractLocalProcessRunner<Collection<TestName>>.ResultHandler(runResult) {
|
||||||
override fun getLoggedRun() = LoggedData.TestRun(getLoggedParameters(), runResult)
|
override fun getLoggedRun() = LoggedData.TestRun(getLoggedParameters(), runResult)
|
||||||
override fun doHandle() = parseGTestListing(runResult.processOutput.stdOut.filteredOutput)
|
override fun doHandle() = GTestListing.parse(runResult.processOutput.stdOut.filteredOutput)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-53
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
|||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.GTestListingParseState as State
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts [TestName]s from GTest listing.
|
* Extracts [TestName]s from GTest listing.
|
||||||
@@ -22,60 +21,62 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.util.GTestListingParseSta
|
|||||||
* yields TestName(packageName = "sample.test", packagePartClassName = "SampleTestKt", functionName = "one")
|
* yields TestName(packageName = "sample.test", packagePartClassName = "SampleTestKt", functionName = "one")
|
||||||
* and TestName(packageName = "sample.test", packagePartClassName = "SampleTestKt", functionName = "two")
|
* and TestName(packageName = "sample.test", packagePartClassName = "SampleTestKt", functionName = "two")
|
||||||
*/
|
*/
|
||||||
internal fun parseGTestListing(listing: String): Collection<TestName> = buildList {
|
internal object GTestListing {
|
||||||
fun parseError(message: String, index: Int, line: String): Nothing = fail {
|
fun parse(listing: String): Collection<TestName> = buildList {
|
||||||
buildString {
|
fun parseError(message: String, index: Int, line: String): Nothing = fail {
|
||||||
appendLine("$message at line #$index: \"$line\"")
|
buildString {
|
||||||
appendLine()
|
appendLine("$message at line #$index: \"$line\"")
|
||||||
appendLine("Full listing:")
|
appendLine()
|
||||||
appendLine(listing)
|
appendLine("Full listing:")
|
||||||
}
|
appendLine(listing)
|
||||||
}
|
|
||||||
|
|
||||||
var state: State = State.Begin
|
|
||||||
|
|
||||||
val lines = listing.lines()
|
|
||||||
lines.forEachIndexed { index, line ->
|
|
||||||
fun parseError(message: String): Nothing = parseError(message, index, line)
|
|
||||||
|
|
||||||
state = when {
|
|
||||||
line.startsWith(STDLIB_TESTS_IGNORED_LINE_PREFIX) && state is State.Begin -> State.Begin
|
|
||||||
line.isBlank() -> when (state) {
|
|
||||||
is State.NewTest, is State.End -> State.End
|
|
||||||
else -> parseError("Unexpected empty line")
|
|
||||||
}
|
|
||||||
line[0].isWhitespace() -> when (state) {
|
|
||||||
is State.NewTestSuite,
|
|
||||||
is State.NewTest -> {
|
|
||||||
val testSuite = state.testSuite
|
|
||||||
this += TestName(testSuite.testSuiteNameWithDotSuffix + line.trim())
|
|
||||||
State.NewTest(testSuite)
|
|
||||||
}
|
|
||||||
else -> parseError("Test name encountered before test suite name")
|
|
||||||
}
|
|
||||||
else -> when (state) {
|
|
||||||
is State.Begin, is State.NewTest -> {
|
|
||||||
State.NewTestSuite(line.trimEnd())
|
|
||||||
}
|
|
||||||
else -> parseError("Unexpected test suite name")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var state: ParseState = ParseState.Begin
|
||||||
|
|
||||||
|
val lines = listing.lines()
|
||||||
|
lines.forEachIndexed { index, line ->
|
||||||
|
fun parseError(message: String): Nothing = parseError(message, index, line)
|
||||||
|
|
||||||
|
state = when {
|
||||||
|
line.startsWith(STDLIB_TESTS_IGNORED_LINE_PREFIX) && state is ParseState.Begin -> ParseState.Begin
|
||||||
|
line.isBlank() -> when (state) {
|
||||||
|
is ParseState.NewTest, is ParseState.End -> ParseState.End
|
||||||
|
else -> parseError("Unexpected empty line")
|
||||||
|
}
|
||||||
|
line[0].isWhitespace() -> when (state) {
|
||||||
|
is ParseState.NewTestSuite,
|
||||||
|
is ParseState.NewTest -> {
|
||||||
|
val testSuite = state.testSuite
|
||||||
|
this += TestName(testSuite.testSuiteNameWithDotSuffix + line.trim())
|
||||||
|
ParseState.NewTest(testSuite)
|
||||||
|
}
|
||||||
|
else -> parseError("Test name encountered before test suite name")
|
||||||
|
}
|
||||||
|
else -> when (state) {
|
||||||
|
is ParseState.Begin, is ParseState.NewTest -> {
|
||||||
|
ParseState.NewTestSuite(line.trimEnd())
|
||||||
|
}
|
||||||
|
else -> parseError("Unexpected test suite name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state is ParseState.NewTestSuite)
|
||||||
|
parseError("Test name expected before test suite name", lines.lastIndex, lines.last())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state is State.NewTestSuite)
|
private sealed interface ParseState {
|
||||||
parseError("Test name expected before test suite name", lines.lastIndex, lines.last())
|
object Begin : ParseState
|
||||||
|
object End : ParseState
|
||||||
|
|
||||||
|
class NewTestSuite(val testSuiteNameWithDotSuffix: String) : ParseState
|
||||||
|
class NewTest(val testSuite: NewTestSuite) : ParseState
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline val ParseState.testSuite: ParseState.NewTestSuite
|
||||||
|
get() = safeAs<ParseState.NewTestSuite>() ?: cast<ParseState.NewTest>().testSuite
|
||||||
|
|
||||||
|
// The very first line of stdlib test output may contain seed of Random. Such line should be ignored.
|
||||||
|
private const val STDLIB_TESTS_IGNORED_LINE_PREFIX = "Seed: "
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed interface GTestListingParseState {
|
|
||||||
object Begin : State
|
|
||||||
object End : State
|
|
||||||
|
|
||||||
class NewTestSuite(val testSuiteNameWithDotSuffix: String) : State
|
|
||||||
class NewTest(val testSuite: NewTestSuite) : State
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline val State.testSuite: State.NewTestSuite
|
|
||||||
get() = safeAs<State.NewTestSuite>() ?: cast<State.NewTest>().testSuite
|
|
||||||
|
|
||||||
// The very first line of stdlib test output may contain seed of Random. Such line should be ignored.
|
|
||||||
private const val STDLIB_TESTS_IGNORED_LINE_PREFIX = "Seed: "
|
|
||||||
|
|||||||
Reference in New Issue
Block a user