Skip to content

Commit

Permalink
Added a test that reproduces the plugin order problem.
Browse files Browse the repository at this point in the history
Fixes #384
  • Loading branch information
mvicsokolova committed Dec 20, 2023
1 parent 520d81c commit b43d4aa
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 6 deletions.
52 changes: 52 additions & 0 deletions integration-testing/examples/plugin-order-bug/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}

dependencies {
// If the order of adding atomicfu-gradle-plugin and kotlin-gradle-pluin to the classpath is changed,
// then atomicfu dependency is not added to the classpath
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlinVersion.get()}")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${libs.versions.atomicfuVersion.get()}")
classpath("org.jetbrains.kotlin:atomicfu:${libs.versions.kotlinVersion.get()}")
}
}

apply plugin: 'org.jetbrains.kotlin.multiplatform'
// The issue is described in #384. Application of kotlin-gradle-plugin by id fixes the compilation error.
//plugins {
// id 'org.jetbrains.kotlin.multiplatform' version '1.9.21'
//}
apply plugin: 'kotlinx-atomicfu'

repositories {
mavenCentral()
maven{ url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
mavenLocal()
}

kotlin {
jvm()

js()

wasmJs {}
wasmWasi {}

macosArm64()
macosX64()
linuxArm64()
linuxX64()
mingwX64()

sourceSets {
commonMain {
dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("test-junit"))
}
}
commonTest {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##
## Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
##
kotlin_version=1.9.21
atomicfu_version=0.23.1-SNAPSHOT
19 changes: 19 additions & 0 deletions integration-testing/examples/plugin-order-bug/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
gradlePluginPortal()
}
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
version("atomicfuVersion", providers.gradleProperty("atomicfu_version").orNull)
version("kotlinVersion", providers.gradleProperty("kotlin_version").orNull)
}
}
}

rootProject.name = "plugin-order-bug"
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package examples.mpp_sample

import kotlinx.atomicfu.*
import kotlinx.atomicfu.locks.*
import kotlin.test.*

public class AtomicSampleClass {
private val _x = atomic(0)
val x get() = _x.value

public fun doWork(finalValue: Int) {
assertEquals(0, x)
assertEquals(0, _x.getAndSet(3))
assertEquals(3, x)
assertTrue(_x.compareAndSet(3, finalValue))
}

private val lock = reentrantLock()

public fun synchronizedFoo(value: Int): Int {
return lock.withLock { value }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import kotlin.test.*
import examples.mpp_sample.*

class AtomicSampleTest {

@Test
fun testInt() {
val a = AtomicSampleClass()
a.doWork(1234)
assertEquals(1234, a.x)
assertEquals(42, a.synchronizedFoo(42))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package kotlinx.atomicfu.gradle.plugin.test.cases

import kotlinx.atomicfu.gradle.plugin.test.framework.runner.*
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.GradleBuild
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.cleanAndBuild
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.createGradleBuildFromSources
import kotlin.test.*

/**
* This test reproduces and tracks the issue #384.
*/
class PluginOrderBugTest {
private val pluginOrderBugProject: GradleBuild = createGradleBuildFromSources("plugin-order-bug")

@Test
fun testUserProjectBuild() {
val buildResult = pluginOrderBugProject.cleanAndBuild()
assertFalse(buildResult.isSuccessful)
assertTrue(buildResult.output.contains("unresolved reference: kotlinx"), buildResult.output)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ internal class GradleBuild(val projectName: String, val targetDir: File) {

private var runCount = 0

fun runGradle(commands: List<String>): BuildResult =
buildGradleByShell(runCount++, commands, properties).also {
require(it.isSuccessful) { "Running $commands on project $projectName FAILED with error:\n" + it.output }
}
fun runGradle(commands: List<String>): BuildResult = buildGradleByShell(runCount++, commands, properties)
}

internal class BuildResult(exitCode: Int, private val logFile: File) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ package kotlinx.atomicfu.gradle.plugin.test.framework.runner

internal fun GradleBuild.cleanAndBuild(): BuildResult = runGradle(listOf("clean", "build"))

internal fun GradleBuild.dependencies(): BuildResult = runGradle(listOf("dependencies"))
internal fun GradleBuild.dependencies(): BuildResult =
runGradle(listOf("dependencies")).also {
require(it.isSuccessful) { "${this.projectName}:dependencies task FAILED: ${it.output} " }
}

internal fun GradleBuild.publishToLocalRepository(): BuildResult =
runGradle(listOf("clean", "publish"))
runGradle(listOf("clean", "publish")).also {
require(it.isSuccessful) { "${this.projectName}:publish task FAILED: ${it.output} " }
}

0 comments on commit b43d4aa

Please sign in to comment.