aboutsummaryrefslogtreecommitdiff
path: root/atomicfu-gradle-plugin/src/test/kotlin/kotlinx/atomicfu/plugin/gradle/BaseKotlinGradleTest.kt
blob: b81a0c9c4e940363ef4f5d4eedf8a9dbd5211176 (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
/*
 * 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.internal.impldep.com.google.common.io.Files
import org.junit.After
import org.junit.Before
import java.io.File

abstract class BaseKotlinGradleTest {
    private lateinit var workingDir: File

    fun project(name: String, suffix: String = "", fn: Project.() -> Unit) {
        workingDir = File("build${File.separator}test-$name$suffix").absoluteFile
        workingDir.deleteRecursively()
        workingDir.mkdirs()
        val testResources = File("src/test/resources")
        val originalProjectDir = testResources.resolve("projects/$name").apply { checkExists() }
        val projectDir = workingDir.resolve(name).apply { mkdirs() }
        originalProjectDir.listFiles().forEach { it.copyRecursively(projectDir.resolve(it.name)) }

        // Add an empty setting.gradle
        projectDir.resolve("settings.gradle").writeText("// this file is intentionally left empty")

        Project(projectDir = projectDir).fn()
    }
}