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 JvmProjectTest : BaseKotlinGradleTest() { 12 @Test testKotlinPluginnull13 fun testKotlinPlugin() = 14 project("jvm-simple") { 15 doSimpleTest() 16 } 17 18 @Test testKotlinPlatformJvmPluginnull19 fun testKotlinPlatformJvmPlugin() = 20 project("jvm-simple", "-platform") { 21 projectDir.resolve("build.gradle").modify { 22 it.checkedReplace("apply plugin: 'kotlin'", "apply plugin: 'kotlin-platform-jvm'") 23 } 24 doSimpleTest() 25 } 26 Projectnull27 private fun Project.doSimpleTest() { 28 val tasksToCheck = arrayOf( 29 ":compileKotlin", 30 ":compileTestKotlin", 31 ":transformAtomicfuClasses", 32 ":transformTestAtomicfuClasses" 33 ) 34 35 build("build") { 36 checkOutcomes(TaskOutcome.SUCCESS, *tasksToCheck) 37 38 val testCompileClasspathFiles = filesFrom("build/test_compile_classpath.txt") 39 val testRuntimeClasspathFiles = filesFrom("build/test_runtime_classpath.txt") 40 41 projectDir.resolve("build/classes/kotlin/main/IntArithmetic.class").let { 42 it.checkExists() 43 check(it in testCompileClasspathFiles) { "Original '$it' is missing from test compile classpath" } 44 check(it in testRuntimeClasspathFiles) { "Original '$it' is missing from test runtime classpath" } 45 } 46 47 projectDir.resolve("build/classes/atomicfu/main/IntArithmetic.class").let { 48 it.checkExists() 49 check(it !in testCompileClasspathFiles) { "Transformed '$it' is present in test compile classpath" } 50 check(it !in testRuntimeClasspathFiles) { "Transformed '$it' is present in test runtime classpath" } 51 } 52 } 53 54 build("build") { 55 checkOutcomes(TaskOutcome.UP_TO_DATE, *tasksToCheck) 56 } 57 } 58 Projectnull59 private fun Project.filesFrom(name: String) = projectDir.resolve(name) 60 .readLines().asSequence().flatMap { listFiles(it) }.toHashSet() 61 <lambda>null62 private fun listFiles(dir: String): Sequence<File> = File(dir).walk().filter { it.isFile } 63 } 64