package org.gradle.kotlin.dsl.integration

import org.gradle.kotlin.dsl.fixtures.AbstractIntegrationTest
import org.gradle.kotlin.dsl.fixtures.DeepThought
import org.junit.Test


class KotlinInitScriptIntegrationTest : AbstractIntegrationTest() {

    @Test
    fun `initscript classpath`() {

        withClassJar("fixture.jar", DeepThought::class.java)

        val initScript =
            withFile("init.gradle.kts", """

                initscript {
                    dependencies { classpath(files("fixture.jar")) }
                }

                val computer = ${DeepThought::class.qualifiedName}()
                val answer = computer.compute()
                println("*" + answer + "*")
            """)

        assert(
            build("-I", initScript.canonicalPath)
                .output.contains("*42*"))
    }

    @Test
    fun `initscript file path is resolved against parent script dir`() {

        withBuildScript("""
            val answer: String by extra
            println("*" + answer + "*")
        """)

        val initScript =
            withFile("gradle/init.gradle.kts", """
                apply { from("./answer.gradle.kts") }
            """)

        withFile("gradle/answer.gradle.kts", """
            rootProject {
                val answer by extra { "42" }
            }
        """)

        assert(
            build("-I", initScript.canonicalPath)
                .output.contains("*42*"))
    }
}

package org.gradle.kotlin.dsl.integration

import org.gradle.kotlin.dsl.fixtures.AbstractIntegrationTest
import org.gradle.kotlin.dsl.fixtures.DeepThought
import org.junit.Test


class KotlinInitScriptIntegrationTest : AbstractIntegrationTest() {

    @Test
    fun `initscript classpath`() {

        withClassJar("fixture.jar", DeepThought::class.java)

        val initScript =
            withFile("init.gradle.kts", """

                initscript {
                    dependencies { classpath(files("fixture.jar")) }
                }

                val computer = ${DeepThought::class.qualifiedName}()
                val answer = computer.compute()
                println("*" + answer + "*")
            """)

        assert(
            build("-I", initScript.canonicalPath)
                .output.contains("*42*"))
    }

    @Test
    fun `initscript file path is resolved relative to parent script dir`() {

        val initScript =
            withFile("gradle/init.gradle.kts", """
                apply { from("./answer.gradle.kts") }
            """)

        withFile("gradle/answer.gradle.kts", """
            rootProject {
                val answer by extra { "42" }
            }
        """)

        withBuildScript("""
            val answer: String by extra
            println("*" + answer + "*")
        """)

        assert(
            build("-I", initScript.canonicalPath)
                .output.contains("*42*"))
    }
}

Reorder test statements for clarity
Reorder test statements for clarity

blindpirate/gradle,robinverduijn/gradle,blindpirate/gradle,gradle/gradle-script-kotlin,gradle/gradle,robinverduijn/gradle,blindpirate/gradle,robinverduijn/gradle,blindpirate/gradle,robinverduijn/gradle,robinverduijn/gradle,gradle/gradle,blindpirate/gradle,blindpirate/gradle,gradle/gradle,gradle/gradle,blindpirate/gradle,gradle/gradle,robinverduijn/gradle,robinverduijn/gradle,gradle/gradle,gradle/gradle-script-kotlin,robinverduijn/gradle,blindpirate/gradle,robinverduijn/gradle,gradle/gradle,blindpirate/gradle,robinverduijn/gradle,blindpirate/gradle,robinverduijn/gradle,gradle/gradle,gradle/gradle,gradle/gradle