migrated CInteropIdeaSyncIT to junit5 and gradle TestKit

#KT-51553

Co-authored-by: Alexander Likhachev <me@alikhachev.com>

Merge-request: KT-MR-9599
Merged-by: Dmitrii Krasnov <Dmitrii.Krasnov@jetbrains.com>
This commit is contained in:
Dmitrii Krasnov
2023-04-20 09:48:20 +00:00
committed by Space Team
parent 58143a2006
commit c3bfe72394
@@ -1,35 +1,38 @@
/* /*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * 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. * 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 package org.jetbrains.kotlin.gradle.native
import org.jetbrains.kotlin.gradle.BaseGradleIT import org.gradle.util.GradleVersion
import kotlin.test.Test import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.konan.file.File
import org.junit.jupiter.api.DisplayName
import kotlin.io.path.writeText
class CInteropIdeaSyncIT : BaseGradleIT() { @DisplayName("Tests for the K/N CInterop tool during IDEA project import")
@NativeGradlePluginTests
class CInteropIdeaSyncIT : KGPBaseTest() {
private val ideaSyncBuildOptions = defaultBuildOptions().copy( private val ideaSyncBuildOptions = defaultBuildOptions.copy(freeArgs = listOf("-Didea.sync.active=true"))
freeCommandLineArgs = listOf("-Didea.sync.active=true")
)
@Test @DisplayName("Idea sync warning failing cinterop warning")
fun `test failing cinterop warning`() { @GradleTest
fun shouldPrintWarningForCInteroperability(gradleVersion: GradleVersion) {
val ideaSyncWarningMessage = "Warning: Failed to generate cinterop for :cinteropSampleInteropNative" val ideaSyncWarningMessage = "Warning: Failed to generate cinterop for :cinteropSampleInteropNative"
val interopTaskName = ":cinteropSampleInteropNative" val interopTaskName = ":cinteropSampleInteropNative"
with(Project("cinterop-failing")) { nativeProject("cinterop-failing", gradleVersion) {
/* Task still fails on 'normal' builds */ /* Task still fails on 'normal' builds */
build("commonize") { buildAndFail("commonize") {
assertTasksFailed(interopTaskName) assertTasksFailed(interopTaskName)
} }
/* Task failure is just a warning during import */ /* Task failure is just a warning during import */
build("commonize", options = ideaSyncBuildOptions) { build("commonize", buildOptions = ideaSyncBuildOptions) {
assertSuccessful()
assertTasksExecuted(interopTaskName) assertTasksExecuted(interopTaskName)
assertContains(ideaSyncWarningMessage) assertOutputContains(ideaSyncWarningMessage)
} }
/* /*
@@ -46,35 +49,31 @@ class CInteropIdeaSyncIT : BaseGradleIT() {
*/ */
runCatching { runCatching {
/* Task is not considered up-to-date after lenient failure */ /* Task is not considered up-to-date after lenient failure */
build("commonize", options = ideaSyncBuildOptions) { build("commonize", buildOptions = ideaSyncBuildOptions) {
assertSuccessful()
assertTasksExecuted(interopTaskName) assertTasksExecuted(interopTaskName)
assertContains(ideaSyncWarningMessage) assertOutputContains(ideaSyncWarningMessage)
} }
} }
/* Remove noise that causes failure */ /* Remove noise that causes failure */
projectDir.resolve("src/nativeInterop/cinterop/sampleInteropNoise.h").writeText("") projectPath.resolve("src/nativeInterop/cinterop/sampleInteropNoise.h").writeText("")
build("commonize", options = ideaSyncBuildOptions) { build("commonize", buildOptions = ideaSyncBuildOptions) {
assertSuccessful()
assertTasksExecuted(interopTaskName) assertTasksExecuted(interopTaskName)
assertNotContains(ideaSyncWarningMessage) assertOutputDoesNotContain(ideaSyncWarningMessage)
} }
/* Task is considered up-to-date after first successful run */ /* Task is considered up-to-date after first successful run */
build("commonize", options = ideaSyncBuildOptions) { build("commonize", buildOptions = ideaSyncBuildOptions) {
assertSuccessful()
assertTasksUpToDate(interopTaskName) assertTasksUpToDate(interopTaskName)
assertNotContains(ideaSyncWarningMessage) assertOutputDoesNotContain(ideaSyncWarningMessage)
} }
/* Task is still considered up-to-date after successful run in idea sync */ /* Task is still considered up-to-date after successful run in idea sync */
build("commonize") { build("commonize") {
assertSuccessful()
assertTasksUpToDate(interopTaskName) assertTasksUpToDate(interopTaskName)
assertNotContains(ideaSyncWarningMessage) assertOutputDoesNotContain(ideaSyncWarningMessage)
} }
} }
} }
} }