1 /* 2 * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.atomicfu.plugin.gradle 6 7 import org.gradle.testkit.runner.TaskOutcome 8 import org.junit.Test 9 import java.io.File 10 11 class MppProjectTest : BaseKotlinGradleTest() { 12 @Test <lambda>null13 fun testKotlinMultiplatformPlugin() = project("mpp-simple") { 14 val tasksToCheck = arrayOf( 15 ":compileKotlinJvm", 16 ":compileTestKotlinJvm", 17 ":transformJvmMainAtomicfu", 18 ":transformJvmTestAtomicfu", 19 ":compileKotlinJs", 20 ":transformJsMainAtomicfu" 21 ) 22 23 build("build") { 24 checkOutcomes(TaskOutcome.SUCCESS, *tasksToCheck) 25 26 fun checkPlatform(platform: String, fileInMainName: String) { 27 val isJs = platform == "js" 28 val testCompileClasspathFiles = projectDir.resolve("build/classpath/$platform/test_compile.txt") 29 .readLines().asSequence().flatMapTo(HashSet()) { File(it).walk().filter(File::isFile) } 30 val testRuntimeClasspathFiles = if (isJs) emptySet<File>() else projectDir.resolve("build/classpath/$platform/test_runtime.txt") 31 .readLines().asSequence().flatMapTo(HashSet()) { File(it).walk().filter(File::isFile) } 32 33 projectDir.resolve("build/classes/kotlin/$platform/main/$fileInMainName").let { 34 it.checkExists() 35 check(it in testCompileClasspathFiles) { "Original '$it' is missing from $platform test compile classpath" } 36 if (!isJs) check(it in testRuntimeClasspathFiles) { "Original '$it' is missing from $platform test runtime classpath" } 37 } 38 39 projectDir.resolve("build/classes/atomicfu/jvm/main/IntArithmetic.class").let { 40 it.checkExists() 41 check(it !in testCompileClasspathFiles) { "Transformed '$it' is present in $platform test compile classpath" } 42 if (!isJs) check(it !in testRuntimeClasspathFiles) { "Transformed '$it' is present in $platform test runtime classpath" } 43 } 44 45 } 46 47 checkPlatform("jvm", "IntArithmetic.class") 48 checkPlatform("js", "mpp-simple.js") 49 } 50 51 build("build") { 52 checkOutcomes(TaskOutcome.UP_TO_DATE, *tasksToCheck) 53 } 54 } 55 } 56