From 390f9c7ca316b8ee639ccad48df029a98dfc23ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20G=C3=B3ral?= Date: Fri, 6 Nov 2020 11:28:22 +0100 Subject: [PATCH] Upgrade unit tests & fix rewriteXcTestRunV2 implementation --- .../ftl/ios/xctest/FindXcTestNamesV2.kt | 7 +- .../ftl/ios/xctest/RewriteXcTestRunV2.kt | 45 ++- .../main/kotlin/ftl/ios/xctest/common/Util.kt | 16 +- .../test/kotlin/ftl/gc/GcIosTestMatrixTest.kt | 2 +- .../src/test/kotlin/ftl/ios/Constants.kt | 3 - .../src/test/kotlin/ftl/ios/ParseTest.kt | 114 ------- .../src/test/kotlin/ftl/ios/XctestrunTest.kt | 309 ------------------ .../ftl/ios/xctest/FindXcTestNamesV1KtTest.kt | 24 ++ .../ftl/ios/xctest/FindXcTestNamesV2KtTest.kt | 21 ++ .../ios/xctest/RewriteXcTestRunV1KtTest.kt | 184 +++++++++++ .../ios/xctest/RewriteXcTestRunV2KtTest.kt | 60 ++++ .../src/test/kotlin/ftl/ios/xctest/Util.kt | 99 ++++++ .../xctest/common/FindTestsForTargetKtTest.kt | 88 +++++ .../ios/xctest/common/ParseObjTestsKtTest.kt | 33 ++ .../xctest/common/ParseSwiftTestsKtTest.kt | 38 +++ .../ftl/ios/xctest/common/UtilKtTest.kt | 24 ++ 16 files changed, 611 insertions(+), 456 deletions(-) delete mode 100644 test_runner/src/test/kotlin/ftl/ios/Constants.kt delete mode 100644 test_runner/src/test/kotlin/ftl/ios/ParseTest.kt delete mode 100644 test_runner/src/test/kotlin/ftl/ios/XctestrunTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/FindXcTestNamesV1KtTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/FindXcTestNamesV2KtTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/RewriteXcTestRunV1KtTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/RewriteXcTestRunV2KtTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/Util.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/common/FindTestsForTargetKtTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/common/ParseObjTestsKtTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/common/ParseSwiftTestsKtTest.kt create mode 100644 test_runner/src/test/kotlin/ftl/ios/xctest/common/UtilKtTest.kt diff --git a/test_runner/src/main/kotlin/ftl/ios/xctest/FindXcTestNamesV2.kt b/test_runner/src/main/kotlin/ftl/ios/xctest/FindXcTestNamesV2.kt index 246064c017..1fc757370b 100644 --- a/test_runner/src/main/kotlin/ftl/ios/xctest/FindXcTestNamesV2.kt +++ b/test_runner/src/main/kotlin/ftl/ios/xctest/FindXcTestNamesV2.kt @@ -1,12 +1,10 @@ package ftl.ios.xctest -import com.dd.plist.NSArray -import com.dd.plist.NSDictionary -import ftl.ios.xctest.common.TEST_TARGETS import ftl.ios.xctest.common.XctestrunMethods import ftl.ios.xctest.common.findTestsForTarget import ftl.ios.xctest.common.getBlueprintName import ftl.ios.xctest.common.getTestConfigurations +import ftl.ios.xctest.common.getTestTargets import ftl.ios.xctest.common.parseToNSDictionary import java.io.File @@ -27,6 +25,3 @@ private fun findXcTestNamesV2(xctestrun: File): Map { } } } - -private fun NSDictionary.getTestTargets(): List = - (get(TEST_TARGETS) as NSArray).array.map { it as NSDictionary } diff --git a/test_runner/src/main/kotlin/ftl/ios/xctest/RewriteXcTestRunV2.kt b/test_runner/src/main/kotlin/ftl/ios/xctest/RewriteXcTestRunV2.kt index bcf4ba2923..10c35c0916 100644 --- a/test_runner/src/main/kotlin/ftl/ios/xctest/RewriteXcTestRunV2.kt +++ b/test_runner/src/main/kotlin/ftl/ios/xctest/RewriteXcTestRunV2.kt @@ -3,41 +3,50 @@ package ftl.ios.xctest import com.dd.plist.NSArray import com.dd.plist.NSDictionary import com.dd.plist.NSObject -import ftl.ios.xctest.common.TEST_CONFIGURATION +import com.google.common.annotations.VisibleForTesting +import ftl.ios.xctest.common.TEST_CONFIGURATIONS import ftl.ios.xctest.common.XctestrunMethods import ftl.ios.xctest.common.getBlueprintName import ftl.ios.xctest.common.getTestConfigurations +import ftl.ios.xctest.common.getTestTargets import ftl.ios.xctest.common.parseToNSDictionary import ftl.ios.xctest.common.setOnlyTestIdentifiers import ftl.ios.xctest.common.toByteArray fun rewriteXcTestRunV2( xcTestPlan: String, - filterMethods: List + filterMethods: List = emptyList() ): Map = rewriteXcTestRunV2( parseToNSDictionary(xcTestPlan), - findXcTestNamesV2(xcTestPlan).mapValues { (_, map) -> - map.mapValues { (_, list) -> - list.filter(filterMethods::contains) - } - }, + findXcTestNamesV2(xcTestPlan).filterXcTestMethods(filterMethods), ) -private fun rewriteXcTestRunV2( +@VisibleForTesting +internal fun Map.filterXcTestMethods( + names: List +) = mapValues { (_, map) -> + map.mapValues { (_, list) -> + list.filter(names::contains) + } +} + +@VisibleForTesting +internal fun rewriteXcTestRunV2( root: NSDictionary, methods: Map ): Map = - root.getTestConfigurations().mapValues { (key, configDict) -> - root.clone().also { - val testMethods = methods[key] - ?.get(configDict.getBlueprintName()) - ?: emptyList() - - it[TEST_CONFIGURATION] = configDict - .setOnlyTestIdentifiers(testMethods) - .wrapInNSArray() + root.getTestConfigurations().mapValues { (configName, configDict) -> + root.clone().also { rootClone -> + rootClone[TEST_CONFIGURATIONS] = configDict.clone().apply { + getTestTargets().forEach { target -> + val testMethods = methods[configName] + ?.get(target.getBlueprintName()) + ?: emptyList() + target.setOnlyTestIdentifiers(testMethods) + } + }.wrapInNSArray() }.toByteArray() }.toMap() -private fun NSObject.wrapInNSArray() = NSArray().also { it.setValue(0, this) } +private fun NSObject.wrapInNSArray() = NSArray(1).also { it.setValue(0, this) } diff --git a/test_runner/src/main/kotlin/ftl/ios/xctest/common/Util.kt b/test_runner/src/main/kotlin/ftl/ios/xctest/common/Util.kt index 60ca7d9564..b948a5c156 100644 --- a/test_runner/src/main/kotlin/ftl/ios/xctest/common/Util.kt +++ b/test_runner/src/main/kotlin/ftl/ios/xctest/common/Util.kt @@ -12,7 +12,7 @@ typealias XctestrunMethods = Map> internal const val XCTEST_METADATA = "__xctestrun_metadata__" internal const val FORMAT_VERSION = "FormatVersion" -internal const val TEST_CONFIGURATION = "TestConfiguration" +internal const val TEST_CONFIGURATIONS = "TestConfigurations" internal const val TEST_TARGETS = "TestTargets" internal const val TEST_PLAN = "TestPlan" internal const val NAME = "Name" @@ -28,19 +28,25 @@ internal fun NSDictionary.getXcTestRunVersion(): Int = ?.get(FORMAT_VERSION)?.toJavaObject(Int::class.java) ?: throw FlankGeneralError("Given NSDictionary doesn't contains $FORMAT_VERSION") -fun NSDictionary.getTestConfigurations(): Map = +internal fun NSDictionary.getTestConfigurations(): Map = testConfigurationsNSArray().array.map { it as NSDictionary }.associateBy { it.getName() } private fun NSDictionary.testConfigurationsNSArray(): NSArray = - get(TEST_CONFIGURATION) as NSArray + get(TEST_CONFIGURATIONS) as NSArray + +internal fun NSDictionary.getTestTargets(): List = + (get(TEST_TARGETS) as NSArray).array.map { it as NSDictionary } + +internal fun NSDictionary.getOnlyTestIdentifiers() = + (get(ONLY_TEST_IDENTIFIERS) as NSArray).array.map { it.toString() } private fun NSDictionary.getName(): String = get(NAME) ?.toJavaObject(String::class.java) ?: throw FlankConfigurationError("Cannot get Name key from NSDictionary:\n ${toXMLPropertyList()}") -fun NSDictionary.getBlueprintName() = get(BLUEPRINT_NAME).toString() +internal fun NSDictionary.getBlueprintName() = get(BLUEPRINT_NAME).toString() internal fun NSDictionary.toByteArray(): ByteArray { val out = ByteArrayOutputStream() @@ -74,7 +80,7 @@ internal fun validateIsFile(path: String) = File(path).run { // https://github.com/google/xctestrunner/blob/51dbb6b7eb35f2ed55439459ca49e06992bc4da0/xctestrunner/test_runner/xctestrun.py#L129 // Rewrites tests so that only the listed tests execute -fun NSDictionary.setOnlyTestIdentifiers(methods: Collection) = apply { +internal fun NSDictionary.setOnlyTestIdentifiers(methods: Collection) = apply { while (containsKey(ONLY_TEST_IDENTIFIERS)) remove(ONLY_TEST_IDENTIFIERS) this[ONLY_TEST_IDENTIFIERS] = NSArray(methods.size).also { methods.forEachIndexed(it::setValue) } } diff --git a/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt b/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt index e8da56641c..2911f8fc83 100644 --- a/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt +++ b/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt @@ -4,7 +4,7 @@ import com.dd.plist.NSDictionary import com.google.api.services.testing.model.IosDeviceList import ftl.args.IosArgs import ftl.config.FtlConstants.isWindows -import ftl.ios.FIXTURES_PATH +import ftl.ios.xctest.FIXTURES_PATH import ftl.shard.Chunk import ftl.shard.TestMethod import ftl.test.util.FlankTestRunner diff --git a/test_runner/src/test/kotlin/ftl/ios/Constants.kt b/test_runner/src/test/kotlin/ftl/ios/Constants.kt deleted file mode 100644 index f85d25e180..0000000000 --- a/test_runner/src/test/kotlin/ftl/ios/Constants.kt +++ /dev/null @@ -1,3 +0,0 @@ -package ftl.ios - -const val FIXTURES_PATH = "./src/test/kotlin/ftl/fixtures/tmp" diff --git a/test_runner/src/test/kotlin/ftl/ios/ParseTest.kt b/test_runner/src/test/kotlin/ftl/ios/ParseTest.kt deleted file mode 100644 index 8faaba2f69..0000000000 --- a/test_runner/src/test/kotlin/ftl/ios/ParseTest.kt +++ /dev/null @@ -1,114 +0,0 @@ -package ftl.ios - -import com.google.common.truth.Truth.assertThat -import ftl.config.FtlConstants.isWindows -import ftl.ios.xctest.common.parseObjcTests -import ftl.ios.xctest.common.parseSwiftTests -import ftl.test.util.FlankTestRunner -import ftl.run.exception.FlankGeneralError -import org.junit.Assume.assumeFalse -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(FlankTestRunner::class) -class ParseTest { - - private val objcBinary = "$FIXTURES_PATH/ios/earl_grey_example/objc/EarlGreyExampleTests" - private val swiftBinary = "$FIXTURES_PATH/ios/earl_grey_example/swift/EarlGreyExampleSwiftTests" - - private val objcTests = listOf( - "EarlGreyExampleTests/testBasicSelection", - "EarlGreyExampleTests/testBasicSelectionActionAssert", - "EarlGreyExampleTests/testBasicSelectionAndAction", - "EarlGreyExampleTests/testBasicSelectionAndAssert", - "EarlGreyExampleTests/testCatchErrorOnFailure", - "EarlGreyExampleTests/testCollectionMatchers", - "EarlGreyExampleTests/testCustomAction", - "EarlGreyExampleTests/testLayout", - "EarlGreyExampleTests/testSelectionOnMultipleElements", - "EarlGreyExampleTests/testTableCellOutOfScreen", - "EarlGreyExampleTests/testWithCondition", - "EarlGreyExampleTests/testWithCustomAssertion", - "EarlGreyExampleTests/testWithCustomFailureHandler", - "EarlGreyExampleTests/testWithCustomMatcher", - "EarlGreyExampleTests/testWithInRoot" - ) - - private val swiftTests = listOf( - "EarlGreyExampleSwiftTests/testBasicSelection", - "EarlGreyExampleSwiftTests/testBasicSelectionActionAssert", - "EarlGreyExampleSwiftTests/testBasicSelectionAndAction", - "EarlGreyExampleSwiftTests/testBasicSelectionAndAssert", - "EarlGreyExampleSwiftTests/testCatchErrorOnFailure", - "EarlGreyExampleSwiftTests/testCollectionMatchers", - "EarlGreyExampleSwiftTests/testCustomAction", - "EarlGreyExampleSwiftTests/testLayout", - "EarlGreyExampleSwiftTests/testSelectionOnMultipleElements", - "EarlGreyExampleSwiftTests/testTableCellOutOfScreen", - "EarlGreyExampleSwiftTests/testThatThrows", - "EarlGreyExampleSwiftTests/testWithCondition", - "EarlGreyExampleSwiftTests/testWithCustomAssertion", - "EarlGreyExampleSwiftTests/testWithCustomFailureHandler", - "EarlGreyExampleSwiftTests/testWithCustomMatcher", - "EarlGreyExampleSwiftTests/testWithGreyAssertions", - "EarlGreyExampleSwiftTests/testWithInRoot" - ) - - private fun checkObjcTests(actual: List) { - actual.forEachIndexed { index, result -> - assertThat(objcTests[index]).isEqualTo(result) - } - - assertThat(objcTests.size).isEqualTo(actual.size) - } - - private fun checkSwiftTests(actual: List) { - actual.forEachIndexed { index, result -> - assertThat(result).isEqualTo(swiftTests[index]) - } - - assertThat(actual.size).isEqualTo(swiftTests.size) - } - - @Test - fun `Parse ObjC and Swift with space in path`() { - assumeFalse(isWindows) - - var results = parseObjcTests("$FIXTURES_PATH/sp ace/objc/EarlGreyExampleTests").sorted() - checkObjcTests(results) - - results = parseSwiftTests("$FIXTURES_PATH/sp ace/swift/EarlGreyExampleSwiftTests").sorted() - checkSwiftTests(results) - } - - @Test - fun parseObjcTests() { - assumeFalse(isWindows) - - val results = parseObjcTests(objcBinary).sorted() - checkObjcTests(results) - } - - @Test(expected = FlankGeneralError::class) - fun `parseObjcTests fileNotFound`() { - parseObjcTests("./BinaryThatDoesNotExist") - } - - @Test - fun parseSwiftTests() { - assumeFalse(isWindows) - - val results = parseSwiftTests(swiftBinary).sorted() - checkSwiftTests(results) - } - - @Test(expected = FlankGeneralError::class) - fun `parseSwiftTests fileNotFound`() { - parseSwiftTests("./BinaryThatDoesNotExist") - } - - @Test(expected = FlankGeneralError::class) - fun `parseSwiftTests tmpFolder`() { - parseSwiftTests("/tmp") - } -} diff --git a/test_runner/src/test/kotlin/ftl/ios/XctestrunTest.kt b/test_runner/src/test/kotlin/ftl/ios/XctestrunTest.kt deleted file mode 100644 index 9508223f4c..0000000000 --- a/test_runner/src/test/kotlin/ftl/ios/XctestrunTest.kt +++ /dev/null @@ -1,309 +0,0 @@ -package ftl.ios - -import com.dd.plist.NSArray -import com.dd.plist.NSDictionary -import com.google.common.truth.Truth.assertThat -import ftl.config.FtlConstants.isWindows -import ftl.ios.xctest.common.findTestsForTestTarget -import ftl.ios.xctest.findXcTestNamesV1 -import ftl.ios.xctest.common.parseToNSDictionary -import ftl.ios.xctest.rewriteXcTestRunV1 -import ftl.test.util.FlankTestRunner -import ftl.test.util.TestHelper.normalizeLineEnding -import ftl.run.exception.FlankGeneralError -import org.junit.Assume.assumeFalse -import org.junit.Test -import org.junit.runner.RunWith -import java.io.File -import java.nio.file.Files -import java.nio.file.Paths - -@RunWith(FlankTestRunner::class) -class XctestrunTest { - - private val swiftXctestrun = "$FIXTURES_PATH/ios/earl_grey_example/EarlGreyExampleSwiftTests.xctestrun" - private val multipleTargetsSwiftXctestrun = "$FIXTURES_PATH/ios/flank_ios_example/FlankExampleTests.xctestrun" - - private val swiftTests = listOf( - "EarlGreyExampleSwiftTests/testBasicSelection", - "EarlGreyExampleSwiftTests/testBasicSelectionActionAssert", - "EarlGreyExampleSwiftTests/testBasicSelectionAndAction", - "EarlGreyExampleSwiftTests/testBasicSelectionAndAssert", - "EarlGreyExampleSwiftTests/testCatchErrorOnFailure", - "EarlGreyExampleSwiftTests/testCollectionMatchers", - "EarlGreyExampleSwiftTests/testCustomAction", - "EarlGreyExampleSwiftTests/testLayout", - "EarlGreyExampleSwiftTests/testSelectionOnMultipleElements", - "EarlGreyExampleSwiftTests/testTableCellOutOfScreen", - "EarlGreyExampleSwiftTests/testThatThrows", - "EarlGreyExampleSwiftTests/testWithCondition", - "EarlGreyExampleSwiftTests/testWithCustomAssertion", - "EarlGreyExampleSwiftTests/testWithCustomFailureHandler", - "EarlGreyExampleSwiftTests/testWithCustomMatcher", - "EarlGreyExampleSwiftTests/testWithGreyAssertions", - "EarlGreyExampleSwiftTests/testWithInRoot" - ) - - @Test - fun parse() { - val result = parseToNSDictionary(swiftXctestrun) - assertThat(arrayOf("EarlGreyExampleSwiftTests", "__xctestrun_metadata__")).isEqualTo(result.allKeys()) - val dict = result["EarlGreyExampleSwiftTests"] as NSDictionary - assertThat(dict.count()).isEqualTo(20) - assertThat(dict.containsKey("OnlyTestIdentifiers")).isFalse() - } - - @Test(expected = FlankGeneralError::class) - fun `parse fileNotFound`() { - parseToNSDictionary("./XctestrunThatDoesNotExist") - } - - @Test - fun findTestNames() { - assumeFalse(isWindows) - - val names = findXcTestNamesV1(swiftXctestrun) - .flatMap { it.value } - .sorted() - assertThat(swiftTests).isEqualTo(names) - } - - @Test - fun rewrite() { - assumeFalse(isWindows) - - val root = parseToNSDictionary(swiftXctestrun) - val methods = findTestsForTestTarget(testTarget = "EarlGreyExampleSwiftTests", xctestrun = File(swiftXctestrun)) - val methodsData = mapOf>("EarlGreyExampleSwiftTests" to methods) - - val results = String(rewriteXcTestRunV1(root, methodsData)) - - assertThat(results.contains("OnlyTestIdentifiers")).isTrue() - } - - @Test - fun rewriteImmutable() { - assumeFalse(isWindows) - - val root = parseToNSDictionary(swiftXctestrun) - val methods = findTestsForTestTarget(testTarget = "EarlGreyExampleSwiftTests", xctestrun = File(swiftXctestrun)) - val methodsData = mapOf>("EarlGreyExampleSwiftTests" to methods) - - // ensure root object isn't modified. Rewrite should return a new object. - val key = "OnlyTestIdentifiers" - - assertThat(root.toASCIIPropertyList().contains(key)).isFalse() - - rewriteXcTestRunV1(root, methodsData) - - assertThat(root.toASCIIPropertyList().contains(key)).isFalse() - } - - @Test - fun `rewrite idempotent`() { - val root = NSDictionary() - root["EarlGreyExampleSwiftTests"] = NSDictionary() - root["EarlGreyExampleTests"] = NSDictionary() - val methods = listOf("testOne", "testTwo") - val methodsData = mapOf>("EarlGreyExampleSwiftTests" to methods, "EarlGreyExampleTests" to methods) - rewriteXcTestRunV1(root, methodsData) - rewriteXcTestRunV1(root, methodsData) - val result = rewriteXcTestRunV1(root, methodsData) - val expected = """ - - - - EarlGreyExampleSwiftTests - - OnlyTestIdentifiers - - testOne - testTwo - - - EarlGreyExampleTests - - OnlyTestIdentifiers - - testOne - testTwo - - - -""" - assertThat(expected).isEqualTo(String(result).normalizeLineEnding()) - } - - @Test - fun `rewrite preserves skip`() { - val inputXml = """ - - - - - EarlGreyExampleSwiftTests - - SkipTestIdentifiers - - testTwo - - OnlyTestIdentifiers - - testOne - testTwo - - - - - """.trimIndent() - val root = parseToNSDictionary(inputXml.toByteArray()) - - val tests = mapOf>("EarlGreyExampleSwiftTests" to listOf("testOne", "testTwo")) - val rewrittenXml = String(rewriteXcTestRunV1(root, tests)) - - assertThat(inputXml).isEqualTo(rewrittenXml.normalizeLineEnding()) - } - - @Test - fun `findTestNames respects skip`() { - assumeFalse(isWindows) - - val inputXml = """ - - - - - EarlGreyExampleSwiftTests - - DependentProductPaths - - __TESTROOT__/Debug-iphoneos/EarlGreyExampleSwift.app/PlugIns/EarlGreyExampleSwiftTests.xctest - __TESTROOT__/Debug-iphoneos/EarlGreyExampleSwift.app - - SkipTestIdentifiers - - EarlGreyExampleSwiftTests/testBasicSelectionActionAssert - EarlGreyExampleSwiftTests/testBasicSelectionAndAction - EarlGreyExampleSwiftTests/testBasicSelectionAndAssert - EarlGreyExampleSwiftTests/testCatchErrorOnFailure - EarlGreyExampleSwiftTests/testCollectionMatchers - EarlGreyExampleSwiftTests/testCustomAction - EarlGreyExampleSwiftTests/testLayout - EarlGreyExampleSwiftTests/testSelectionOnMultipleElements - EarlGreyExampleSwiftTests/testTableCellOutOfScreen - EarlGreyExampleSwiftTests/testThatThrows - EarlGreyExampleSwiftTests/testWithCondition - EarlGreyExampleSwiftTests/testWithCustomAssertion - EarlGreyExampleSwiftTests/testWithCustomFailureHandler - EarlGreyExampleSwiftTests/testWithCustomMatcher - EarlGreyExampleSwiftTests/testWithGreyAssertions - EarlGreyExampleSwiftTests/testWithInRoot - - - - - """.trimIndent() - - val tmpXml = Paths.get(FIXTURES_PATH, "skip.xctestrun") - Files.write(tmpXml, inputXml.toByteArray()) - tmpXml.toFile().deleteOnExit() - - val actualTests = findTestsForTestTarget("EarlGreyExampleSwiftTests", tmpXml.toFile()).sorted() - assertThat(actualTests).isEqualTo(listOf("EarlGreyExampleSwiftTests/testBasicSelection")) - } - - @Test - fun findTestNamesForTestTarget() { - assumeFalse(isWindows) - val names = findTestsForTestTarget(testTarget = "EarlGreyExampleSwiftTests", xctestrun = File(swiftXctestrun)).sorted() - assertThat(swiftTests).isEqualTo(names) - } - - @Test(expected = FlankGeneralError::class) - fun `findTestNames for nonexisting test target`() { - assumeFalse(isWindows) - findTestsForTestTarget(testTarget = "Incorrect", xctestrun = File(swiftXctestrun)).sorted() - } - - @Test - fun `find test names for xctestrun file containing multiple test targets`() { - assumeFalse(isWindows) - val names = findTestsForTestTarget(testTarget = "FlankExampleTests", xctestrun = File(multipleTargetsSwiftXctestrun)).sorted() - assertThat(names).isEqualTo(listOf("FlankExampleTests/test1", "FlankExampleTests/test2")) - - val names2 = findTestsForTestTarget(testTarget = "FlankExampleSecondTests", xctestrun = File(multipleTargetsSwiftXctestrun)).sorted() - assertThat(names2).isEqualTo(listOf("FlankExampleSecondTests/test3", "FlankExampleSecondTests/test4")) - } - - @Test - fun `rewrite methods in single test target`() { - assumeFalse(isWindows) - val methods = listOf("EarlGreyExampleSwiftTests/testBasicSelectionActionAssert", "EarlGreyExampleSwiftTests/testBasicSelection") - val result = rewriteXcTestRunV1(xctestrun = swiftXctestrun, methods) - val resultXML = parseToNSDictionary(result) - val testTarget = resultXML["EarlGreyExampleSwiftTests"] as NSDictionary - val resultMethods = testTarget["OnlyTestIdentifiers"] as NSArray - - assertThat(methods.toSet()).isEqualTo(resultMethods.array.map { it.toJavaObject() }.toSet()) - } - - @Test - fun `rewrite methods in multiple test targets`() { - assumeFalse(isWindows) // TODO enable it on #1180 - - val expectedMethods1 = listOf("FlankExampleTests/test1", "FlankExampleTests/test2") - val expectedMethods2 = listOf("FlankExampleSecondTests/test3") - - val result = rewriteXcTestRunV1(xctestrun = multipleTargetsSwiftXctestrun, listOf(expectedMethods1, expectedMethods2).flatMap { it }) - val resultXML = parseToNSDictionary(result) - - val target1 = resultXML["FlankExampleTests"] as NSDictionary - val target2 = resultXML["FlankExampleSecondTests"] as NSDictionary - val resultMethods1 = target1["OnlyTestIdentifiers"] as NSArray - val resultMethods2 = target2["OnlyTestIdentifiers"] as NSArray - - assertThat(expectedMethods1.toSet()).isEqualTo(resultMethods1.array.map { it.toJavaObject() }.toSet()) - assertThat(expectedMethods2.toSet()).isEqualTo(resultMethods2.array.map { it.toJavaObject() }.toSet()) - } - - @Test - fun `rewrite incorrect methods in multiple test targets`() { - assumeFalse(isWindows) // TODO enable it on #1180 - - val methods1 = listOf("incorrect1", "incorrect2") - val methods2 = listOf("incorrect3") - - val result = rewriteXcTestRunV1(xctestrun = multipleTargetsSwiftXctestrun, listOf(methods1, methods2).flatMap { it }) - val resultXML = parseToNSDictionary(result) - - val target1 = resultXML["FlankExampleTests"] as NSDictionary - val target2 = resultXML["FlankExampleSecondTests"] as NSDictionary - val resultMethods1 = target1["OnlyTestIdentifiers"] as NSArray - val resultMethods2 = target2["OnlyTestIdentifiers"] as NSArray - - assertThat(resultMethods1.array.isEmpty()).isTrue() - assertThat(resultMethods2.array.isEmpty()).isTrue() - } - - @Test - fun `rewrite mix of correct and incorrect methods in multiple test targets`() { - assumeFalse(isWindows) // TODO enable it on #1180 - - val methods1 = listOf("FlankExampleTests/test1", "FlankExampleTests/test2", "incorrect1") - val methods2 = listOf("FlankExampleSecondTests/test3", "incorrect2") - - val expectedMethods1 = listOf("FlankExampleTests/test1", "FlankExampleTests/test2") - val expectedMethods2 = listOf("FlankExampleSecondTests/test3") - - val result = rewriteXcTestRunV1(xctestrun = multipleTargetsSwiftXctestrun, listOf(methods1, methods2).flatMap { it }) - val resultXML = parseToNSDictionary(result) - - val target1 = resultXML["FlankExampleTests"] as NSDictionary - val target2 = resultXML["FlankExampleSecondTests"] as NSDictionary - val resultMethods1 = target1["OnlyTestIdentifiers"] as NSArray - val resultMethods2 = target2["OnlyTestIdentifiers"] as NSArray - - assertThat(expectedMethods1.toSet()).isEqualTo(resultMethods1.array.map { it.toJavaObject() }.toSet()) - assertThat(expectedMethods2.toSet()).isEqualTo(resultMethods2.array.map { it.toJavaObject() }.toSet()) - } -} diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/FindXcTestNamesV1KtTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/FindXcTestNamesV1KtTest.kt new file mode 100644 index 0000000000..046a09a5fc --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/FindXcTestNamesV1KtTest.kt @@ -0,0 +1,24 @@ +package ftl.ios.xctest + +import com.google.common.truth.Truth.assertThat +import ftl.config.FtlConstants +import org.junit.Assume.assumeFalse +import org.junit.Test + +class FindXcTestNamesV1KtTest { + + @Test + fun findTestNames() { + assumeFalse(FtlConstants.isWindows) + + // when + val names = findXcTestNamesV1(swiftXcTestRunV1) + .flatMap { it.value } + .sorted() + + // then + assertThat(swiftTestsV1).isEqualTo(names) + } +} + + diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/FindXcTestNamesV2KtTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/FindXcTestNamesV2KtTest.kt new file mode 100644 index 0000000000..4b203c6852 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/FindXcTestNamesV2KtTest.kt @@ -0,0 +1,21 @@ +package ftl.ios.xctest + +import com.google.common.truth.Truth.assertThat +import ftl.config.FtlConstants +import org.junit.Assume.assumeFalse +import org.junit.Test + +class FindXcTestNamesV2KtTest { + + @Test + fun findTestNames() { + assumeFalse(FtlConstants.isWindows) + + // when + val names = findXcTestNamesV2(swiftXcTestRunV2) + + // then + val sortedNames = names.mapValues { it.value.mapValues { entry -> entry.value.sorted() } } + assertThat(sortedNames).isEqualTo(swiftTestsV2) + } +} diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/RewriteXcTestRunV1KtTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/RewriteXcTestRunV1KtTest.kt new file mode 100644 index 0000000000..6e7ff76c18 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/RewriteXcTestRunV1KtTest.kt @@ -0,0 +1,184 @@ +package ftl.ios.xctest + +import com.dd.plist.NSArray +import com.dd.plist.NSDictionary +import com.google.common.truth.Truth.assertThat +import ftl.config.FtlConstants +import ftl.ios.xctest.common.findTestsForTestTarget +import ftl.ios.xctest.common.parseToNSDictionary +import ftl.test.util.TestHelper.normalizeLineEnding +import org.junit.Assume.assumeFalse +import org.junit.Test +import java.io.File + +class RewriteXcTestRunV1KtTest { + + @Test + fun rewrite() { + assumeFalse(FtlConstants.isWindows) + + val root = parseToNSDictionary(swiftXcTestRunV1) + val methods = findTestsForTestTarget(testTarget = "EarlGreyExampleSwiftTests", xctestrun = File(swiftXcTestRunV1)) + val methodsData = mapOf("EarlGreyExampleSwiftTests" to methods) + + val results = String(rewriteXcTestRunV1(root, methodsData)) + + assertThat(results.contains("OnlyTestIdentifiers")).isTrue() + } + + @Test + fun rewriteImmutable() { + assumeFalse(FtlConstants.isWindows) + + val root = parseToNSDictionary(swiftXcTestRunV1) + val methods = findTestsForTestTarget(testTarget = "EarlGreyExampleSwiftTests", xctestrun = File(swiftXcTestRunV1)) + val methodsData = mapOf("EarlGreyExampleSwiftTests" to methods) + + // ensure root object isn't modified. Rewrite should return a new object. + val key = "OnlyTestIdentifiers" + + assertThat(root.toASCIIPropertyList().contains(key)).isFalse() + + rewriteXcTestRunV1(root, methodsData) + + assertThat(root.toASCIIPropertyList().contains(key)).isFalse() + } + + @Test + fun `rewrite idempotent`() { + val root = NSDictionary() + root["EarlGreyExampleSwiftTests"] = NSDictionary() + root["EarlGreyExampleTests"] = NSDictionary() + val methods = listOf("testOne", "testTwo") + val methodsData = mapOf("EarlGreyExampleSwiftTests" to methods, "EarlGreyExampleTests" to methods) + rewriteXcTestRunV1(root, methodsData) + rewriteXcTestRunV1(root, methodsData) + val result = rewriteXcTestRunV1(root, methodsData) + val expected = """ + + + + EarlGreyExampleSwiftTests + + OnlyTestIdentifiers + + testOne + testTwo + + + EarlGreyExampleTests + + OnlyTestIdentifiers + + testOne + testTwo + + + +""" + assertThat(expected).isEqualTo(String(result).normalizeLineEnding()) + } + + @Test + fun `rewrite preserves skip`() { + val inputXml = """ + + + + + EarlGreyExampleSwiftTests + + SkipTestIdentifiers + + testTwo + + OnlyTestIdentifiers + + testOne + testTwo + + + + + """.trimIndent() + val root = parseToNSDictionary(inputXml.toByteArray()) + + val tests = mapOf("EarlGreyExampleSwiftTests" to listOf("testOne", "testTwo")) + val rewrittenXml = String(rewriteXcTestRunV1(root, tests)) + + assertThat(inputXml).isEqualTo(rewrittenXml.normalizeLineEnding()) + } + + + @Test + fun `rewrite methods in single test target`() { + assumeFalse(FtlConstants.isWindows) + val methods = listOf("EarlGreyExampleSwiftTests/testBasicSelectionActionAssert", "EarlGreyExampleSwiftTests/testBasicSelection") + val result = rewriteXcTestRunV1(xctestrun = swiftXcTestRunV1, methods) + val resultXML = parseToNSDictionary(result) + val testTarget = resultXML["EarlGreyExampleSwiftTests"] as NSDictionary + val resultMethods = testTarget["OnlyTestIdentifiers"] as NSArray + + assertThat(methods.toSet()).isEqualTo(resultMethods.array.map { it.toJavaObject() }.toSet()) + } + + @Test + fun `rewrite methods in multiple test targets`() { + assumeFalse(FtlConstants.isWindows) // TODO enable it on #1180 + + val expectedMethods1 = listOf("FlankExampleTests/test1", "FlankExampleTests/test2") + val expectedMethods2 = listOf("FlankExampleSecondTests/test3") + + val result = rewriteXcTestRunV1(xctestrun = multiTargetsSwiftXcTestRunV1, listOf(expectedMethods1, expectedMethods2).flatMap { it }) + val resultXML = parseToNSDictionary(result) + + val target1 = resultXML["FlankExampleTests"] as NSDictionary + val target2 = resultXML["FlankExampleSecondTests"] as NSDictionary + val resultMethods1 = target1["OnlyTestIdentifiers"] as NSArray + val resultMethods2 = target2["OnlyTestIdentifiers"] as NSArray + + assertThat(expectedMethods1.toSet()).isEqualTo(resultMethods1.array.map { it.toJavaObject() }.toSet()) + assertThat(expectedMethods2.toSet()).isEqualTo(resultMethods2.array.map { it.toJavaObject() }.toSet()) + } + + @Test + fun `rewrite incorrect methods in multiple test targets`() { + assumeFalse(FtlConstants.isWindows) // TODO enable it on #1180 + + val methods1 = listOf("incorrect1", "incorrect2") + val methods2 = listOf("incorrect3") + + val result = rewriteXcTestRunV1(xctestrun = multiTargetsSwiftXcTestRunV1, listOf(methods1, methods2).flatMap { it }) + val resultXML = parseToNSDictionary(result) + + val target1 = resultXML["FlankExampleTests"] as NSDictionary + val target2 = resultXML["FlankExampleSecondTests"] as NSDictionary + val resultMethods1 = target1["OnlyTestIdentifiers"] as NSArray + val resultMethods2 = target2["OnlyTestIdentifiers"] as NSArray + + assertThat(resultMethods1.array.isEmpty()).isTrue() + assertThat(resultMethods2.array.isEmpty()).isTrue() + } + + @Test + fun `rewrite mix of correct and incorrect methods in multiple test targets`() { + assumeFalse(FtlConstants.isWindows) // TODO enable it on #1180 + + val methods1 = listOf("FlankExampleTests/test1", "FlankExampleTests/test2", "incorrect1") + val methods2 = listOf("FlankExampleSecondTests/test3", "incorrect2") + + val expectedMethods1 = listOf("FlankExampleTests/test1", "FlankExampleTests/test2") + val expectedMethods2 = listOf("FlankExampleSecondTests/test3") + + val result = rewriteXcTestRunV1(xctestrun = multiTargetsSwiftXcTestRunV1, listOf(methods1, methods2).flatMap { it }) + val resultXML = parseToNSDictionary(result) + + val target1 = resultXML["FlankExampleTests"] as NSDictionary + val target2 = resultXML["FlankExampleSecondTests"] as NSDictionary + val resultMethods1 = target1["OnlyTestIdentifiers"] as NSArray + val resultMethods2 = target2["OnlyTestIdentifiers"] as NSArray + + assertThat(expectedMethods1.toSet()).isEqualTo(resultMethods1.array.map { it.toJavaObject() }.toSet()) + assertThat(expectedMethods2.toSet()).isEqualTo(resultMethods2.array.map { it.toJavaObject() }.toSet()) + } +} diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/RewriteXcTestRunV2KtTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/RewriteXcTestRunV2KtTest.kt new file mode 100644 index 0000000000..457ac15656 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/RewriteXcTestRunV2KtTest.kt @@ -0,0 +1,60 @@ +package ftl.ios.xctest + +import com.google.common.truth.Truth.assertThat +import ftl.config.FtlConstants +import ftl.ios.xctest.common.ONLY_TEST_IDENTIFIERS +import ftl.ios.xctest.common.getOnlyTestIdentifiers +import ftl.ios.xctest.common.getTestConfigurations +import ftl.ios.xctest.common.getTestTargets +import ftl.ios.xctest.common.parseToNSDictionary +import org.junit.Assume.assumeFalse +import org.junit.Test + +class RewriteXcTestRunV2KtTest { + + @Test + fun rewrite() { + assumeFalse(FtlConstants.isWindows) + // given + val uiTestsMethods = listOf("UITests/test1") + val secondUiTestsMethods = emptyList() + val expectedTargetNames = listOf("en", "pl") + + // when + val result = rewriteXcTestRunV2( + swiftXcTestRunV2, + uiTestsMethods + ).mapValues { (_, bytes) -> + parseToNSDictionary(bytes) + } + + // then + assertThat(result.keys.toList().sorted()).isEqualTo(expectedTargetNames) + expectedTargetNames.forEach { targetName -> + result.getValue(targetName).getTestConfigurations().values.let { configurations -> + assertThat(configurations.size).isEqualTo(1) + configurations.first().getTestTargets().let { targets -> + assertThat(targets.size).isEqualTo(2) + assertThat(targets[0].getOnlyTestIdentifiers()).isEqualTo(uiTestsMethods) + assertThat(targets[1].getOnlyTestIdentifiers()).isEqualTo(secondUiTestsMethods) + } + } + } + } + + @Test + fun `ensure rewrite not mutates root`() { + assumeFalse(FtlConstants.isWindows) + + // given + val root = parseToNSDictionary(swiftXcTestRunV2) + val methods = findXcTestNamesV2(swiftXcTestRunV2) + assertThat(root.toASCIIPropertyList().contains(ONLY_TEST_IDENTIFIERS)).isFalse() + + // when + rewriteXcTestRunV2(root, methods) + + // then + assertThat(root.toASCIIPropertyList().contains(ONLY_TEST_IDENTIFIERS)).isFalse() + } +} diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/Util.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/Util.kt new file mode 100644 index 0000000000..dd6261ffe8 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/Util.kt @@ -0,0 +1,99 @@ +package ftl.ios.xctest + +import com.google.common.truth.Truth.assertThat + +const val FIXTURES_PATH = "./src/test/kotlin/ftl/fixtures/tmp" + +const val swiftXcTestRunV1 = "$FIXTURES_PATH/ios/earl_grey_example/EarlGreyExampleSwiftTests.xctestrun" +const val multiTargetsSwiftXcTestRunV1 = "$FIXTURES_PATH/ios/flank_ios_example/FlankExampleTests.xctestrun" +const val swiftXcTestRunV2 = "$FIXTURES_PATH/ios/multi_test_targets/AllTests_AllTests_iphoneos13.7-arm64e.xctestrun" + +const val objcBinary = "$FIXTURES_PATH/ios/earl_grey_example/objc/EarlGreyExampleTests" +const val swiftBinary = "$FIXTURES_PATH/ios/earl_grey_example/swift/EarlGreyExampleSwiftTests" + +val objcTestsV1 = listOf( + "EarlGreyExampleTests/testBasicSelection", + "EarlGreyExampleTests/testBasicSelectionActionAssert", + "EarlGreyExampleTests/testBasicSelectionAndAction", + "EarlGreyExampleTests/testBasicSelectionAndAssert", + "EarlGreyExampleTests/testCatchErrorOnFailure", + "EarlGreyExampleTests/testCollectionMatchers", + "EarlGreyExampleTests/testCustomAction", + "EarlGreyExampleTests/testLayout", + "EarlGreyExampleTests/testSelectionOnMultipleElements", + "EarlGreyExampleTests/testTableCellOutOfScreen", + "EarlGreyExampleTests/testWithCondition", + "EarlGreyExampleTests/testWithCustomAssertion", + "EarlGreyExampleTests/testWithCustomFailureHandler", + "EarlGreyExampleTests/testWithCustomMatcher", + "EarlGreyExampleTests/testWithInRoot" +) + +val swiftTestsV1 = listOf( + "EarlGreyExampleSwiftTests/testBasicSelection", + "EarlGreyExampleSwiftTests/testBasicSelectionActionAssert", + "EarlGreyExampleSwiftTests/testBasicSelectionAndAction", + "EarlGreyExampleSwiftTests/testBasicSelectionAndAssert", + "EarlGreyExampleSwiftTests/testCatchErrorOnFailure", + "EarlGreyExampleSwiftTests/testCollectionMatchers", + "EarlGreyExampleSwiftTests/testCustomAction", + "EarlGreyExampleSwiftTests/testLayout", + "EarlGreyExampleSwiftTests/testSelectionOnMultipleElements", + "EarlGreyExampleSwiftTests/testTableCellOutOfScreen", + "EarlGreyExampleSwiftTests/testThatThrows", + "EarlGreyExampleSwiftTests/testWithCondition", + "EarlGreyExampleSwiftTests/testWithCustomAssertion", + "EarlGreyExampleSwiftTests/testWithCustomFailureHandler", + "EarlGreyExampleSwiftTests/testWithCustomMatcher", + "EarlGreyExampleSwiftTests/testWithGreyAssertions", + "EarlGreyExampleSwiftTests/testWithInRoot" +) + +val swiftTestsV2 = mapOf( + "en" to mapOf( + "UITests" to listOf( + "UITests/test1", + "UITests/test1ENLocale", + "UITests/test1PLLocale", + "UITests/test3", + ), + "SecondUITests" to listOf( + "SecondUITests/test11", + "SecondUITests/test12", + "SecondUITests/test13", + "SecondUITests/test2ENLocale", + "SecondUITests/test2PLLocale", + ) + ), + "pl" to mapOf( + "UITests" to listOf( + "UITests/test1", + "UITests/test1ENLocale", + "UITests/test1PLLocale", + "UITests/test3", + ), + "SecondUITests" to listOf( + "SecondUITests/test11", + "SecondUITests/test12", + "SecondUITests/test13", + "SecondUITests/test2ENLocale", + "SecondUITests/test2PLLocale", + ) + ) +) + +fun checkObjcTests(actual: List) { + actual.forEachIndexed { index, result -> + assertThat(objcTestsV1[index]).isEqualTo(result) + } + + assertThat(objcTestsV1.size).isEqualTo(actual.size) +} + +fun checkSwiftTests(actual: List) { + actual.forEachIndexed { index, result -> + assertThat(result).isEqualTo(swiftTestsV1[index]) + } + + assertThat(actual.size).isEqualTo(swiftTestsV1.size) +} diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/common/FindTestsForTargetKtTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/common/FindTestsForTargetKtTest.kt new file mode 100644 index 0000000000..23917ed889 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/common/FindTestsForTargetKtTest.kt @@ -0,0 +1,88 @@ +package ftl.ios.xctest.common + +import com.google.common.truth.Truth.assertThat +import ftl.config.FtlConstants +import ftl.ios.xctest.FIXTURES_PATH +import ftl.ios.xctest.multiTargetsSwiftXcTestRunV1 +import ftl.ios.xctest.swiftTestsV1 +import ftl.ios.xctest.swiftXcTestRunV1 +import ftl.run.exception.FlankGeneralError +import org.junit.Assume.assumeFalse +import org.junit.Test +import java.io.File +import java.nio.file.Files +import java.nio.file.Paths + +class FindTestsForTargetKtTest { + + @Test + fun `findTestNames respects skip`() { + assumeFalse(FtlConstants.isWindows) + + val inputXml = """ + + + + + EarlGreyExampleSwiftTests + + DependentProductPaths + + __TESTROOT__/Debug-iphoneos/EarlGreyExampleSwift.app/PlugIns/EarlGreyExampleSwiftTests.xctest + __TESTROOT__/Debug-iphoneos/EarlGreyExampleSwift.app + + SkipTestIdentifiers + + EarlGreyExampleSwiftTests/testBasicSelectionActionAssert + EarlGreyExampleSwiftTests/testBasicSelectionAndAction + EarlGreyExampleSwiftTests/testBasicSelectionAndAssert + EarlGreyExampleSwiftTests/testCatchErrorOnFailure + EarlGreyExampleSwiftTests/testCollectionMatchers + EarlGreyExampleSwiftTests/testCustomAction + EarlGreyExampleSwiftTests/testLayout + EarlGreyExampleSwiftTests/testSelectionOnMultipleElements + EarlGreyExampleSwiftTests/testTableCellOutOfScreen + EarlGreyExampleSwiftTests/testThatThrows + EarlGreyExampleSwiftTests/testWithCondition + EarlGreyExampleSwiftTests/testWithCustomAssertion + EarlGreyExampleSwiftTests/testWithCustomFailureHandler + EarlGreyExampleSwiftTests/testWithCustomMatcher + EarlGreyExampleSwiftTests/testWithGreyAssertions + EarlGreyExampleSwiftTests/testWithInRoot + + + + + """.trimIndent() + + val tmpXml = Paths.get(FIXTURES_PATH, "skip.xctestrun") + Files.write(tmpXml, inputXml.toByteArray()) + tmpXml.toFile().deleteOnExit() + + val actualTests = findTestsForTestTarget("EarlGreyExampleSwiftTests", tmpXml.toFile()).sorted() + assertThat(actualTests).isEqualTo(listOf("EarlGreyExampleSwiftTests/testBasicSelection")) + } + + @Test + fun findTestNamesForTestTarget() { + assumeFalse(FtlConstants.isWindows) + val names = findTestsForTestTarget(testTarget = "EarlGreyExampleSwiftTests", xctestrun = File(swiftXcTestRunV1)).sorted() + assertThat(swiftTestsV1).isEqualTo(names) + } + + @Test(expected = FlankGeneralError::class) + fun `findTestNames for nonexisting test target`() { + assumeFalse(FtlConstants.isWindows) + findTestsForTestTarget(testTarget = "Incorrect", xctestrun = File(swiftXcTestRunV1)).sorted() + } + + @Test + fun `find test names for xctestrun file containing multiple test targets`() { + assumeFalse(FtlConstants.isWindows) + val names = findTestsForTestTarget(testTarget = "FlankExampleTests", xctestrun = File(multiTargetsSwiftXcTestRunV1)).sorted() + assertThat(names).isEqualTo(listOf("FlankExampleTests/test1", "FlankExampleTests/test2")) + + val names2 = findTestsForTestTarget(testTarget = "FlankExampleSecondTests", xctestrun = File(multiTargetsSwiftXcTestRunV1)).sorted() + assertThat(names2).isEqualTo(listOf("FlankExampleSecondTests/test3", "FlankExampleSecondTests/test4")) + } +} diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/common/ParseObjTestsKtTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/common/ParseObjTestsKtTest.kt new file mode 100644 index 0000000000..e8fc7f5d60 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/common/ParseObjTestsKtTest.kt @@ -0,0 +1,33 @@ +package ftl.ios.xctest.common + +import ftl.config.FtlConstants +import ftl.ios.xctest.FIXTURES_PATH +import ftl.ios.xctest.checkObjcTests +import ftl.ios.xctest.objcBinary +import ftl.run.exception.FlankGeneralError +import org.junit.Assume.assumeFalse +import org.junit.Test + +class ParseObjTestsKtTest { + + @Test + fun parseObjcTests() { + assumeFalse(FtlConstants.isWindows) + + val results = parseObjcTests(objcBinary).sorted() + checkObjcTests(results) + } + + @Test(expected = FlankGeneralError::class) + fun `parseObjcTests fileNotFound`() { + parseObjcTests("./BinaryThatDoesNotExist") + } + + @Test + fun `Parse ObjC with space in path`() { + assumeFalse(FtlConstants.isWindows) + + val results = parseObjcTests("$FIXTURES_PATH/sp ace/objc/EarlGreyExampleTests").sorted() + checkObjcTests(results) + } +} diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/common/ParseSwiftTestsKtTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/common/ParseSwiftTestsKtTest.kt new file mode 100644 index 0000000000..fa4d6e2818 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/common/ParseSwiftTestsKtTest.kt @@ -0,0 +1,38 @@ +package ftl.ios.xctest.common + +import ftl.config.FtlConstants +import ftl.ios.xctest.FIXTURES_PATH +import ftl.ios.xctest.checkSwiftTests +import ftl.ios.xctest.swiftBinary +import ftl.run.exception.FlankGeneralError +import org.junit.Assume.assumeFalse +import org.junit.Test + +class ParseSwiftTestsKtTest { + + @Test + fun parseSwiftTests() { + assumeFalse(FtlConstants.isWindows) + + val results = parseSwiftTests(swiftBinary).sorted() + checkSwiftTests(results) + } + + @Test(expected = FlankGeneralError::class) + fun `parseSwiftTests fileNotFound`() { + parseSwiftTests("./BinaryThatDoesNotExist") + } + + @Test(expected = FlankGeneralError::class) + fun `parseSwiftTests tmpFolder`() { + parseSwiftTests("/tmp") + } + + @Test + fun `Parse Swift with space in path`() { + assumeFalse(FtlConstants.isWindows) + + val results = parseSwiftTests("$FIXTURES_PATH/sp ace/swift/EarlGreyExampleSwiftTests").sorted() + checkSwiftTests(results) + } +} diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/common/UtilKtTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/common/UtilKtTest.kt new file mode 100644 index 0000000000..2f54b284d2 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/common/UtilKtTest.kt @@ -0,0 +1,24 @@ +package ftl.ios.xctest.common + +import com.dd.plist.NSDictionary +import com.google.common.truth.Truth.assertThat +import ftl.ios.xctest.swiftXcTestRunV1 +import ftl.run.exception.FlankGeneralError +import org.junit.Test + +class UtilKtTest { + + @Test + fun parse() { + val result = parseToNSDictionary(swiftXcTestRunV1) + assertThat(arrayOf("EarlGreyExampleSwiftTests", "__xctestrun_metadata__")).isEqualTo(result.allKeys()) + val dict = result["EarlGreyExampleSwiftTests"] as NSDictionary + assertThat(dict.count()).isEqualTo(20) + assertThat(dict.containsKey("OnlyTestIdentifiers")).isFalse() + } + + @Test(expected = FlankGeneralError::class) + fun `parse fileNotFound`() { + parseToNSDictionary("./XctestrunThatDoesNotExist") + } +}