aboutsummaryrefslogtreecommitdiff
path: root/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/JvmProjectTest.kt
blob: e017f05bd7d264a64f195f013ae68088252b0d07 (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
/*
 * 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

import org.gradle.testkit.runner.TaskOutcome
import org.junit.Test
import java.io.File

class JvmProjectTest : BaseKotlinGradleTest() {
    @Test
    fun testKotlinPlugin() =
        project("jvm-simple") {
            doSimpleTest()
        }

    @Test
    fun testKotlinPlatformJvmPlugin() =
        project("jvm-simple", "-platform") {
            projectDir.resolve("build.gradle").modify {
                it.checkedReplace("apply plugin: 'kotlin'", "apply plugin: 'kotlin-platform-jvm'")
            }
            doSimpleTest()
        }

    private fun Project.doSimpleTest() {
        val tasksToCheck = arrayOf(
            ":compileKotlin",
            ":compileTestKotlin",
            ":transformAtomicfuClasses",
            ":transformTestAtomicfuClasses"
        )

        build("build") {
            checkOutcomes(TaskOutcome.SUCCESS, *tasksToCheck)

            val testCompileClasspathFiles = filesFrom("build/test_compile_classpath.txt")
            val testRuntimeClasspathFiles = filesFrom("build/test_runtime_classpath.txt")

            projectDir.resolve("build/classes/kotlin/main/IntArithmetic.class").let {
                it.checkExists()
                check(it in testCompileClasspathFiles) { "Original '$it' is missing from test compile classpath" }
                check(it in testRuntimeClasspathFiles) { "Original '$it' is missing from test runtime classpath" }
            }

            projectDir.resolve("build/classes/atomicfu/main/IntArithmetic.class").let {
                it.checkExists()
                check(it !in testCompileClasspathFiles) { "Transformed '$it' is present in test compile classpath" }
                check(it !in testRuntimeClasspathFiles) { "Transformed '$it' is present in test runtime classpath" }
            }
        }

        build("build") {
            checkOutcomes(TaskOutcome.UP_TO_DATE, *tasksToCheck)
        }
    }

    private fun Project.filesFrom(name: String) = projectDir.resolve(name)
        .readLines().asSequence().flatMap { listFiles(it) }.toHashSet()

    private fun listFiles(dir: String): Sequence<File> = File(dir).walk().filter { it.isFile }
}