[BTA tests] Add example tests
^KT-61860 In Progress
This commit is contained in:
committed by
Space Team
parent
15a24319d5
commit
60ccdf0e2c
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.buildtools.api.tests.compilation
|
||||
|
||||
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.CompatibilityTests
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.assertions.assertOutputs
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.BaseCompilationTest
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.DefaultStrategyAgnosticCompilationTest
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.project
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
|
||||
@Disabled("Example tests for evaluation purposes of the DSL")
|
||||
class ExampleCompatibilityCompilationTest : BaseCompilationTest() {
|
||||
@CompatibilityTests
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
@DisplayName("Sample compatibility compilation test that is run as part of each test suit")
|
||||
fun myTest(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
project {
|
||||
val module1 = module("jvm-module-1")
|
||||
val module2 = module("jvm-module-2", listOf(module1))
|
||||
|
||||
module1.compile(strategyConfig) {
|
||||
assertOutputs("FooKt.class", "Bar.class", "BazKt.class")
|
||||
}
|
||||
module2.compile(strategyConfig) {
|
||||
assertOutputs("AKt.class", "BKt.class")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.buildtools.api.tests.compilation
|
||||
|
||||
import org.jetbrains.kotlin.buildtools.api.CompilationService
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.CompatibilityTests
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@Disabled("Example tests for evaluation purposes of the DSL")
|
||||
class ExampleCompatibilityTest {
|
||||
private val compilationService = CompilationService.loadImplementation(ExampleCompatibilityTest::class.java.classLoader)
|
||||
|
||||
@CompatibilityTests
|
||||
@Test
|
||||
@DisplayName("Sample compatibility test that is run as part of each test suit")
|
||||
fun testDefaultNonIncrementalSettings() {
|
||||
val config = compilationService.makeJvmCompilationConfiguration()
|
||||
Assertions.assertEquals(emptySet<String>(), config.kotlinScriptFilenameExtensions)
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.buildtools.api.tests.compilation
|
||||
|
||||
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
|
||||
import org.jetbrains.kotlin.buildtools.api.SourcesChanges
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.assertions.assertCompiledSources
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.assertions.assertLogContainsPatterns
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.BaseCompilationTest
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.DefaultStrategyAgnosticCompilationTest
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.LogLevel
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.project
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import kotlin.io.path.readText
|
||||
import kotlin.io.path.writeText
|
||||
|
||||
@Disabled("Example tests for evaluation purposes of the DSL")
|
||||
class ExampleIncrementalCompilationTest : BaseCompilationTest() {
|
||||
@DisplayName("Sample IC test with a single module")
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
fun singleModuleTest(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
project {
|
||||
val module1 = module("jvm-module-1")
|
||||
|
||||
module1.compileIncrementally(strategyConfig, SourcesChanges.Unknown)
|
||||
|
||||
val fooKt = module1.sourcesDirectory.resolve("foo.kt")
|
||||
fooKt.writeText(fooKt.readText().replace("foo()", "foo(i: Int = 1)"))
|
||||
|
||||
module1.compileIncrementally(
|
||||
strategyConfig,
|
||||
SourcesChanges.Known(modifiedFiles = listOf(fooKt.toFile()), removedFiles = emptyList()),
|
||||
) {
|
||||
assertCompiledSources("foo.kt", "bar.kt")
|
||||
assertLogContainsPatterns(LogLevel.DEBUG, ".*Incremental compilation completed".toRegex())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Sample IC test with 2 modules and custom compilation options")
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
fun twoModulesTest(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
project {
|
||||
val module1 = module("jvm-module-1")
|
||||
val module2 = module("jvm-module-2", listOf(module1))
|
||||
|
||||
module1.compileIncrementally(strategyConfig, SourcesChanges.Unknown)
|
||||
module2.compileIncrementally(strategyConfig, SourcesChanges.Unknown)
|
||||
|
||||
val barKt = module1.sourcesDirectory.resolve("bar.kt")
|
||||
barKt.writeText(barKt.readText().replace("bar()", "bar(i: Int = 1)"))
|
||||
|
||||
module1.compileIncrementally(
|
||||
strategyConfig,
|
||||
SourcesChanges.Known(modifiedFiles = listOf(barKt.toFile()), removedFiles = emptyList()),
|
||||
incrementalCompilationConfigAction = {
|
||||
it.keepIncrementalCompilationCachesInMemory(false)
|
||||
},
|
||||
)
|
||||
|
||||
module2.compileIncrementally(
|
||||
strategyConfig,
|
||||
SourcesChanges.Known(modifiedFiles = emptyList(), removedFiles = emptyList())
|
||||
) {
|
||||
assertCompiledSources("b.kt")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.buildtools.api.tests.compilation
|
||||
|
||||
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.assertions.assertCompiledSources
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.scenario.scenario
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.BaseCompilationTest
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.DefaultStrategyAgnosticCompilationTest
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
|
||||
@Disabled("Example tests for evaluation purposes of the DSL")
|
||||
class ExampleIncrementalScenarioTest : BaseCompilationTest() {
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
@DisplayName("Sample scenario DSL IC test with a single module")
|
||||
fun scenario1Test(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
scenario(strategyConfig) {
|
||||
val module1 = module("jvm-module-1")
|
||||
|
||||
module1.createFile(
|
||||
"foobar.kt",
|
||||
addedOutputs = setOf("FoobarKt.class"),
|
||||
//language=kt
|
||||
"""
|
||||
fun foobar() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
module1.compile {
|
||||
assertCompiledSources("foobar.kt")
|
||||
}
|
||||
|
||||
module1.deleteFile(
|
||||
"foobar.kt",
|
||||
removedOutputs = setOf("FoobarKt.class"),
|
||||
)
|
||||
|
||||
module1.compile {
|
||||
assertCompiledSources()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Another sample scenario DSL IC test with a single module and custom IC options")
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
fun scenario2Test(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
scenario(strategyConfig) {
|
||||
val module1 = module("jvm-module-1", incrementalCompilationOptionsModifier = { it.keepIncrementalCompilationCachesInMemory(false) })
|
||||
|
||||
module1.createFile(
|
||||
"foobar.kt",
|
||||
addedOutputs = setOf("FoobarKt.class"),
|
||||
//language=kt
|
||||
"""
|
||||
fun foobar() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
module1.compile {
|
||||
assertCompiledSources("foobar.kt")
|
||||
}
|
||||
|
||||
module1.deleteFile(
|
||||
"foobar.kt",
|
||||
removedOutputs = setOf("FoobarKt.class"),
|
||||
)
|
||||
|
||||
module1.compile {
|
||||
assertCompiledSources()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Sample scenario DSL IC test with two modules")
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
fun scenario3Test(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
scenario(strategyConfig) {
|
||||
val module1 = module("jvm-module-1")
|
||||
val module2 = module("jvm-module-2", listOf(module1))
|
||||
|
||||
module1.changeFile(
|
||||
"bar.kt",
|
||||
transform = {
|
||||
//language=kt
|
||||
it.replace("fun bar()", "fun bar(someNumber: Int = 50)")
|
||||
}
|
||||
)
|
||||
|
||||
module1.compile {
|
||||
assertCompiledSources("bar.kt")
|
||||
}
|
||||
|
||||
module2.compile {
|
||||
assertCompiledSources("b.kt")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.buildtools.api.tests.compilation
|
||||
|
||||
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.assertions.assertLogContainsPatterns
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.assertions.assertOutputs
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.BaseCompilationTest
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.DefaultStrategyAgnosticCompilationTest
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.LogLevel
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.project
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import kotlin.io.path.writeText
|
||||
|
||||
@Disabled("Example tests for evaluation purposes of the DSL")
|
||||
class ExampleNonIncrementalCompilationTest : BaseCompilationTest() {
|
||||
@DisplayName("Sample non-incremental compilation test with two modules")
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
fun myTest(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
project {
|
||||
val module1 = module("jvm-module-1")
|
||||
val module2 = module("jvm-module-2", listOf(module1))
|
||||
|
||||
module1.compile(strategyConfig) {
|
||||
assertOutputs("FooKt.class", "Bar.class", "BazKt.class")
|
||||
}
|
||||
module2.compile(strategyConfig) {
|
||||
assertOutputs("AKt.class", "BKt.class")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Sample non-incremental compilation test with a single module and a compilation error")
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
fun failedCompilationTest(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
project {
|
||||
val module1 = module("jvm-module-1")
|
||||
|
||||
module1.sourcesDirectory.resolve("bar.kt").writeText("aaaa")
|
||||
|
||||
module1.compile(strategyConfig) {
|
||||
expectFail()
|
||||
assertLogContainsPatterns(LogLevel.ERROR, ".*bar\\.kt:1:1 Syntax error: Expecting a top level declaration.*".toRegex())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
class Bar {
|
||||
fun bar() = foo()
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
fun baz() = 42
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
val a = 5
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
val b = Bar().bar()
|
||||
Reference in New Issue
Block a user