Migrated cocoapods tests to new test dsl (junit 5 and gradle test kit)
This commit is contained in:
committed by
Space Team
parent
58d9727092
commit
c1026a759a
-32
@@ -19,7 +19,6 @@ import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_BUILD_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_GEN_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_IMPORT_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_INSTALL_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_SETUP_BUILD_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_SPEC_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
@@ -31,10 +30,8 @@ import org.junit.jupiter.api.Assumptions
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.io.path.readText
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@OsCondition(supportedOn = [OS.MAC], enabledOnCI = [OS.MAC])
|
||||
@@ -66,7 +63,6 @@ class CocoaPodsGitIT : KGPBaseTest() {
|
||||
private val podGenTaskName = ":$POD_GEN_TASK_NAME"
|
||||
private val podSetupBuildTaskName = ":$POD_SETUP_BUILD_TASK_NAME"
|
||||
private val podBuildTaskName = ":$POD_BUILD_TASK_NAME"
|
||||
private val podInstallTaskName = ":$POD_INSTALL_TASK_NAME"
|
||||
|
||||
private val defaultPodInstallSyntheticTaskName = ":podInstallSyntheticIos"
|
||||
private val defaultPodGenTaskName = podGenFullTaskName()
|
||||
@@ -516,34 +512,6 @@ class CocoaPodsGitIT : KGPBaseTest() {
|
||||
""".trimMargin()
|
||||
}
|
||||
|
||||
private fun BuildResult.podImportAsserts(
|
||||
buildScript: Path,
|
||||
projectName: String? = null,
|
||||
) {
|
||||
|
||||
val buildScriptText = buildScript.readText()
|
||||
val taskPrefix = projectName?.let { ":$it" } ?: ""
|
||||
val podspec = "podspec"
|
||||
|
||||
if ("noPodspec()" in buildScriptText) {
|
||||
assertTasksSkipped("$taskPrefix:$podspec")
|
||||
}
|
||||
|
||||
if ("podfile" in buildScriptText) {
|
||||
assertTasksExecuted("$taskPrefix$podInstallTaskName")
|
||||
} else {
|
||||
assertTasksSkipped("$taskPrefix$podInstallTaskName")
|
||||
}
|
||||
if (buildScriptText.matches("pod\\(.*\\)".toRegex())) {
|
||||
assertTasksExecuted(listOf("$taskPrefix:$POD_GEN_TASK_NAME"))
|
||||
}
|
||||
|
||||
with(listOf(POD_SETUP_BUILD_TASK_NAME, POD_BUILD_TASK_NAME).map { "$taskPrefix:$it" }) {
|
||||
if (buildScriptText.matches("pod\\(.*\\)".toRegex())) {
|
||||
assertTasksExecuted(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isRepoAvailable(repos: List<String>) = runBlocking {
|
||||
HttpClient(CIO).use { client ->
|
||||
|
||||
+709
-943
File diff suppressed because it is too large
Load Diff
+115
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.native
|
||||
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
import kotlin.io.path.appendText
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@OptIn(EnvironmentalVariablesOverride::class)
|
||||
@OsCondition(supportedOn = [OS.MAC], enabledOnCI = [OS.MAC])
|
||||
@DisplayName("K/N tests with synthetic cocoapods")
|
||||
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_0)
|
||||
@NativeGradlePluginTests
|
||||
class CocoaPodsSyntheticIT : KGPBaseTest() {
|
||||
|
||||
override val defaultBuildOptions = super.defaultBuildOptions.copy(
|
||||
nativeOptions = super.defaultBuildOptions.nativeOptions.copy(
|
||||
cocoapodsGenerateWrapper = true
|
||||
)
|
||||
)
|
||||
|
||||
private val cocoapodsSingleKtPod = "native-cocoapods-single"
|
||||
private val templateProjectName = "native-cocoapods-template"
|
||||
|
||||
private val defaultPodInstallSyntheticTaskName = ":podInstallSyntheticIos"
|
||||
|
||||
private val environmentVariables = EnvironmentalVariables(cocoaPodsEnvironmentVariables())
|
||||
|
||||
@BeforeAll
|
||||
fun setUp() {
|
||||
ensureCocoapodsInstalled()
|
||||
}
|
||||
|
||||
@DisplayName("Synthetic project podfile generation")
|
||||
@GradleTest
|
||||
fun testSyntheticProjectPodfileGeneration(gradleVersion: GradleVersion) {
|
||||
nativeProject(cocoapodsSingleKtPod, gradleVersion, environmentVariables = environmentVariables) {
|
||||
buildGradleKts.addCocoapodsBlock(
|
||||
"""
|
||||
ios.deploymentTarget = "14.1"
|
||||
pod("SSZipArchive")
|
||||
pod("AFNetworking", "~> 4.0.1")
|
||||
pod("Alamofire") {
|
||||
source = git("https://github.com/Alamofire/Alamofire.git") {
|
||||
tag = "5.6.1"
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
build(defaultPodInstallSyntheticTaskName) {
|
||||
assertTasksExecuted(":podGenIos")
|
||||
|
||||
val podfile = "build/cocoapods/synthetic/ios/Podfile"
|
||||
assertFileInProjectContains(
|
||||
podfile,
|
||||
"platform :ios, '14.1'",
|
||||
"pod 'SSZipArchive'",
|
||||
"pod 'AFNetworking', '~> 4.0.1'",
|
||||
"pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '5.6.1'",
|
||||
"config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = \"\"",
|
||||
"config.build_settings['CODE_SIGNING_REQUIRED'] = \"NO\"",
|
||||
"config.build_settings['CODE_SIGNING_ALLOWED'] = \"NO\""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Synthetic project podfile postprocessing")
|
||||
@GradleTest
|
||||
fun testSyntheticProjectPodfilePostprocessing(gradleVersion: GradleVersion) {
|
||||
nativeProject(templateProjectName, gradleVersion, environmentVariables = environmentVariables) {
|
||||
preparePodfile("ios-app", ImportMode.FRAMEWORKS)
|
||||
buildGradleKts.addCocoapodsBlock("""pod("ChatSDK", version = "5.2.1")""")
|
||||
buildGradleKts.appendText(
|
||||
"""
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.targets.native.tasks.PodGenTask>().configureEach {
|
||||
doLast {
|
||||
podfile.get().appendText("ENV['SWIFT_VERSION'] = '5'")
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build(defaultPodInstallSyntheticTaskName) {
|
||||
assertFileInProjectContains("build/cocoapods/synthetic/ios/Podfile", "ENV['SWIFT_VERSION'] = '5'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Reinstalling pod invalidates UTD")
|
||||
@GradleTest
|
||||
fun testPodInstallInvalidatesUTD(gradleVersion: GradleVersion) {
|
||||
nativeProject(templateProjectName, gradleVersion, environmentVariables = environmentVariables) {
|
||||
preparePodfile("ios-app", ImportMode.FRAMEWORKS)
|
||||
buildGradleKts.addPod("AFNetworking")
|
||||
|
||||
build(defaultPodInstallSyntheticTaskName) {
|
||||
assertTasksExecuted(defaultPodInstallSyntheticTaskName)
|
||||
assertTrue { projectPath.resolve("build/cocoapods/synthetic/ios/Pods/AFNetworking").toFile().deleteRecursively() }
|
||||
}
|
||||
|
||||
build(defaultPodInstallSyntheticTaskName) {
|
||||
assertTasksExecuted(defaultPodInstallSyntheticTaskName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -76,6 +76,7 @@ data class BuildOptions(
|
||||
val platformLibrariesMode: String? = null,
|
||||
val reinstall: Boolean? = null,
|
||||
val restrictedDistribution: Boolean? = null,
|
||||
val useXcodeMessageStyle: Boolean? = null,
|
||||
val version: String? = null,
|
||||
)
|
||||
|
||||
@@ -227,6 +228,9 @@ data class BuildOptions(
|
||||
nativeOptions.restrictedDistribution?.let {
|
||||
arguments.add("-Pkotlin.native.restrictedDistribution=${it}")
|
||||
}
|
||||
nativeOptions.useXcodeMessageStyle?.let {
|
||||
arguments.add("-Pkotlin.native.useXcodeMessageStyle=${it}")
|
||||
}
|
||||
nativeOptions.version?.let {
|
||||
arguments.add("-Pkotlin.native.version=${it}")
|
||||
}
|
||||
|
||||
+41
-2
@@ -5,15 +5,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.testbase
|
||||
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.BaseGradleIT
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_BUILD_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_INSTALL_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_SETUP_BUILD_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.util.assertProcessRunResult
|
||||
import org.jetbrains.kotlin.gradle.util.replaceText
|
||||
import org.jetbrains.kotlin.gradle.util.runProcess
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.*
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
|
||||
val String.normalizeCocoapadsFrameworkName: String
|
||||
@@ -204,8 +210,37 @@ fun KGPBaseTest.nativeProjectWithCocoapodsAndIosAppPodFile(
|
||||
}
|
||||
}
|
||||
|
||||
fun BuildResult.podImportAsserts(
|
||||
buildScript: Path,
|
||||
projectName: String? = null,
|
||||
) {
|
||||
|
||||
val buildScriptText = buildScript.readText()
|
||||
val taskPrefix = projectName?.let { ":$it" } ?: ""
|
||||
val podspec = "podspec"
|
||||
|
||||
if ("noPodspec()" in buildScriptText) {
|
||||
assertTasksSkipped("$taskPrefix:$podspec")
|
||||
}
|
||||
|
||||
if ("podfile" in buildScriptText) {
|
||||
assertTasksExecuted("$taskPrefix$podInstallTaskName")
|
||||
} else {
|
||||
assertTasksSkipped("$taskPrefix$podInstallTaskName")
|
||||
}
|
||||
if (buildScriptText.matches("pod\\(.*\\)".toRegex())) {
|
||||
assertTasksExecuted(listOf("$taskPrefix:${KotlinCocoapodsPlugin.POD_GEN_TASK_NAME}"))
|
||||
}
|
||||
|
||||
if (buildScriptText.matches("pod\\(.*\\)".toRegex())) {
|
||||
assertTasksExecuted("$taskPrefix:$POD_SETUP_BUILD_TASK_NAME", "$taskPrefix:$POD_BUILD_TASK_NAME")
|
||||
}
|
||||
}
|
||||
|
||||
private val templateProjectName = "native-cocoapods-template"
|
||||
|
||||
private val podInstallTaskName = ":$POD_INSTALL_TASK_NAME"
|
||||
|
||||
private val shouldInstallLocalCocoapods: Boolean = System.getProperty("installCocoapods").toBoolean()
|
||||
private val cocoapodsInstallationRoot: Path by lazy { createTempDirectory("cocoapods") }
|
||||
private val cocoapodsBinPath: Path by lazy { cocoapodsInstallationRoot.resolve("bin") }
|
||||
@@ -228,8 +263,12 @@ private fun gem(vararg args: String): String {
|
||||
val command = listOf("gem", *args)
|
||||
println("Run command: ${command.joinToString(separator = " ")}")
|
||||
val result = runProcess(command, File("."), options = BaseGradleIT.BuildOptions(forceOutputToStdout = true))
|
||||
check(result.isSuccessful) {
|
||||
"Process 'gem ${args.joinToString(separator = " ")}' exited with error code ${result.exitCode}. See log for details."
|
||||
|
||||
assertProcessRunResult(result) {
|
||||
assertTrue(
|
||||
result.isSuccessful,
|
||||
"Process 'gem ${args.joinToString(separator = " ")}' exited with error code ${result.exitCode}. See log for details."
|
||||
)
|
||||
}
|
||||
return result.output
|
||||
}
|
||||
|
||||
+2
-1
@@ -168,9 +168,10 @@ fun BuildResult.assertNativeTasksClasspath(
|
||||
fun TestProject.buildAndAssertAllTasks(
|
||||
registeredTasks: List<String> = emptyList(),
|
||||
notRegisteredTasks: List<String> = emptyList(),
|
||||
buildOptions: BuildOptions = this.buildOptions,
|
||||
environmentVariables: EnvironmentalVariables = EnvironmentalVariables()
|
||||
) {
|
||||
build("tasks", "--all", environmentVariables = environmentVariables) {
|
||||
build("tasks", "--all", buildOptions = buildOptions, environmentVariables = environmentVariables) {
|
||||
assertTasksInBuildOutput(registeredTasks, notRegisteredTasks)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("org.jetbrains.kotlin.multiplatform").version("<pluginMarkerVersion>")
|
||||
id("org.jetbrains.kotlin.native.cocoapods").version("<pluginMarkerVersion>")
|
||||
id("org.jetbrains.kotlin.multiplatform")
|
||||
id("org.jetbrains.kotlin.native.cocoapods")
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "<pluginMarkerVersion>"
|
||||
kotlin("native.cocoapods") version "<pluginMarkerVersion>"
|
||||
kotlin("multiplatform")
|
||||
kotlin("native.cocoapods")
|
||||
}
|
||||
|
||||
group = "org.jetbrains.kotlin.sample.native"
|
||||
|
||||
Reference in New Issue
Block a user