Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/android_remote_parser_listener_2
Browse files Browse the repository at this point in the history
Malinskiy authored Jan 22, 2024
2 parents c3c0976 + 034a996 commit 419fb44
Showing 12 changed files with 106 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -74,6 +74,9 @@ class AmInstrumentTestParser(
testBundles: List<AndroidTestBundle>,
blockListenerArgumentOverride: Boolean,
): List<Test> {
val androidAppInstaller = AndroidAppInstaller(configuration)
androidAppInstaller.prepareInstallation(device)

return testBundles.flatMap { bundle ->
val androidTestBundle =
AndroidTestBundle(bundle.application, bundle.testApplication, bundle.extraApplications, bundle.splitApks)
@@ -100,8 +103,6 @@ class AmInstrumentTestParser(
supportedFeatures = device.supportedFeatures,
coroutineScope = device,
)
val androidAppInstaller = AndroidAppInstaller(configuration)
androidAppInstaller.prepareInstallation(device)
val channel = device.executeTestRequest(runnerRequest)
var observedAnnotations = false

Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package com.malinskiy.marathon.ios
import com.malinskiy.marathon.config.Configuration
import com.malinskiy.marathon.config.vendor.VendorConfiguration
import com.malinskiy.marathon.ios.executor.listener.AppleTestRunListener
import com.malinskiy.marathon.ios.extensions.testBundle
import com.malinskiy.marathon.ios.test.TestEvent
import com.malinskiy.marathon.ios.test.TestPassed
import com.malinskiy.marathon.ios.test.TestFailed
@@ -40,6 +41,7 @@ class AppleDeviceTestRunner(private val device: AppleSimulatorDevice, private va
tests = rawTestBatch.tests,
xcresult = remoteXcresultPath,
coverage = configuration.isCodeCoverageEnabled,
testTargetName = vendorConfiguration.testBundle().testBundleId,
)
var channel: ReceiveChannel<List<TestEvent>>? = null
try {
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ import com.malinskiy.marathon.ios.executor.listener.TestResultsListener
import com.malinskiy.marathon.ios.executor.listener.TestRunListenerAdapter
import com.malinskiy.marathon.ios.executor.listener.screenshot.ScreenCapturerTestRunListener
import com.malinskiy.marathon.ios.logparser.XctestEventProducer
import com.malinskiy.marathon.ios.logparser.formatter.NoopPackageNameFormatter
import com.malinskiy.marathon.ios.logparser.parser.DebugLogPrinter
import com.malinskiy.marathon.ios.logparser.parser.DeviceFailureException
import com.malinskiy.marathon.ios.logparser.parser.DiagnosticLogsPathFinder
@@ -349,7 +348,7 @@ class AppleSimulatorDevice(
withContext(Dispatchers.IO) {
val deferredStdout = supervisorScope {
async {
val testEventProducer = XctestEventProducer(NoopPackageNameFormatter, timer)
val testEventProducer = XctestEventProducer(request.testTargetName ?: "", timer)
for (line in session.stdout) {
testEventProducer.process(line)?.let {
send(it)
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import com.malinskiy.marathon.device.Device
import com.malinskiy.marathon.exceptions.TestParsingException
import com.malinskiy.marathon.execution.RemoteTestParser
import com.malinskiy.marathon.execution.withRetry
import com.malinskiy.marathon.ios.extensions.testBundle
import com.malinskiy.marathon.ios.model.AppleTestBundle
import com.malinskiy.marathon.ios.test.TestEvent
import com.malinskiy.marathon.ios.test.TestRequest
@@ -77,7 +78,9 @@ class XCTestParser(
for (event in events) {
when (event) {
is TestStarted -> {
tests.add(event.id)
//Target name is never printed via xcodebuild. We create it using the bundle id in com.malinskiy.marathon.ios.xctestrun.TestRootFactory
val testWithTargetName = event.id.copy(pkg = vendorConfiguration.testBundle().testBundleId)
tests.add(testWithTargetName)
}
else -> Unit
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.malinskiy.marathon.ios.logparser

import com.malinskiy.marathon.ios.logparser.formatter.PackageNameFormatter
import com.malinskiy.marathon.ios.logparser.parser.DeviceFailureParser
import com.malinskiy.marathon.ios.logparser.parser.TestRunProgressParser
import com.malinskiy.marathon.ios.test.TestEvent
import com.malinskiy.marathon.time.Timer

/**
* Currently doesn't provide any guarantee on the methods that should be called even once
*
* @param targetName target name (or blueprint name) is not printed by xcodebuild output, we have to augment the results to still have
* 'target/class_name/test_name' structure mapped properly to marathon's package.class.method
*/
class XctestEventProducer(packageNameFormatter: PackageNameFormatter, timer: Timer) : TestEventProducer {
class XctestEventProducer(targetName: String, timer: Timer) : TestEventProducer {
private val failureParser = DeviceFailureParser()
private val testRunListener = TestRunProgressParser(timer, packageNameFormatter)
private val testRunListener = TestRunProgressParser(timer, targetName)

override fun process(line: String): List<TestEvent>? {
return failureParser.process(line) ?: testRunListener.process(line)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.malinskiy.marathon.ios.logparser.parser

import com.malinskiy.marathon.ios.logparser.TestEventProducer
import com.malinskiy.marathon.ios.logparser.formatter.PackageNameFormatter
import com.malinskiy.marathon.ios.test.TestEvent
import com.malinskiy.marathon.ios.test.TestFailed
import com.malinskiy.marathon.ios.test.TestIgnored
@@ -14,14 +13,14 @@ import kotlin.math.roundToInt

class TestRunProgressParser(
private val timer: Timer,
private val packageNameFormatter: PackageNameFormatter,
private val targetName: String,
) : TestEventProducer {

val logger = MarathonLogging.logger(TestRunProgressParser::class.java.simpleName)

val TEST_CASE_STARTED = """Test Case '-\[([a-zA-Z0-9_.]+) ([a-zA-Z0-9_]+)]' started\.""".toRegex()
val TEST_CASE_STARTED = """Test Case '-\[([a-zA-Z0-9_.]+) ([a-zA-Z0-9_ ]+)]' started\.""".toRegex()
val TEST_CASE_FINISHED =
"""Test Case '-\[([a-zA-Z0-9_.]+) ([a-zA-Z0-9_]+)]' (passed|failed|skipped) \(([\d\.]+) seconds\)\.""".toRegex()
"""Test Case '-\[([a-zA-Z0-9_.]+) ([a-zA-Z0-9_ ]+)]' (passed|failed|skipped) \(([\d\.]+) seconds\)\.""".toRegex()

/**
* $1 = file
@@ -65,8 +64,13 @@ class TestRunProgressParser(
var pkg: String? = null
var clazz: String? = null
if (pkgWithClass != null) {
pkg = packageNameFormatter.format(pkgWithClass.substringBeforeLast('.', missingDelimiterValue = ""))
clazz = pkgWithClass.substringAfter('.', missingDelimiterValue = pkgWithClass)
if (pkgWithClass.contains('.')) {
pkg = pkgWithClass.substringBeforeLast('.', missingDelimiterValue = "")
clazz = pkgWithClass.substringAfter('.', missingDelimiterValue = pkgWithClass)
} else {
pkg = targetName
clazz = pkgWithClass
}
}

val method = matchResult?.groups?.get(2)?.value
@@ -111,8 +115,13 @@ class TestRunProgressParser(
var pkg: String? = null
var clazz: String? = null
if (pkgWithClass != null) {
pkg = packageNameFormatter.format(pkgWithClass.substringBeforeLast('.', missingDelimiterValue = ""))
clazz = pkgWithClass.substringAfter('.', missingDelimiterValue = pkgWithClass)
if (pkgWithClass.contains('.')) {
pkg = pkgWithClass.substringBeforeLast('.', missingDelimiterValue = "")
clazz = pkgWithClass.substringAfter('.', missingDelimiterValue = pkgWithClass)
} else {
pkg = targetName
clazz = pkgWithClass
}
}
val method = matchResult?.groups?.get(2)?.value

Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ data class TestRequest(
val coverage: Boolean,
val tests: List<Test>? = null,
val xcresult: String? = null,
val testTargetName: String? = null,
) {
fun toXcodebuildTestFilter(): Array<String> {
return tests?.map { "'-only-testing:${it.toTestName(packageSeparator = '/', methodSeparator = '/')}'" }?.toTypedArray() ?: emptyArray()
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package com.malinskiy.marathon.ios.logparser.parser

import assertk.assertThat
import assertk.assertions.isEqualTo
import com.malinskiy.marathon.ios.logparser.formatter.NoopPackageNameFormatter
import com.malinskiy.marathon.ios.test.TestEvent
import com.malinskiy.marathon.time.Timer
import org.mockito.kotlin.mock
@@ -23,7 +22,7 @@ class TestRunProgressParserTest {

@Test
fun testSample1() {
val parser = TestRunProgressParser(mockTimer, NoopPackageNameFormatter)
val parser = TestRunProgressParser(mockTimer, "")

val events = mutableListOf<TestEvent>()
javaClass.getResourceAsStream("/fixtures/test_output/success_0.log").bufferedReader().use {
@@ -40,7 +39,7 @@ class TestRunProgressParserTest {

@Test
fun testSample2() {
val parser = TestRunProgressParser(mockTimer, NoopPackageNameFormatter)
val parser = TestRunProgressParser(mockTimer, "testTarget")

val events = mutableListOf<TestEvent>()
javaClass.getResourceAsStream("/fixtures/test_output/patrol.log").bufferedReader().use {
@@ -57,7 +56,24 @@ class TestRunProgressParserTest {

@Test
fun testSample3() {
val parser = TestRunProgressParser(mockTimer, NoopPackageNameFormatter)
val parser = TestRunProgressParser(mockTimer, "")

val events = mutableListOf<TestEvent>()
javaClass.getResourceAsStream("/fixtures/test_output/success_multiple_0.log").bufferedReader().use {
it.lines().forEach { line ->
parser.process(line)?.let {
events.addAll(it)
}
}
}

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/fixtures/test_output/success_multiple_0.expected").reader().readText().trimEnd())
}

@Test
fun testSample3WithTargetOverride() {
val parser = TestRunProgressParser(mockTimer, "testTarget")

val events = mutableListOf<TestEvent>()
javaClass.getResourceAsStream("/fixtures/test_output/success_multiple_0.log").bufferedReader().use {
@@ -74,7 +90,7 @@ class TestRunProgressParserTest {

@Test
fun testX() {
val parser = TestRunProgressParser(mockTimer, NoopPackageNameFormatter)
val parser = TestRunProgressParser(mockTimer, "")

// """Test Case '-[sample_appUITests.MoreTests testPresentModal]' started."""
parser.process("""Test Case '-[RunnerUITests androidAppTest___tapsAround]' started.""")

Large diffs are not rendered by default.

0 comments on commit 419fb44

Please sign in to comment.