Fix failing non-JUnit5 tests.

They have failed due to migration to new plugin api in test projects.

^KT-45744 Fixed
This commit is contained in:
Yahor Berdnikau
2021-03-29 15:05:26 +02:00
committed by TeamCityServer
parent 9ef5817f8b
commit 00df2c4a9e
14 changed files with 174 additions and 25 deletions
@@ -615,7 +615,7 @@ open class Kapt3IT : Kapt3BaseIT() {
val kaptProject = Project("simple", directoryPrefix = "kapt2").apply { setupWorkingDir() } val kaptProject = Project("simple", directoryPrefix = "kapt2").apply { setupWorkingDir() }
kaptProject.projectDir.copyRecursively(projectDir.resolve("simple")) kaptProject.projectDir.copyRecursively(projectDir.resolve("simple"))
projectDir.resolve("settings.gradle").writeText("include 'simple'") projectDir.resolve("settings.gradle").appendText("include 'simple'")
gradleBuildScript().appendText("\ndependencies { implementation project(':simple') }") gradleBuildScript().appendText("\ndependencies { implementation project(':simple') }")
testResolveAllConfigurations() testResolveAllConfigurations()
@@ -413,8 +413,10 @@ class KotlinGradleIT : BaseGradleIT() {
val project = Project("kotlinProject") val project = Project("kotlinProject")
project.setupWorkingDir() project.setupWorkingDir()
File(project.projectDir, "build.gradle").modify { File(project.projectDir, "build.gradle").modify {
it.replace("kotlin-stdlib:\$kotlin_version", "kotlin-stdlib").apply { check(!equals(it)) } + "\n" + """ """
apply plugin: 'maven-publish' $it
plugins.apply('maven-publish')
group = "com.example" group = "com.example"
version = "1.0" version = "1.0"
@@ -442,7 +444,7 @@ class KotlinGradleIT : BaseGradleIT() {
assertSuccessful() assertSuccessful()
assertTasksExecuted(":compileKotlin", ":compileTestKotlin") assertTasksExecuted(":compileKotlin", ":compileTestKotlin")
val pomLines = File(project.projectDir, "build/publications/myLibrary/pom-default.xml").readLines() val pomLines = File(project.projectDir, "build/publications/myLibrary/pom-default.xml").readLines()
val stdlibVersionLineNumber = pomLines.indexOfFirst { "<artifactId>kotlin-stdlib</artifactId>" in it } + 1 val stdlibVersionLineNumber = pomLines.indexOfFirst { "<artifactId>kotlin-stdlib-jdk8</artifactId>" in it } + 1
val versionLine = pomLines[stdlibVersionLineNumber] val versionLine = pomLines[stdlibVersionLineNumber]
assertTrue { "<version>${defaultBuildOptions().kotlinVersion}</version>" in versionLine } assertTrue { "<version>${defaultBuildOptions().kotlinVersion}</version>" in versionLine }
} }
@@ -1116,14 +1118,16 @@ class KotlinGradleIT : BaseGradleIT() {
} }
@Test @Test
fun testLoadCompilerEmbeddableAfterOtherKotlinArtifacts() = with(Project("simpleProject")) { fun testLoadCompilerEmbeddableAfterOtherKotlinArtifacts() = with(Project("simpleProjectClasspath")) {
setupWorkingDir() setupWorkingDir()
val buildscriptClasspathPrefix = "buildscript-classpath = " val buildscriptClasspathPrefix = "buildscript-classpath = "
gradleBuildScript().appendText( gradleBuildScript()
"\n" + """ .appendText(
"""
println "$buildscriptClasspathPrefix" + Arrays.toString(buildscript.classLoader.getURLs()) println "$buildscriptClasspathPrefix" + Arrays.toString(buildscript.classLoader.getURLs())
""".trimIndent() """.trimIndent()
) )
// get the classpath, then reorder it so that kotlin-compiler-embeddable is loaded after all other JARs // get the classpath, then reorder it so that kotlin-compiler-embeddable is loaded after all other JARs
lateinit var classpath: List<String> lateinit var classpath: List<String>
@@ -256,22 +256,24 @@ class KotlinSpecificDependenciesIT : BaseGradleIT() {
@Test @Test
fun testNoFailureIfConfigurationIsObserved() = with(jvmProject()) { fun testNoFailureIfConfigurationIsObserved() = with(jvmProject()) {
lateinit var originalScript: String gradleBuildScript().modify {
try { //language=Groovy
gradleBuildScript().modify { """
originalScript = it $it
"""
configurations.create("api") configurations {
dependencies { apiTest
api("org.jetbrains.kotlin:kotlin-reflect") api.extendsFrom(apiTest)
}
println(configurations.api.incoming.dependencies.toList())
""".trimIndent() + "\n" + it
} }
checkTaskCompileClasspath("compileKotlin", listOf("kotlin-reflect"))
} finally { dependencies {
gradleBuildScript().writeText(originalScript) apiTest("org.jetbrains.kotlin:kotlin-reflect")
}
println(configurations.apiTest.incoming.resolutionResult.allDependencies)
println(configurations.apiTest.incoming.dependencies.toList())
""".trimIndent()
} }
checkTaskCompileClasspath("compileKotlin", listOf("kotlin-reflect"))
} }
private fun Project.checkConfigurationContent( private fun Project.checkConfigurationContent(
@@ -115,8 +115,7 @@ class UpToDateIT : BaseGradleIT() {
override fun initProject(project: Project) = with(project) { override fun initProject(project: Project) = with(project) {
buildGradle.appendText( buildGradle.appendText(
"\n" + """ "\n" + """
buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-allopen:${'$'}kotlin_version" } } plugins.apply("org.jetbrains.kotlin.plugin.allopen")
apply plugin: "kotlin-allopen"
allOpen { annotation("allopen.Foo"); annotation("allopen.Bar") } allOpen { annotation("allopen.Foo"); annotation("allopen.Bar") }
""".trimIndent() """.trimIndent()
) )
@@ -0,0 +1,10 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
}
plugins {
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
}
}
@@ -1,5 +1,6 @@
plugins { plugins {
id "org.jetbrains.kotlin.jvm" id "org.jetbrains.kotlin.jvm"
id "org.jetbrains.kotlin.plugin.allopen" apply false
} }
repositories { repositories {
@@ -4,9 +4,11 @@ pluginManagement {
repositories { repositories {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
gradlePluginPortal()
} }
plugins { plugins {
id "org.jetbrains.kotlin.jvm" version "$kotlin_version" id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
id "org.jetbrains.kotlin.plugin.allopen" version "$kotlin_version"
} }
} }
@@ -0,0 +1,10 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
}
plugins {
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
}
}
@@ -0,0 +1,33 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
apply plugin: "java"
sourceSets {
deploy
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'com.google.guava:guava:12.0'
deployImplementation 'com.google.guava:guava:12.0'
testImplementation 'org.testng:testng:6.8'
implementation "org.jetbrains.kotlin:kotlin-stdlib"
deployImplementation "org.jetbrains.kotlin:kotlin-stdlib"
}
test {
useTestNG()
}
@@ -0,0 +1,12 @@
package demo
import com.google.common.primitives.Ints
import com.google.common.base.Joiner
class ExampleSource(param : Int) {
val property = param
fun f() : String? {
return "Hello World"
}
}
@@ -0,0 +1,17 @@
package demo;
/**
* Created by Nikita.Skvortsov
* Date: 3/1/13, 10:53 AM
*/
public class Greeter {
private final String myGreeting;
public Greeter(String greeting) {
myGreeting = greeting;
}
public String getGreeting() {
return myGreeting;
}
}
@@ -0,0 +1,18 @@
package demo;
/**
* Created by Nikita.Skvortsov
* Date: 3/1/13, 10:50 AM
*/
public class HelloWorld {
public static void main(String[] args) {
final KotlinGreetingJoiner example = new KotlinGreetingJoiner(new Greeter("Hi"));
example.addName("Harry");
example.addName("Ron");
example.addName(null);
example.addName("Hermione");
System.out.println(example.getJoinedGreeting());
}
}
@@ -0,0 +1,20 @@
package demo
import com.google.common.primitives.Ints
import com.google.common.base.Joiner
import java.util.ArrayList
class KotlinGreetingJoiner(val greeter : Greeter) {
val names = ArrayList<String?>()
fun addName(name : String?): Unit{
names.add(name)
}
fun getJoinedGreeting() : String? {
val joiner = Joiner.on(" and ").skipNulls();
return "${greeter.getGreeting()} ${joiner.join(names)}"
}
}
@@ -0,0 +1,21 @@
package demo
import com.google.common.primitives.Ints
import com.google.common.base.Joiner
import org.testng.Assert.*
import org.testng.annotations.AfterMethod
import org.testng.annotations.BeforeMethod
import org.testng.annotations.Test as test
class TestSource() {
@test fun f() {
val example : KotlinGreetingJoiner = KotlinGreetingJoiner(Greeter("Hi"))
example.addName("Harry")
example.addName("Ron")
example.addName(null)
example.addName("Hermione")
assertEquals(example.getJoinedGreeting(), "Hi Harry and Ron and Hermione")
}
}