aboutsummaryrefslogtreecommitdiff
path: root/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/test/JvmProjectTest.kt
blob: 2545e0ea3f816f2a7e0cdd2b266f72c65ed2889c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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",
                ":transformAtomicfuClasses",
                ":compileTestKotlin",
                ":transformTestAtomicfuClasses"
            ),
            excludedTasks = emptyList()
        )

    @Test
    fun testClasspath() {
        runner.build()
        checkJvmCompilationClasspath(
            originalClassFile = "build/classes/kotlin/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(
                ":transformAtomicfuClasses",
                ":transformTestAtomicfuClasses"
            )
        )

    @Test
    fun testAtomicfuReferences() {
        runner.build()
        checkBytecode("build/classes/kotlin/main/IntArithmetic.class")
    }
}