aboutsummaryrefslogtreecommitdiff
path: root/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/MppProjectTest.kt
blob: 6dd7fa16a26ba51e71454786909bb4d1d09e9cd0 (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
/*
 * 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 MppProjectTest : BaseKotlinGradleTest() {
    @Test
    fun testKotlinMultiplatformPlugin() = project("mpp-simple") {
        val tasksToCheck = arrayOf(
            ":compileKotlinJvm",
            ":compileTestKotlinJvm",
            ":transformJvmMainAtomicfu",
            ":transformJvmTestAtomicfu",
            ":compileKotlinJs",
            ":transformJsMainAtomicfu"
        )

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

            fun checkPlatform(platform: String, fileInMainName: String) {
                val isJs = platform == "js"
                val testCompileClasspathFiles = projectDir.resolve("build/classpath/$platform/test_compile.txt")
                    .readLines().asSequence().flatMapTo(HashSet()) { File(it).walk().filter(File::isFile) }
                val testRuntimeClasspathFiles = if (isJs) emptySet<File>() else projectDir.resolve("build/classpath/$platform/test_runtime.txt")
                    .readLines().asSequence().flatMapTo(HashSet()) { File(it).walk().filter(File::isFile) }

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

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

            }

            checkPlatform("jvm", "IntArithmetic.class")
            checkPlatform("js", "mpp-simple.js")
        }

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