-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: iOS support for testplans (#1321)
Fixes #685 ## Documentation https://github.com/Flank/flank/blob/master/docs/feature/ios_test_plans.md ## Test Plan > How do we know the code works? From repository root: ``` . .env flankScripts testArtifacts -b master resolve flankScripts shell buildFlank cd test_runner flank ios run -c=./src/test/kotlin/ftl/fixtures/test_app_cases/flank-xctestrunv2-all.yml ``` Feel free to modify `flank-xctestrunv2-all.yml` to test possible edge-cases. ## Checklist - [x] Documented - [x] Unit tested
- Loading branch information
Showing
33 changed files
with
924 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 13 additions & 14 deletions
27
test_runner/src/main/kotlin/ftl/ios/xctest/FindXcTestNamesV1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
package ftl.ios.xctest | ||
|
||
import com.dd.plist.NSDictionary | ||
import ftl.ios.xctest.common.XctestrunMethods | ||
import ftl.ios.xctest.common.findTestsForTarget | ||
import ftl.ios.xctest.common.isMetadata | ||
import ftl.ios.xctest.common.parseToNSDictionary | ||
import java.io.File | ||
|
||
internal fun findXcTestNamesV1(xctestrun: String): XctestrunMethods = | ||
findXcTestNamesV1(File(xctestrun)) | ||
|
||
private fun findXcTestNamesV1(xctestrun: File): XctestrunMethods = | ||
parseToNSDictionary(xctestrun).run { | ||
val testRoot = xctestrun.parent + "/" | ||
allKeys().filterNot(String::isMetadata).map { testTarget -> | ||
internal fun findXcTestNamesV1( | ||
xcTestRoot: String, | ||
xcTestNsDictionary: NSDictionary | ||
): Map<String, List<String>> = | ||
xcTestNsDictionary | ||
.allKeys() | ||
.filterNot(String::isMetadata) | ||
.map { testTarget -> | ||
testTarget to findTestsForTarget( | ||
testRoot = testRoot, | ||
testTargetDict = get(testTarget) as NSDictionary, | ||
testRoot = xcTestRoot, | ||
testTargetDict = xcTestNsDictionary[testTarget] as NSDictionary, | ||
testTargetName = testTarget, | ||
) | ||
}.distinct().toMap() | ||
} | ||
} | ||
.distinct() | ||
.toMap() |
41 changes: 22 additions & 19 deletions
41
test_runner/src/main/kotlin/ftl/ios/xctest/FindXcTestNamesV2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
package ftl.ios.xctest | ||
|
||
import ftl.ios.xctest.common.XctestrunMethods | ||
import com.dd.plist.NSDictionary | ||
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 | ||
|
||
internal fun findXcTestNamesV2(xctestrun: String): Map<String, XctestrunMethods> = | ||
findXcTestNamesV2(File(xctestrun)) | ||
internal fun findXcTestNamesV2( | ||
xcTestRoot: String, | ||
xcTestNsDictionary: NSDictionary | ||
): Map<String, Map<String, List<String>>> = | ||
xcTestNsDictionary | ||
.getTestConfigurations() | ||
.mapValues { (_, configDict: NSDictionary) -> | ||
configDict.findTestTargetMethods(xcTestRoot) | ||
} | ||
|
||
private fun findXcTestNamesV2(xctestrun: File): Map<String, XctestrunMethods> { | ||
val testRoot = xctestrun.parent + "/" | ||
return parseToNSDictionary(xctestrun).getTestConfigurations().mapValues { (_, configDict) -> | ||
configDict.getTestTargets() | ||
.associateBy { targetDict -> targetDict.getBlueprintName() } | ||
.mapValues { (name, dict) -> | ||
findTestsForTarget( | ||
testRoot = testRoot, | ||
testTargetName = name, | ||
testTargetDict = dict, | ||
) | ||
} | ||
} | ||
} | ||
private fun NSDictionary.findTestTargetMethods( | ||
xcTestRoot: String | ||
): Map<String, List<String>> = | ||
getTestTargets() | ||
.associateBy { targetDict -> targetDict.getBlueprintName() } | ||
.mapValues { (name, dict) -> | ||
findTestsForTarget( | ||
testRoot = xcTestRoot, | ||
testTargetName = name, | ||
testTargetDict = dict, | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
test_runner/src/main/kotlin/ftl/ios/xctest/ReduceXcTestRunV1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ftl.ios.xctest | ||
|
||
import com.dd.plist.NSDictionary | ||
import ftl.ios.xctest.common.XCTEST_METADATA | ||
import ftl.ios.xctest.common.setOnlyTestIdentifiers | ||
|
||
fun NSDictionary.reduceXcTestRunV1( | ||
targets: Map<String, List<String>>, | ||
): NSDictionary = apply { | ||
(keys - targets.keys - XCTEST_METADATA).forEach(this::remove) | ||
targets.forEach { (testTarget, methods) -> | ||
setOnlyTestIdentifiers(testTarget, methods) | ||
} | ||
} | ||
|
||
private fun NSDictionary.setOnlyTestIdentifiers( | ||
testTarget: String, | ||
methods: List<String> | ||
) { | ||
set( | ||
testTarget, | ||
getValue(testTarget) | ||
.let { it as NSDictionary } | ||
.setOnlyTestIdentifiers(methods) | ||
) | ||
} |
46 changes: 46 additions & 0 deletions
46
test_runner/src/main/kotlin/ftl/ios/xctest/ReduceXcTestRunV2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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_CONFIGURATIONS | ||
import ftl.ios.xctest.common.TEST_TARGETS | ||
import ftl.ios.xctest.common.getBlueprintName | ||
import ftl.ios.xctest.common.getTestConfigurations | ||
import ftl.ios.xctest.common.getTestTargets | ||
import ftl.ios.xctest.common.setOnlyTestIdentifiers | ||
|
||
fun NSDictionary.reduceXcTestRunV2( | ||
configuration: String, | ||
targets: Map<String, List<String>> | ||
): NSDictionary = apply { | ||
set( | ||
TEST_CONFIGURATIONS, | ||
getTestConfigurations() | ||
.getValue(configuration) | ||
.reduceTestConfiguration(targets) | ||
.inNSArray() | ||
) | ||
} | ||
|
||
private fun NSDictionary.reduceTestConfiguration( | ||
targetMethods: Map<String, List<String>> | ||
): NSDictionary = apply { | ||
set( | ||
TEST_TARGETS, | ||
getTestTargets().mapNotNull { target -> | ||
targetMethods[target.getBlueprintName()]?.let { methods -> | ||
target.setOnlyTestIdentifiers(methods) | ||
} | ||
}.toNsArray() | ||
) | ||
} | ||
|
||
private fun <T : NSObject> List<T>.toNsArray(): NSArray = | ||
NSArray(size).also { nsArray -> | ||
forEachIndexed { index, t -> | ||
nsArray.setValue(index, t) | ||
} | ||
} | ||
|
||
private fun NSObject.inNSArray() = NSArray(1).also { it.setValue(0, this) } |
36 changes: 0 additions & 36 deletions
36
test_runner/src/main/kotlin/ftl/ios/xctest/RewriteXcTestRunV1.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.