From aee5a16fb9bd7eec2f7640c6264ec4436cea3ebb Mon Sep 17 00:00:00 2001 From: Maria Sokolova Date: Thu, 7 Dec 2023 11:20:53 +0100 Subject: [PATCH] Removed old tests for atomicfu-gradle-plugin, they are now replaced with integration-testing --- .../atomicfu/plugin/gradle/internal/Assert.kt | 36 ---- .../plugin/gradle/internal/TestDsl.kt | 145 ---------------- .../atomicfu/plugin/gradle/internal/utils.kt | 13 -- .../gradle/test/BaseKotlinGradleTest.kt | 111 ------------ .../plugin/gradle/test/JvmProjectTest.kt | 108 ------------ .../plugin/gradle/test/MppProjectTest.kt | 162 ------------------ .../projects/jvm-simple/gradle.properties | 1 - .../projects/jvm-simple/jvm-simple.gradle.kts | 47 ----- .../projects/jvm-simple/settings.gradle.kts | 1 - .../src/main/kotlin/IntArithmetic.kt | 23 --- .../src/test/kotlin/ArithmeticTest.kt | 14 -- .../mpp-simple/gradle.properties_both | 3 - .../projects/mpp-simple/gradle.properties_js | 2 - .../mpp-simple/gradle.properties_js_legacy | 1 - .../projects/mpp-simple/gradle.properties_jvm | 2 - .../projects/mpp-simple/mpp-simple.gradle.kts | 91 ---------- .../projects/mpp-simple/settings.gradle.kts | 1 - .../src/commonMain/kotlin/IntArithmetic.kt | 23 --- .../src/commonTest/kotlin/ArithmeticTest.kt | 14 -- 19 files changed, 798 deletions(-) delete mode 100644 atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/Assert.kt delete mode 100644 atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/TestDsl.kt delete mode 100644 atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/utils.kt delete mode 100644 atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/BaseKotlinGradleTest.kt delete mode 100644 atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/JvmProjectTest.kt delete mode 100644 atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/MppProjectTest.kt delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/gradle.properties delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/jvm-simple.gradle.kts delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/settings.gradle.kts delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/src/main/kotlin/IntArithmetic.kt delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/src/test/kotlin/ArithmeticTest.kt delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_both delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_js delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_js_legacy delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_jvm delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/mpp-simple.gradle.kts delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/settings.gradle.kts delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/src/commonMain/kotlin/IntArithmetic.kt delete mode 100644 atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/src/commonTest/kotlin/ArithmeticTest.kt diff --git a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/Assert.kt b/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/Assert.kt deleted file mode 100644 index 191dbac0..00000000 --- a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/Assert.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2016-2022 JetBrains s.r.o. - * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. - */ - -package kotlinx.atomicfu.plugin.gradle.internal - -import org.gradle.testkit.runner.BuildResult -import org.gradle.testkit.runner.TaskOutcome -import kotlin.test.assertEquals - -/** - * Helper `fun` for asserting a [TaskOutcome] to be equal to [TaskOutcome.SUCCESS] - */ -internal fun BuildResult.assertTaskSuccess(task: String) { - assertTaskOutcome(TaskOutcome.SUCCESS, task) -} - -/** - * Helper `fun` for asserting a [TaskOutcome] to be equal to [TaskOutcome.FAILED] - */ -internal fun BuildResult.assertTaskFailure(task: String) { - assertTaskOutcome(TaskOutcome.FAILED, task) -} - -internal fun BuildResult.assertTaskUpToDate(task: String) { - assertTaskOutcome(TaskOutcome.UP_TO_DATE, task) -} - -private fun BuildResult.assertTaskOutcome(taskOutcome: TaskOutcome, taskName: String) { - assertEquals( - taskOutcome, - task(taskName)?.outcome, - "Task $taskName does not have ${taskOutcome.name} outcome" - ) -} diff --git a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/TestDsl.kt b/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/TestDsl.kt deleted file mode 100644 index ed11b10e..00000000 --- a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/TestDsl.kt +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2016-2022 JetBrains s.r.o. - * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. - */ - -package kotlinx.atomicfu.plugin.gradle.internal - -import kotlinx.atomicfu.plugin.gradle.test.* -import org.gradle.testkit.runner.* -import java.io.* - -internal fun BaseKotlinGradleTest.test(fn: BaseKotlinScope.() -> Unit): GradleRunner { - val baseKotlinScope = BaseKotlinScope() - fn(baseKotlinScope) - - baseKotlinScope.files.forEach { scope -> - val fileWriteTo = rootProjectDir.resolve(scope.filePath) - .apply { - parentFile.mkdirs() - createNewFile() - } - - scope.files.forEach { - val fileContent = readFileList(it) - fileWriteTo.appendText(fileContent) - } - } - - return GradleRunner.create() - .withProjectDir(rootProjectDir) - .withArguments(baseKotlinScope.runner.arguments) - .withPluginClasspath() - .addPluginTestRuntimeClasspath() -} - -/** - * same as [file][FileContainer.file], but prepends "src/${sourceSet}/kotlin" before given `classFileName` - */ -internal fun FileContainer.kotlin(classFileName: String, sourceSet: String = "main", fn: AppendableScope.() -> Unit) { - require(classFileName.endsWith(".kt")) { - "ClassFileName must end with '.kt'" - } - - val fileName = "src/${sourceSet}/kotlin/$classFileName" - file(fileName, fn) -} - -/** - * Shortcut for creating a `build.gradle.kts` by using [file][FileContainer.file] - */ -internal fun FileContainer.buildGradleKts(fn: AppendableScope.() -> Unit) { - val fileName = "build.gradle.kts" - file(fileName, fn) -} - -/** - * Shortcut for creating a `settings.gradle.kts` by using [file][FileContainer.file] - */ -internal fun FileContainer.settingsGradleKts(fn: AppendableScope.() -> Unit) { - val fileName = "settings.gradle.kts" - file(fileName, fn) -} - -/** - * Shortcut for creating a `gradle.properties` by using [file][FileContainer.file] - */ -internal fun FileContainer.gradleProperties(fn: AppendableScope.() -> Unit) { - val fileName = "gradle.properties" - file(fileName, fn) -} - -/** - * Declares a directory with the given [dirName] inside the current container. - * All calls creating files within this scope will create the files nested in this directory. - * - * Note that it is valid to call this method multiple times at the same level with the same [dirName]. - * Files declared within 2 independent calls to [dir] will be added to the same directory. - */ -internal fun FileContainer.dir(dirName: String, fn: DirectoryScope.() -> Unit) { - DirectoryScope(dirName, this).fn() -} - -internal fun BaseKotlinScope.runner(fn: Runner.() -> Unit) { - val runner = Runner() - fn(runner) - - this.runner = runner -} - -internal fun AppendableScope.resolve(fileName: String) { - this.files.add(fileName) -} - -internal interface FileContainer { - fun file(fileName: String, fn: AppendableScope.() -> Unit) -} - -internal class BaseKotlinScope : FileContainer { - var files: MutableList = mutableListOf() - var runner: Runner = Runner() - - override fun file(fileName: String, fn: AppendableScope.() -> Unit) { - val appendableScope = AppendableScope(fileName) - fn(appendableScope) - files.add(appendableScope) - } -} - -internal class DirectoryScope( - val dirPath: String, - val parent: FileContainer -): FileContainer { - - override fun file(fileName: String, fn: AppendableScope.() -> Unit) { - parent.file("$dirPath/$fileName", fn) - } -} - -internal class AppendableScope(val filePath: String) { - val files: MutableList = mutableListOf() -} - -internal class Runner { - val arguments: MutableList = mutableListOf() -} - -internal fun readFileList(fileName: String): String = - getFile(fileName).readText() - -internal fun getFileOrNull(fileName: String): File? { - return BaseKotlinGradleTest::class.java.classLoader.getResource(fileName)?.let { - resource -> File(resource.toURI()) - } -} - -internal fun getFile(fileName: String): File { - val resource = BaseKotlinGradleTest::class.java.classLoader.getResource(fileName) - ?: throw IllegalStateException("Could not find resource '$fileName'") - return File(resource.toURI()) -} - -internal fun GradleRunner.addPluginTestRuntimeClasspath() = apply { - val pluginClasspath = getFile("plugin-classpath.txt").readLines().map { File(it) } - withPluginClasspath(pluginClasspath) -} diff --git a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/utils.kt b/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/utils.kt deleted file mode 100644 index 49856f2f..00000000 --- a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/internal/utils.kt +++ /dev/null @@ -1,13 +0,0 @@ -package kotlinx.atomicfu.plugin.gradle.internal - -import java.io.* -import kotlin.test.* - -fun File.checkExists() { - assertTrue(exists(), "File does not exist: $canonicalPath") -} - -fun File.filesFrom(relative: String) = resolve(relative) - .readLines().asSequence().flatMap { listFiles(it) }.toHashSet() - -fun listFiles(dir: String): Sequence = File(dir).walk().filter { it.isFile } \ No newline at end of file diff --git a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/BaseKotlinGradleTest.kt b/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/BaseKotlinGradleTest.kt deleted file mode 100644 index 7ae5bdc8..00000000 --- a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/BaseKotlinGradleTest.kt +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.atomicfu.plugin.gradle.test - -import kotlinx.atomicfu.plugin.gradle.internal.* -import org.objectweb.asm.* -import java.io.File -import kotlin.test.* - -abstract class BaseKotlinGradleTest(private val projectName: String) { - internal val rootProjectDir: File - private val ATOMIC_FU_REF = "Lkotlinx/atomicfu/".toByteArray() - private val KOTLIN_METADATA_DESC = "Lkotlin/Metadata;" - - init { - rootProjectDir = File("build${File.separator}test-$projectName").absoluteFile - rootProjectDir.deleteRecursively() - rootProjectDir.mkdirs() - } - - internal abstract fun BaseKotlinScope.createProject() - - val runner = test { - createProject() - runner { - arguments.add(":build") - getFileOrNull("kotlin-repo-url.txt")?.let { kotlinRepoURLResource -> - arguments.add("-Pkotlin_repo_url=${kotlinRepoURLResource.readText()}") - } - } - } - - fun checkTaskOutcomes(executedTasks: List, excludedTasks: List) { - runner.build().apply { - val tasks = tasks.map { it.path } - excludedTasks.forEach { - check(it !in tasks) { "Post-compilation transformation task $it was added in the compiler plugin mode" } - } - executedTasks.forEach { - assertTaskSuccess(it) - } - } - // check that task outcomes are cached for the second build - runner.build().apply { - executedTasks.forEach { - assertTaskUpToDate(it) - } - } - } - - fun checkJvmCompilationClasspath(originalClassFile: String, transformedClassFile: String) { - // check that test compile and runtime classpath does not contain original non-transformed classes - val testCompileClasspathFiles = rootProjectDir.filesFrom("build/test_compile_jvm_classpath.txt") - val testRuntimeClasspathFiles = rootProjectDir.filesFrom("build/test_runtime_jvm_classpath.txt") - - rootProjectDir.resolve(transformedClassFile).let { - it.checkExists() - check(it in testCompileClasspathFiles) { "Transformed '$it' is missing from test compile classpath" } - check(it in testRuntimeClasspathFiles) { "Transformed '$it' is missing from test runtime classpath" } - } - - rootProjectDir.resolve(originalClassFile).let { - it.checkExists() - check(it !in testCompileClasspathFiles) { "Original '$it' is present in test compile classpath" } - check(it !in testRuntimeClasspathFiles) { "Original '$it' is present in test runtime classpath" } - } - } - - fun checkJsCompilationClasspath() { - // check that test compilation depends on transformed main sources - val testCompileClasspathFiles = rootProjectDir.filesFrom("build/test_compile_js_classpath.txt") - - rootProjectDir.resolve("build/classes/atomicfu/js/main/$projectName.js").let { - it.checkExists() - check(it in testCompileClasspathFiles) { "Transformed '$it' is missing from test compile classpath" } - } - } - - fun checkBytecode(classFilePath: String) { - rootProjectDir.resolve(classFilePath).let { - it.checkExists() - assertFalse(it.readBytes().findAtomicfuRef(), "Found 'Lkotlinx/atomicfu/' reference in $it" ) - } - } - - private fun ByteArray.findAtomicfuRef(): Boolean { - val bytes = this.eraseMetadata() - loop@for (i in 0 until bytes.size - ATOMIC_FU_REF.size) { - for (j in 0 until ATOMIC_FU_REF.size) { - if (bytes[i + j] != ATOMIC_FU_REF[j]) continue@loop - } - return true - } - return false - } - - // The atomicfu compiler plugin does not remove atomic properties from metadata, - // so for now we check that there are no ATOMIC_FU_REF left in the class bytecode excluding metadata. - // This may be reverted after the fix in the compiler plugin transformer (See #254). - private fun ByteArray.eraseMetadata(): ByteArray { - val cw = ClassWriter(ClassWriter.COMPUTE_MAXS or ClassWriter.COMPUTE_FRAMES) - ClassReader(this).accept(object : ClassVisitor(Opcodes.ASM9, cw) { - override fun visitAnnotation(descriptor: String?, visible: Boolean): AnnotationVisitor? { - return if (descriptor == KOTLIN_METADATA_DESC) null else super.visitAnnotation(descriptor, visible) - } - }, ClassReader.SKIP_FRAMES) - return cw.toByteArray() - } -} diff --git a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/JvmProjectTest.kt b/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/JvmProjectTest.kt deleted file mode 100644 index 282df802..00000000 --- a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/JvmProjectTest.kt +++ /dev/null @@ -1,108 +0,0 @@ -package kotlinx.atomicfu.plugin.gradle.test - -import kotlinx.atomicfu.plugin.gradle.internal.* -import kotlinx.atomicfu.plugin.gradle.internal.BaseKotlinScope -import org.junit.Test - -/** - * Test that ensures correctness of `atomicfu-gradle-plugin` application to the JVM project: - * - post-compilation bytecode transformation tasks are created - * (legacy transformation is tested here, compiler plugin is not applied). - * - original non-transformed classes are not left in compile/runtime classpath. - * - no `kotlinx/atomicfu` references are left in the transformed bytecode. - */ -class JvmLegacyTransformationTest : BaseKotlinGradleTest("jvm-simple") { - - override fun BaseKotlinScope.createProject() { - buildGradleKts { - resolve("projects/jvm-simple/jvm-simple.gradle.kts") - } - settingsGradleKts { - resolve("projects/jvm-simple/settings.gradle.kts") - } - dir("src/main/kotlin") {} - kotlin("IntArithmetic.kt", "main") { - resolve("projects/jvm-simple/src/main/kotlin/IntArithmetic.kt") - } - dir("src/test/kotlin") {} - kotlin("ArithmeticTest.kt", "test") { - resolve("projects/jvm-simple/src/test/kotlin/ArithmeticTest.kt") - } - } - - @Test - fun testPluginApplication() = - checkTaskOutcomes( - executedTasks = listOf( - ":compileKotlin", - ":transformMainAtomicfu", - ":compileTestKotlin", - ":transformTestAtomicfu" - ), - excludedTasks = emptyList() - ) - - @Test - fun testClasspath() { - runner.build() - checkJvmCompilationClasspath( - originalClassFile = "build/classes/atomicfu-orig/main/IntArithmetic.class", - transformedClassFile = "build/classes/atomicfu/main/IntArithmetic.class" - ) - } - - @Test - fun testAtomicfuReferences() { - runner.build() - checkBytecode("build/classes/atomicfu/main/IntArithmetic.class") - } -} - -/** - * Test that ensures correctness of `atomicfu-gradle-plugin` application to the JVM project, - * - JVM IR compiler plugin transformation (kotlinx.atomicfu.enableJvmIrTransformation=true) - * - no post-compilation bytecode transforming tasks created - * - no `kotlinx/atomicfu` references are left in the resulting bytecode after IR transformation. - */ -class JvmIrTransformationTest : BaseKotlinGradleTest("jvm-simple") { - - override fun BaseKotlinScope.createProject() { - buildGradleKts { - resolve("projects/jvm-simple/jvm-simple.gradle.kts") - } - settingsGradleKts { - resolve("projects/jvm-simple/settings.gradle.kts") - } - // set kotlinx.atomicfu.enableJvmIrTransformation=true to apply compiler plugin - gradleProperties { - resolve("projects/jvm-simple/gradle.properties") - } - dir("src/main/kotlin") {} - kotlin("IntArithmetic.kt", "main") { - resolve("projects/jvm-simple/src/main/kotlin/IntArithmetic.kt") - } - dir("src/test/kotlin") {} - kotlin("ArithmeticTest.kt", "test") { - resolve("projects/jvm-simple/src/test/kotlin/ArithmeticTest.kt") - } - } - - @Test - fun testPluginApplication() = - checkTaskOutcomes( - executedTasks = listOf( - ":compileKotlin", - ":compileTestKotlin" - ), - excludedTasks = listOf( - ":transformAtomicfu", - ":transformTestAtomicfu" - ) - ) - - @Test - fun testAtomicfuReferences() { - runner.build() - checkBytecode("build/classes/kotlin/main/IntArithmetic.class") - } -} diff --git a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/MppProjectTest.kt b/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/MppProjectTest.kt deleted file mode 100644 index 3e1f6085..00000000 --- a/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/MppProjectTest.kt +++ /dev/null @@ -1,162 +0,0 @@ -package kotlinx.atomicfu.plugin.gradle.test - -import kotlinx.atomicfu.plugin.gradle.internal.* -import org.junit.* - -/** - * Test that ensures correctness of `atomicfu-gradle-plugin` application to the MPP project, - * - JVM IR compiler plugin transformation (kotlinx.atomicfu.enableJvmIrTransformation=true) - * - no post-compilation bytecode transformation tasks are created - * - post-compilation js file transformation task created (as only JVM IR transformation applied, js is transformed in legacy mode) - * - no `kotlinx/atomicfu` references are left in the transformed bytecode. - */ -class MppJvmIrTransformationTest : BaseKotlinGradleTest("mpp-simple") { - - override fun BaseKotlinScope.createProject() { - buildGradleKts { - resolve("projects/mpp-simple/mpp-simple.gradle.kts") - } - settingsGradleKts { - resolve("projects/mpp-simple/settings.gradle.kts") - } - gradleProperties { - resolve("projects/mpp-simple/gradle.properties_jvm") - } - dir("src/commonMain/kotlin") {} - kotlin("IntArithmetic.kt", "commonMain") { - resolve("projects/mpp-simple/src/commonMain/kotlin/IntArithmetic.kt") - } - dir("src/commonTest/kotlin") {} - kotlin("ArithmeticTest.kt", "commonTest") { - resolve("projects/mpp-simple/src/commonTest/kotlin/ArithmeticTest.kt") - } - } - - @Test - fun testPluginApplication() = - checkTaskOutcomes( - executedTasks = listOf( - ":compileKotlinJvm", - ":compileTestKotlinJvm", - ":compileKotlinJs", - // legacy JS transformation - ":transformJsMainAtomicfu", - ":transformJsTestAtomicfu" - ), - excludedTasks = listOf( - ":transformJvmMainAtomicfu", - ":transformJvmTestAtomicfu" - ) - ) - - @Test - fun testAtomicfuReferences() { - runner.build() - checkBytecode("build/classes/kotlin/jvm/main/IntArithmetic.class") - } -} - -/** - * Test that ensures correctness of `atomicfu-gradle-plugin` application to the MPP project, - * - JS IR compiler plugin transformation (kotlinx.atomicfu.enableJsIrTransformation=true) - * - post-compilation bytecode transformation tasks are created (only JS IR transformation is applied, jvm is transformed in legacy mode) - * - no post-compilation js file transformation tasks are created - * - no `kotlinx/atomicfu` references are left in the transformed bytecode. - */ -class MppJsIrTransformationTest : BaseKotlinGradleTest("mpp-simple") { - - override fun BaseKotlinScope.createProject() { - buildGradleKts { - resolve("projects/mpp-simple/mpp-simple.gradle.kts") - } - settingsGradleKts { - resolve("projects/mpp-simple/settings.gradle.kts") - } - gradleProperties { - resolve("projects/mpp-simple/gradle.properties_js") - } - dir("src/commonMain/kotlin") {} - kotlin("IntArithmetic.kt", "commonMain") { - resolve("projects/mpp-simple/src/commonMain/kotlin/IntArithmetic.kt") - } - dir("src/commonTest/kotlin") {} - kotlin("ArithmeticTest.kt", "commonTest") { - resolve("projects/mpp-simple/src/commonTest/kotlin/ArithmeticTest.kt") - } - } - - @Test - fun testPluginApplication() = - checkTaskOutcomes( - executedTasks = listOf( - ":compileKotlinJvm", - ":compileTestKotlinJvm", - ":compileKotlinJs", - // legacy JVM transformation - ":transformJvmMainAtomicfu", - ":transformJvmTestAtomicfu" - ), - excludedTasks = listOf( - ":transformJsMainAtomicfu", - ":transformJsTestAtomicfu" - ) - ) - - @Test - fun testAtomicfuReferences() { - runner.build() - checkBytecode("build/classes/atomicfu/jvm/main/IntArithmetic.class") - } -} - -/** - * Test that ensures correctness of `atomicfu-gradle-plugin` application to the MPP project, - * - JS IR and JVM IR compiler plugin transformation - * - no post-compilation bytecode transformation tasks are created (only JS IR transformation is applied, jvm is transformed in legacy mode) - * - no post-compilation js file transformation tasks are created - * - no `kotlinx/atomicfu` references are left in the transformed bytecode. - */ -class MppBothIrTransformationTest : BaseKotlinGradleTest("mpp-simple") { - - override fun BaseKotlinScope.createProject() { - buildGradleKts { - resolve("projects/mpp-simple/mpp-simple.gradle.kts") - } - settingsGradleKts { - resolve("projects/mpp-simple/settings.gradle.kts") - } - gradleProperties { - resolve("projects/mpp-simple/gradle.properties_both") - } - dir("src/commonMain/kotlin") {} - kotlin("IntArithmetic.kt", "commonMain") { - resolve("projects/mpp-simple/src/commonMain/kotlin/IntArithmetic.kt") - } - dir("src/commonTest/kotlin") {} - kotlin("ArithmeticTest.kt", "commonTest") { - resolve("projects/mpp-simple/src/commonTest/kotlin/ArithmeticTest.kt") - } - } - - @Test - fun testPluginApplication() = - checkTaskOutcomes( - executedTasks = listOf( - ":compileKotlinJvm", - ":compileTestKotlinJvm", - ":compileKotlinJs" - ), - excludedTasks = listOf( - ":transformJvmMainAtomicfu", - ":transformJvmTestAtomicfu", - ":transformJsMainAtomicfu", - ":transformJsTestAtomicfu" - ) - ) - - @Test - fun testAtomicfuReferences() { - runner.build() - checkBytecode("build/classes/kotlin/jvm/main/IntArithmetic.class") - } -} diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/gradle.properties b/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/gradle.properties deleted file mode 100644 index fa37a2cd..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -kotlinx.atomicfu.enableJvmIrTransformation=true diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/jvm-simple.gradle.kts b/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/jvm-simple.gradle.kts deleted file mode 100644 index 4a6b008b..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/jvm-simple.gradle.kts +++ /dev/null @@ -1,47 +0,0 @@ -import org.gradle.api.tasks.compile.* -import org.jetbrains.kotlin.gradle.plugin.* - -buildscript { - dependencies { - classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.17.0") - } -} - -plugins { - kotlin("jvm") -} - -apply(plugin = "kotlinx-atomicfu") - -repositories { - mavenCentral() - (properties["kotlin_repo_url"] as? String)?.let { maven(it) } -} - -dependencies { - implementation(kotlin("stdlib")) - implementation(kotlin("test-junit")) -} - -kotlin { - java { - targetCompatibility = JavaVersion.VERSION_1_8 - sourceCompatibility = JavaVersion.VERSION_1_8 - } - - tasks.compileTestKotlin { - doLast { - file("$buildDir/test_compile_jvm_classpath.txt").writeText( - target.compilations["test"].compileDependencyFiles.joinToString("\n") - ) - } - } - - tasks.test { - doLast { - file("$buildDir/test_runtime_jvm_classpath.txt").writeText( - (target.compilations["test"] as KotlinCompilationToRunnableFiles<*>).runtimeDependencyFiles.joinToString("\n") - ) - } - } -} diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/settings.gradle.kts b/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/settings.gradle.kts deleted file mode 100644 index 2f5327fa..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/settings.gradle.kts +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = "jvm-simple" \ No newline at end of file diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/src/main/kotlin/IntArithmetic.kt b/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/src/main/kotlin/IntArithmetic.kt deleted file mode 100644 index 51408253..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/src/main/kotlin/IntArithmetic.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -import kotlinx.atomicfu.* - -class IntArithmetic { - private val _x = atomic(0) - val x get() = _x.value - - fun doWork() { - _x.getAndSet(3) - _x.compareAndSet(3, 8) - } -} - -// minimal example that forces ASM to call AtomicFUTransformer.CW.getCommonSuperClass -private fun checkTransformerFindCommonSuperClass() { - val (a, b) = 0 to 1 - if (a == 0) { - val c = listOf(a, b) - } -} diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/src/test/kotlin/ArithmeticTest.kt b/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/src/test/kotlin/ArithmeticTest.kt deleted file mode 100644 index e75e8ea2..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/jvm-simple/src/test/kotlin/ArithmeticTest.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -import kotlin.test.* - -class ArithmeticTest { - @Test - fun testInt() { - val a = IntArithmetic() - a.doWork() - check(a.x == 8) - } -} \ No newline at end of file diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_both b/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_both deleted file mode 100644 index 5d28ccda..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_both +++ /dev/null @@ -1,3 +0,0 @@ -kotlin.js.compiler=ir -kotlinx.atomicfu.enableJvmIrTransformation=true -kotlinx.atomicfu.enableJsIrTransformation=true diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_js b/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_js deleted file mode 100644 index b57875b7..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_js +++ /dev/null @@ -1,2 +0,0 @@ -kotlin.js.compiler=ir -kotlinx.atomicfu.enableJsIrTransformation=true diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_js_legacy b/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_js_legacy deleted file mode 100644 index 31585e0e..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_js_legacy +++ /dev/null @@ -1 +0,0 @@ -kotlin.js.compiler=legacy diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_jvm b/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_jvm deleted file mode 100644 index 399d39c6..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/gradle.properties_jvm +++ /dev/null @@ -1,2 +0,0 @@ -kotlinx.atomicfu.enableJvmIrTransformation=true -kotlin.js.compiler=ir diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/mpp-simple.gradle.kts b/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/mpp-simple.gradle.kts deleted file mode 100644 index 64aff01f..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/mpp-simple.gradle.kts +++ /dev/null @@ -1,91 +0,0 @@ -import org.jetbrains.kotlin.gradle.plugin.* - -buildscript { - dependencies { - classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.17.0") - } -} - -plugins { - kotlin("multiplatform") -} - -apply(plugin = "kotlinx-atomicfu") - -repositories { - mavenCentral() - (properties["kotlin_repo_url"] as? String)?.let { maven(it) } -} - -kotlin { - targets { - jvm { - compilations.all { - kotlinOptions.jvmTarget = "1.8" - } - testRuns["test"].executionTask.configure { - useJUnit() - } - } - js { - nodejs() - } - } - sourceSets { - val commonMain by getting { - dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib-common") - } - } - val commonTest by getting { - dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - } - } - val jvmMain by getting { - dependencies { - implementation(kotlin("stdlib")) - } - } - val jvmTest by getting { - dependencies { - implementation(kotlin("test-junit")) - } - } - val jsMain by getting { - dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib-js") - } - } - val jsTest by getting { - dependencies { - implementation("org.jetbrains.kotlin:kotlin-test-js") - } - } - } - - tasks.named("compileTestKotlinJvm") { - doLast { - file("$buildDir/test_compile_jvm_classpath.txt").writeText( - targets["jvm"].compilations["test"].compileDependencyFiles.joinToString("\n") - ) - } - } - - tasks.named("jvmTest") { - doLast { - file("$buildDir/test_runtime_jvm_classpath.txt").writeText( - (targets["jvm"].compilations["test"] as KotlinCompilationToRunnableFiles).runtimeDependencyFiles.joinToString("\n") - ) - } - } - - tasks.named("compileTestKotlinJs") { - doLast { - file("$buildDir/test_compile_js_classpath.txt").writeText( - targets["js"].compilations["test"].compileDependencyFiles.joinToString("\n") - ) - } - } -} diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/settings.gradle.kts b/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/settings.gradle.kts deleted file mode 100644 index 5a4e5abf..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/settings.gradle.kts +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = "mpp-simple" \ No newline at end of file diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/src/commonMain/kotlin/IntArithmetic.kt b/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/src/commonMain/kotlin/IntArithmetic.kt deleted file mode 100644 index 51408253..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/src/commonMain/kotlin/IntArithmetic.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -import kotlinx.atomicfu.* - -class IntArithmetic { - private val _x = atomic(0) - val x get() = _x.value - - fun doWork() { - _x.getAndSet(3) - _x.compareAndSet(3, 8) - } -} - -// minimal example that forces ASM to call AtomicFUTransformer.CW.getCommonSuperClass -private fun checkTransformerFindCommonSuperClass() { - val (a, b) = 0 to 1 - if (a == 0) { - val c = listOf(a, b) - } -} diff --git a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/src/commonTest/kotlin/ArithmeticTest.kt b/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/src/commonTest/kotlin/ArithmeticTest.kt deleted file mode 100644 index e75e8ea2..00000000 --- a/atomicfu-gradle-plugin/src/test/resources/projects/mpp-simple/src/commonTest/kotlin/ArithmeticTest.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -import kotlin.test.* - -class ArithmeticTest { - @Test - fun testInt() { - val a = IntArithmetic() - a.doWork() - check(a.x == 8) - } -} \ No newline at end of file