[KAPT] Migrate tests in kapt3-base and kapt3-cli to JUnit 5
This commit is contained in:
committed by
teamcity
parent
b7cc781e97
commit
fdf1b8b1c0
@@ -212,16 +212,6 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("plugins/kapt3/kapt3-cli/test", "plugins/kapt3/kapt3-cli/testData") {
|
||||
testClass<AbstractArgumentParsingTest> {
|
||||
model("argumentParsing", extension = "txt")
|
||||
}
|
||||
|
||||
testClass<AbstractKaptToolIntegrationTest> {
|
||||
model("integration", recursive = false, extension = null)
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("plugins/sam-with-receiver/tests-gen", "plugins/sam-with-receiver/testData") {
|
||||
testClass<AbstractSamWithReceiverScriptTest> {
|
||||
model("script", extension = "kts")
|
||||
@@ -464,5 +454,15 @@ fun main(args: Array<String>) {
|
||||
model("codegen", excludedPattern = excludedFirTestdataPattern)
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("plugins/kapt3/kapt3-cli/tests-gen", "plugins/kapt3/kapt3-cli/testData") {
|
||||
testClass<AbstractArgumentParsingTest> {
|
||||
model("argumentParsing", extension = "txt")
|
||||
}
|
||||
|
||||
testClass<AbstractKaptToolIntegrationTest> {
|
||||
model("integration", recursive = false, extension = null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,9 @@ dependencies {
|
||||
api(kotlinStdlib())
|
||||
compileOnly(toolsJarApi())
|
||||
|
||||
testApi(commonDependency("junit:junit"))
|
||||
testApiJUnit5()
|
||||
testCompileOnly(toolsJarApi())
|
||||
testRuntimeOnly(toolsJar())
|
||||
|
||||
testCompileOnly(toolsJarApi())
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -22,6 +20,7 @@ sourceSets {
|
||||
testsJar {}
|
||||
|
||||
projectTest {
|
||||
useJUnitPlatform()
|
||||
workingDir = rootDir
|
||||
dependsOn(":dist")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.kapt.base.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.base.kapt3.DetectMemoryLeaksMode
|
||||
import org.jetbrains.kotlin.base.kapt3.KaptFlag
|
||||
import org.jetbrains.kotlin.base.kapt3.KaptOptions
|
||||
@@ -15,15 +14,16 @@ import org.jetbrains.kotlin.kapt3.base.incremental.DeclaredProcType
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor
|
||||
import org.jetbrains.kotlin.kapt3.base.util.KaptBaseError
|
||||
import org.jetbrains.kotlin.kapt3.base.util.WriterBackedKaptLogger
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import javax.annotation.processing.AbstractProcessor
|
||||
import javax.annotation.processing.Processor
|
||||
import javax.annotation.processing.RoundEnvironment
|
||||
import javax.lang.model.element.TypeElement
|
||||
|
||||
class JavaKaptContextTest : TestCase() {
|
||||
class JavaKaptContextTest {
|
||||
companion object {
|
||||
private val TEST_DATA_DIR = File("plugins/kapt3/kapt3-base/testData/runner")
|
||||
val logger = WriterBackedKaptLogger(isVerbose = true)
|
||||
@@ -38,7 +38,7 @@ class JavaKaptContextTest : TestCase() {
|
||||
for (annotatedElement in annotatedElements) {
|
||||
val generatedClassName = annotatedElement.simpleName.toString().replaceFirstChar(Char::uppercaseChar) +
|
||||
annotationName.replaceFirstChar(Char::uppercaseChar)
|
||||
val file = processingEnv.filer.createSourceFile("generated." + generatedClassName)
|
||||
val file = processingEnv.filer.createSourceFile("generated.$generatedClassName")
|
||||
file.openWriter().use {
|
||||
it.write(
|
||||
"""
|
||||
@@ -100,7 +100,11 @@ class JavaKaptContextTest : TestCase() {
|
||||
}
|
||||
|
||||
try {
|
||||
doAnnotationProcessing(File(TEST_DATA_DIR, "Simple.java"), IncrementalProcessor(processor, DeclaredProcType.NON_INCREMENTAL, logger), TEST_DATA_DIR)
|
||||
doAnnotationProcessing(
|
||||
File(TEST_DATA_DIR, "Simple.java"),
|
||||
IncrementalProcessor(processor, DeclaredProcType.NON_INCREMENTAL, logger),
|
||||
TEST_DATA_DIR
|
||||
)
|
||||
} catch (e: KaptBaseError) {
|
||||
assertEquals(KaptBaseError.Kind.EXCEPTION, e.kind)
|
||||
assertEquals("Here we are!", e.cause!!.message)
|
||||
@@ -123,4 +127,4 @@ class JavaKaptContextTest : TestCase() {
|
||||
|
||||
assertTrue(triggered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.kapt.base.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.base.kapt3.KaptOptions
|
||||
import org.jetbrains.kotlin.base.kapt3.collectJavaSourceFiles
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
class KaptPathsTest : TestCase() {
|
||||
class KaptPathsTest {
|
||||
@Test
|
||||
fun testSymbolicLinks() {
|
||||
if (System.getProperty("os.name").lowercase().contains("win")) return
|
||||
@@ -49,8 +50,7 @@ class KaptPathsTest : TestCase() {
|
||||
|
||||
fun assertContains(path: String) {
|
||||
val available by lazy { javaSourceFiles.joinToString { it.toRelativeString(tempDir) } }
|
||||
assertTrue("Can't find path $path\nAvailable: $available",
|
||||
javaSourceFiles.any { it.toRelativeString(tempDir) == path })
|
||||
assertTrue(javaSourceFiles.any { it.toRelativeString(tempDir) == path }) { "Can't find path $path\nAvailable: $available" }
|
||||
}
|
||||
|
||||
assertEquals(4, javaSourceFiles.size)
|
||||
@@ -62,4 +62,4 @@ class KaptPathsTest : TestCase() {
|
||||
tempDir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.kapt3.base
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun File.newSourcesFolder(): File = newFolder("sources")
|
||||
fun File.newClassesFolder(): File = newFolder("classes")
|
||||
fun File.newStubsFolder(): File = newFolder("stubs")
|
||||
fun File.newCacheFolder(): File = newFolder("cache")
|
||||
fun File.newGeneratedSourcesFolder(): File = newFolder("generatedSources")
|
||||
fun File.newCompiledSourcesFolder(): File = newFolder("compiledSources")
|
||||
|
||||
fun File.newFolder(name: String): File {
|
||||
return resolve(name).also { it.mkdir() }
|
||||
}
|
||||
|
||||
fun File.newFile(name: String): File {
|
||||
return resolve(name).also { it.createNewFile() }
|
||||
}
|
||||
+33
-27
@@ -6,80 +6,86 @@
|
||||
package org.jetbrains.kotlin.kapt3.base
|
||||
|
||||
import org.jetbrains.kotlin.base.kapt3.KaptOptions
|
||||
import org.jetbrains.kotlin.kapt3.base.newClassesFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newFile
|
||||
import org.jetbrains.kotlin.kapt3.base.newSourcesFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newStubsFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.util.WriterBackedKaptLogger
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
class ProcessorLoaderTest {
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
val tmp = TemporaryFolder()
|
||||
@TempDir
|
||||
var _rootTempDirectory: File? = null
|
||||
|
||||
val rootTempDirectory: File
|
||||
get() = _rootTempDirectory!!
|
||||
|
||||
@Test
|
||||
fun testProcessorClasspath() {
|
||||
val kaptOptions = with(KaptOptions.Builder()) {
|
||||
val jar = tmp.newFile("empty.jar").also {
|
||||
val jar = rootTempDirectory.newFile("empty.jar").also {
|
||||
ZipOutputStream(it.outputStream()).use {
|
||||
it.putNextEntry(ZipEntry("fake_entry"))
|
||||
it.closeEntry()
|
||||
}
|
||||
}
|
||||
processingClasspath.add(jar)
|
||||
sourcesOutputDir = tmp.newFolder()
|
||||
classesOutputDir = tmp.newFolder()
|
||||
stubsOutputDir = tmp.newFolder()
|
||||
sourcesOutputDir = rootTempDirectory.newSourcesFolder()
|
||||
classesOutputDir = rootTempDirectory.newClassesFolder()
|
||||
stubsOutputDir = rootTempDirectory.newStubsFolder()
|
||||
build()
|
||||
}
|
||||
val loadedProcessors = ProcessorLoader(kaptOptions, WriterBackedKaptLogger(false)).loadProcessors()
|
||||
Assert.assertTrue(loadedProcessors.processors.isEmpty())
|
||||
assertTrue(loadedProcessors.processors.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testProcessorUpperCaseExtensionClasspath() {
|
||||
val kaptOptions = with(KaptOptions.Builder()) {
|
||||
val jar = tmp.newFile("empty.JAR").also {
|
||||
val jar = rootTempDirectory.newFile("empty.JAR").also {
|
||||
ZipOutputStream(it.outputStream()).use {
|
||||
it.putNextEntry(ZipEntry("fake_entry"))
|
||||
it.closeEntry()
|
||||
}
|
||||
}
|
||||
processingClasspath.add(jar)
|
||||
sourcesOutputDir = tmp.newFolder()
|
||||
classesOutputDir = tmp.newFolder()
|
||||
stubsOutputDir = tmp.newFolder()
|
||||
sourcesOutputDir = rootTempDirectory.newSourcesFolder()
|
||||
classesOutputDir = rootTempDirectory.newClassesFolder()
|
||||
stubsOutputDir = rootTempDirectory.newStubsFolder()
|
||||
build()
|
||||
}
|
||||
val loadedProcessors = ProcessorLoader(kaptOptions, WriterBackedKaptLogger(false)).loadProcessors()
|
||||
Assert.assertTrue(loadedProcessors.processors.isEmpty())
|
||||
assertTrue(loadedProcessors.processors.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmptyClasspath() {
|
||||
val kaptOptions = with(KaptOptions.Builder()) {
|
||||
sourcesOutputDir = tmp.newFolder()
|
||||
classesOutputDir = tmp.newFolder()
|
||||
stubsOutputDir = tmp.newFolder()
|
||||
sourcesOutputDir = rootTempDirectory.newSourcesFolder()
|
||||
classesOutputDir = rootTempDirectory.newClassesFolder()
|
||||
stubsOutputDir = rootTempDirectory.newStubsFolder()
|
||||
build()
|
||||
}
|
||||
val loadedProcessors = ProcessorLoader(kaptOptions, WriterBackedKaptLogger(false)).loadProcessors()
|
||||
Assert.assertTrue(loadedProcessors.processors.isEmpty())
|
||||
assertTrue(loadedProcessors.processors.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClasspathWithNonJars() {
|
||||
val kaptOptions = with(KaptOptions.Builder()) {
|
||||
processingClasspath.add(tmp.newFile("do-not-load.gz"))
|
||||
sourcesOutputDir = tmp.newFolder()
|
||||
classesOutputDir = tmp.newFolder()
|
||||
stubsOutputDir = tmp.newFolder()
|
||||
processingClasspath.add(rootTempDirectory.newFile("do-not-load.gz"))
|
||||
sourcesOutputDir = rootTempDirectory.newSourcesFolder()
|
||||
classesOutputDir = rootTempDirectory.newClassesFolder()
|
||||
stubsOutputDir = rootTempDirectory.newStubsFolder()
|
||||
build()
|
||||
}
|
||||
val loadedProcessors = ProcessorLoader(kaptOptions, WriterBackedKaptLogger(false)).loadProcessors()
|
||||
Assert.assertTrue(loadedProcessors.processors.isEmpty())
|
||||
assertTrue(loadedProcessors.processors.isEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.kapt3.base.incremental
|
||||
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractTestWithGeneratedSourcesDir {
|
||||
@TempDir
|
||||
private var _generatedSources: File? = null
|
||||
|
||||
protected val generatedSources: File
|
||||
get() = _generatedSources!!
|
||||
}
|
||||
+6
-21
@@ -3,28 +3,13 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.RuntimeProcType
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
|
||||
class AggregatingIncrementalProcessorTest {
|
||||
@JvmField
|
||||
@Rule
|
||||
val tmp: TemporaryFolder = TemporaryFolder()
|
||||
|
||||
private lateinit var generatedSources: File
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
generatedSources = tmp.newFolder()
|
||||
}
|
||||
|
||||
class AggregatingIncrementalProcessorTest : AbstractTestWithGeneratedSourcesDir() {
|
||||
@Test
|
||||
fun testDependenciesRecorded() {
|
||||
val srcFiles = listOf("User.java", "Address.java", "Observable.java").map { File(TEST_DATA_DIR, it) }
|
||||
@@ -49,7 +34,7 @@ class AggregatingIncrementalProcessorTest {
|
||||
runAnnotationProcessing(srcFiles, listOf(aggregating), generatedSources)
|
||||
|
||||
assertEquals(RuntimeProcType.AGGREGATING, aggregating.getRuntimeType())
|
||||
assertEquals(emptyMap<File, File>(), aggregating.getGeneratedToSources())
|
||||
assertEquals(emptyMap<File, String?>(), aggregating.getGeneratedToSources())
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,4 +57,4 @@ class AggregatingIncrementalProcessorTest {
|
||||
aggregating.getGeneratedToSources()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-8
@@ -3,13 +3,11 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.AnnotationProcessorDependencyCollector
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.RuntimeProcType
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
|
||||
class AnnotationProcessorDependencyCollectorTest {
|
||||
@@ -30,7 +28,7 @@ class AnnotationProcessorDependencyCollectorTest {
|
||||
isolating.add(File("GeneratedA.java").toURI(), emptyArray(), null)
|
||||
|
||||
assertEquals(isolating.getRuntimeType(), RuntimeProcType.NON_INCREMENTAL)
|
||||
assertEquals(isolating.getGeneratedToSources(), emptyMap<File, File?>())
|
||||
assertEquals(isolating.getGeneratedToSources(), emptyMap<File, String?>())
|
||||
assertTrue(warnings.single().contains("Expected 1 originating source file when generating"))
|
||||
}
|
||||
|
||||
@@ -41,7 +39,7 @@ class AnnotationProcessorDependencyCollectorTest {
|
||||
nonIncremental.add(File("GeneratedB.java").toURI(), emptyArray(), null)
|
||||
|
||||
assertEquals(nonIncremental.getRuntimeType(), RuntimeProcType.NON_INCREMENTAL)
|
||||
assertEquals(nonIncremental.getGeneratedToSources(), emptyMap<File, File?>())
|
||||
assertEquals(nonIncremental.getGeneratedToSources(), emptyMap<File, String?>())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-22
@@ -3,29 +3,13 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.RuntimeProcType
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
|
||||
|
||||
class DynamicIncrementalProcessorTest {
|
||||
@JvmField
|
||||
@Rule
|
||||
val tmp: TemporaryFolder = TemporaryFolder()
|
||||
|
||||
private lateinit var generatedSources: File
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
generatedSources = tmp.newFolder()
|
||||
}
|
||||
|
||||
class DynamicIncrementalProcessorTest : AbstractTestWithGeneratedSourcesDir() {
|
||||
@Test
|
||||
fun testIfIsolating() {
|
||||
val srcFiles = listOf("User.java", "Address.java", "Observable.java").map { File(TEST_DATA_DIR, it) }
|
||||
@@ -68,8 +52,8 @@ class DynamicIncrementalProcessorTest {
|
||||
|
||||
assertEquals(RuntimeProcType.NON_INCREMENTAL, dynamic.getRuntimeType())
|
||||
assertEquals(
|
||||
emptyMap<File, File>(),
|
||||
emptyMap<File, String?>(),
|
||||
dynamic.getGeneratedToSources()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+42
-36
@@ -3,40 +3,38 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.base.kapt3.KaptFlag
|
||||
import org.jetbrains.kotlin.base.kapt3.KaptOptions
|
||||
import org.jetbrains.kotlin.base.kapt3.collectJavaSourceFiles
|
||||
import org.jetbrains.kotlin.kapt3.base.KaptContext
|
||||
import org.jetbrains.kotlin.kapt3.base.doAnnotationProcessing
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.RuntimeProcType
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.SourcesToReprocess
|
||||
import org.jetbrains.kotlin.kapt3.base.util.WriterBackedKaptLogger
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
|
||||
class IncrementalKaptTest {
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
var tmp = TemporaryFolder()
|
||||
|
||||
@Test
|
||||
fun testIncrementalRun() {
|
||||
val sourcesDir = tmp.newFolder().resolve("test").also { base ->
|
||||
fun testIncrementalRun(
|
||||
@TempDir baseSourcesDir: File,
|
||||
@TempDir outputDir: File,
|
||||
@TempDir incrementalCacheDir: File,
|
||||
@TempDir projectBaseDirFirstRun: File,
|
||||
@TempDir projectBaseDirSecondRun: File,
|
||||
@TempDir classesOutput: File
|
||||
) {
|
||||
val sourcesDir = baseSourcesDir.resolve("test").also { base ->
|
||||
base.mkdir()
|
||||
listOf("User.java", "Address.java", "Observable.java").map {
|
||||
TEST_DATA_DIR.resolve(it).copyTo(base.resolve(it))
|
||||
}
|
||||
}
|
||||
|
||||
val outputDir = tmp.newFolder()
|
||||
val incrementalCacheDir = tmp.newFolder()
|
||||
val options = KaptOptions.Builder().apply {
|
||||
projectBaseDir = tmp.newFolder()
|
||||
projectBaseDir = projectBaseDirFirstRun
|
||||
javaSourceRoots.add(sourcesDir)
|
||||
|
||||
sourcesOutputDir = outputDir
|
||||
@@ -54,15 +52,14 @@ class IncrementalKaptTest {
|
||||
)
|
||||
}
|
||||
|
||||
val classesOutput = tmp.newFolder()
|
||||
compileSources(sourcesDir.listFiles().asIterable(), classesOutput)
|
||||
compileSources(sourcesDir.listFiles().orEmpty().asIterable(), classesOutput)
|
||||
|
||||
val addressTimestamp = outputDir.resolve("test/AddressGenerated.java").lastModified()
|
||||
assertTrue(outputDir.resolve("test/UserGenerated.java").exists())
|
||||
assertTrue(outputDir.resolve("test/AddressGenerated.java").exists())
|
||||
|
||||
val optionsForSecondRun = KaptOptions.Builder().apply {
|
||||
projectBaseDir = tmp.newFolder()
|
||||
projectBaseDir = projectBaseDirSecondRun
|
||||
|
||||
sourcesOutputDir = outputDir
|
||||
classesOutputDir = outputDir
|
||||
@@ -98,18 +95,23 @@ class IncrementalKaptTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGeneratedCompiledAreIgnored() {
|
||||
val sourcesDir = tmp.newFolder().resolve("test").also { base ->
|
||||
fun testGeneratedCompiledAreIgnored(
|
||||
@TempDir baseSourcesDir: File,
|
||||
@TempDir outputDir: File,
|
||||
@TempDir incrementalCacheDir: File,
|
||||
@TempDir projectBaseDirFirstRun: File,
|
||||
@TempDir projectBaseDirSecondRun: File,
|
||||
@TempDir classesOutput: File
|
||||
) {
|
||||
val sourcesDir = baseSourcesDir.resolve("test").also { base ->
|
||||
base.mkdir()
|
||||
listOf("User.java", "Address.java", "Observable.java").map {
|
||||
TEST_DATA_DIR.resolve(it).copyTo(base.resolve(it))
|
||||
}
|
||||
}
|
||||
|
||||
val outputDir = tmp.newFolder()
|
||||
val incrementalCacheDir = tmp.newFolder()
|
||||
val options = KaptOptions.Builder().apply {
|
||||
projectBaseDir = tmp.newFolder()
|
||||
projectBaseDir = projectBaseDirFirstRun
|
||||
javaSourceRoots.add(sourcesDir)
|
||||
|
||||
sourcesOutputDir = outputDir
|
||||
@@ -127,15 +129,14 @@ class IncrementalKaptTest {
|
||||
)
|
||||
}
|
||||
|
||||
val classesOutput = tmp.newFolder()
|
||||
compileSources(sourcesDir.listFiles().asIterable(), classesOutput)
|
||||
compileSources(sourcesDir.listFiles().orEmpty().asIterable(), classesOutput)
|
||||
compileSources(
|
||||
listOf(outputDir.resolve("test/UserGenerated.java"), outputDir.resolve("test/AddressGenerated.java")),
|
||||
classesOutput
|
||||
)
|
||||
|
||||
val optionsForSecondRun = KaptOptions.Builder().apply {
|
||||
projectBaseDir = tmp.newFolder()
|
||||
projectBaseDir = projectBaseDirSecondRun
|
||||
|
||||
sourcesOutputDir = outputDir
|
||||
classesOutputDir = outputDir
|
||||
@@ -152,7 +153,8 @@ class IncrementalKaptTest {
|
||||
assertFalse(outputDir.resolve("test/UserGenerated.java").exists())
|
||||
|
||||
it.doAnnotationProcessing(
|
||||
optionsForSecondRun.collectJavaSourceFiles(it.sourcesToReprocess), listOf(SimpleGeneratingIfTypeDoesNotExist().toIsolating())
|
||||
optionsForSecondRun.collectJavaSourceFiles(it.sourcesToReprocess),
|
||||
listOf(SimpleGeneratingIfTypeDoesNotExist().toIsolating())
|
||||
)
|
||||
}
|
||||
|
||||
@@ -161,18 +163,22 @@ class IncrementalKaptTest {
|
||||
|
||||
/** Regression test for KT-31322. */
|
||||
@Test
|
||||
fun testCleanupWithDynamicNonIncremental() {
|
||||
val sourcesDir = tmp.newFolder().resolve("test").also { base ->
|
||||
fun testCleanupWithDynamicNonIncremental(
|
||||
@TempDir baseSourcesDir: File,
|
||||
@TempDir outputDir: File,
|
||||
@TempDir incrementalCacheDir: File,
|
||||
@TempDir projectBaseDirFirstRun: File,
|
||||
@TempDir projectBaseDirSecondRun: File
|
||||
) {
|
||||
val sourcesDir = baseSourcesDir.resolve("test").also { base ->
|
||||
base.mkdir()
|
||||
listOf("User.java", "Address.java", "Observable.java").map {
|
||||
TEST_DATA_DIR.resolve(it).copyTo(base.resolve(it))
|
||||
}
|
||||
}
|
||||
|
||||
val outputDir = tmp.newFolder()
|
||||
val incrementalCacheDir = tmp.newFolder()
|
||||
val options = KaptOptions.Builder().apply {
|
||||
projectBaseDir = tmp.newFolder()
|
||||
projectBaseDir = projectBaseDirFirstRun
|
||||
javaSourceRoots.add(sourcesDir)
|
||||
|
||||
sourcesOutputDir = outputDir
|
||||
@@ -192,7 +198,7 @@ class IncrementalKaptTest {
|
||||
}
|
||||
|
||||
val optionsForSecondRun = KaptOptions.Builder().apply {
|
||||
projectBaseDir = tmp.newFolder()
|
||||
projectBaseDir = projectBaseDirSecondRun
|
||||
javaSourceRoots.add(sourcesDir)
|
||||
|
||||
sourcesOutputDir = outputDir
|
||||
@@ -219,4 +225,4 @@ class IncrementalKaptTest {
|
||||
|
||||
assertTrue(outputDir.resolve("test/UserGenerated.java").exists())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-20
@@ -3,14 +3,12 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.DeclaredProcType
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.getIncrementalProcessorsFromClasspath
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
@@ -22,15 +20,11 @@ class IncrementalProcessorDiscoveryTest {
|
||||
Input1Processor3,DYNAMIC
|
||||
Input1Processor4,UNKNOWN
|
||||
Input1Processor5 this is malformed input
|
||||
""".trimIndent();
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
var tmp = TemporaryFolder()
|
||||
""".trimIndent()
|
||||
|
||||
@Test
|
||||
fun locateInJars() {
|
||||
val inputJar = tmp.root.resolve("inputJar.jar")
|
||||
fun locateInJars(@TempDir tmp: File) {
|
||||
val inputJar = tmp.resolve("inputJar.jar")
|
||||
ZipOutputStream(inputJar.outputStream()).use {
|
||||
it.putNextEntry(ZipEntry("META-INF/gradle/incremental.annotation.processors"))
|
||||
it.write(markerFileContent.toByteArray())
|
||||
@@ -53,8 +47,8 @@ class IncrementalProcessorDiscoveryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun locateInDir() {
|
||||
val inputDir = tmp.root.resolve("inputDir")
|
||||
fun locateInDir(@TempDir tmp: File) {
|
||||
val inputDir = tmp.resolve("inputDir")
|
||||
inputDir.resolve("META-INF/gradle/incremental.annotation.processors").let {
|
||||
it.parentFile.mkdirs()
|
||||
it.writeText(markerFileContent)
|
||||
@@ -76,15 +70,15 @@ class IncrementalProcessorDiscoveryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun locateInJarsAndDirs() {
|
||||
val inputJar = tmp.root.resolve("inputJar.jar")
|
||||
fun locateInJarsAndDirs(@TempDir tmp: File) {
|
||||
val inputJar = tmp.resolve("inputJar.jar")
|
||||
ZipOutputStream(inputJar.outputStream()).use {
|
||||
it.putNextEntry(ZipEntry("META-INF/gradle/incremental.annotation.processors"))
|
||||
it.write("InputJarProcessor,ISOLATING".toByteArray())
|
||||
it.closeEntry()
|
||||
}
|
||||
|
||||
val inputDir = tmp.root.resolve("inputDir")
|
||||
val inputDir = tmp.resolve("inputDir")
|
||||
inputDir.resolve("META-INF/gradle/incremental.annotation.processors").let {
|
||||
it.parentFile.mkdirs()
|
||||
it.writeText("InputDirProcessor,DYNAMIC")
|
||||
@@ -102,4 +96,4 @@ class IncrementalProcessorDiscoveryTest {
|
||||
info
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-20
@@ -3,36 +3,30 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.JavaClassCacheManager
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.MentionedTypesTaskListener
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.SourceFileStructure
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newCacheFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newGeneratedSourcesFolder
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
|
||||
private val MY_TEST_DIR = File("plugins/kapt3/kapt3-base/testData/runner/incremental/complex/inherited")
|
||||
|
||||
class TestInheritedAnnotation {
|
||||
|
||||
companion object {
|
||||
@ClassRule
|
||||
@JvmField
|
||||
var tmp = TemporaryFolder()
|
||||
|
||||
private lateinit var cache: JavaClassCacheManager
|
||||
private lateinit var generatedSources: File
|
||||
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setUp() {
|
||||
val classpathHistory = tmp.newFolder()
|
||||
cache = JavaClassCacheManager(tmp.newFolder())
|
||||
generatedSources = tmp.newFolder()
|
||||
@BeforeAll
|
||||
fun setUp(@TempDir tmp: File) {
|
||||
val classpathHistory = tmp.newFolder("classpathHistory")
|
||||
cache = JavaClassCacheManager(tmp.newCacheFolder())
|
||||
generatedSources = tmp.newGeneratedSourcesFolder()
|
||||
cache.close()
|
||||
classpathHistory.resolve("0").createNewFile()
|
||||
val processor = SimpleProcessor().toAggregating()
|
||||
@@ -64,4 +58,4 @@ class TestInheritedAnnotation {
|
||||
), shouldInheritAnnotation.getMentionedTypes()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-21
@@ -3,28 +3,13 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.RuntimeProcType
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
|
||||
class IsolationgIncrementalProcessorTest {
|
||||
@JvmField
|
||||
@Rule
|
||||
val tmp: TemporaryFolder = TemporaryFolder()
|
||||
|
||||
private lateinit var generatedSources: File
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
generatedSources = tmp.newFolder()
|
||||
}
|
||||
|
||||
class IsolationgIncrementalProcessorTest : AbstractTestWithGeneratedSourcesDir() {
|
||||
@Test
|
||||
fun testDependenciesRecorded() {
|
||||
val srcFiles = listOf("User.java", "Address.java", "Observable.java").map { File(TEST_DATA_DIR, it) }
|
||||
@@ -49,7 +34,7 @@ class IsolationgIncrementalProcessorTest {
|
||||
runAnnotationProcessing(srcFiles, listOf(isolating), generatedSources)
|
||||
|
||||
assertEquals(RuntimeProcType.ISOLATING, isolating.getRuntimeType())
|
||||
assertEquals(emptyMap<File, File>(), isolating.getGeneratedToSources())
|
||||
assertEquals(emptyMap<File, String?>(), isolating.getGeneratedToSources())
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,7 +65,7 @@ class IsolationgIncrementalProcessorTest {
|
||||
runAnnotationProcessing(srcFiles, listOf(isolating), generatedSources)
|
||||
|
||||
assertEquals(RuntimeProcType.NON_INCREMENTAL, isolating.getRuntimeType())
|
||||
assertEquals(emptyMap<File, File>(), isolating.getGeneratedToSources())
|
||||
assertEquals(emptyMap<File, String?>(), isolating.getGeneratedToSources())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+29
-22
@@ -3,30 +3,26 @@
|
||||
* 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.kapt3.base.incremental;
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newCompiledSourcesFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newFolder
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
|
||||
class JavaClassCacheManagerTest {
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
var tmp = TemporaryFolder()
|
||||
|
||||
private lateinit var cache: JavaClassCacheManager
|
||||
private lateinit var cacheDir: File
|
||||
private lateinit var compiledSources: List<File>
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
cacheDir = tmp.newFolder()
|
||||
compiledSources = listOf(tmp.newFolder().also { it.resolve(TEST_PACKAGE_NAME).mkdir() })
|
||||
@BeforeEach
|
||||
fun setUp(@TempDir tmp: File) {
|
||||
cacheDir = tmp.newFolder("cacheDir")
|
||||
compiledSources = listOf(tmp.newCompiledSourcesFolder().also { it.resolve(TEST_PACKAGE_NAME).mkdir() })
|
||||
cache = JavaClassCacheManager(cacheDir)
|
||||
}
|
||||
|
||||
@@ -60,8 +56,10 @@ class JavaClassCacheManagerTest {
|
||||
}
|
||||
prepareForIncremental()
|
||||
|
||||
val dirtyFiles =
|
||||
cache.invalidateAndGetDirtyFiles(listOf(File("Mentioned.java").absoluteFile), emptyList(), compiledSources) as SourcesToReprocess.Incremental
|
||||
val dirtyFiles = cache.invalidateAndGetDirtyFiles(
|
||||
listOf(File("Mentioned.java").absoluteFile),
|
||||
emptyList(), compiledSources
|
||||
) as SourcesToReprocess.Incremental
|
||||
assertEquals(
|
||||
listOf(
|
||||
File("Mentioned.java").absoluteFile,
|
||||
@@ -93,7 +91,11 @@ class JavaClassCacheManagerTest {
|
||||
prepareForIncremental()
|
||||
|
||||
val dirtyFiles =
|
||||
cache.invalidateAndGetDirtyFiles(listOf(File("Mentioned.java").absoluteFile), emptyList(), compiledSources) as SourcesToReprocess.Incremental
|
||||
cache.invalidateAndGetDirtyFiles(
|
||||
listOf(File("Mentioned.java").absoluteFile),
|
||||
emptyList(),
|
||||
compiledSources
|
||||
) as SourcesToReprocess.Incremental
|
||||
assertEquals(
|
||||
listOf(
|
||||
File("Mentioned.java").absoluteFile,
|
||||
@@ -126,7 +128,11 @@ class JavaClassCacheManagerTest {
|
||||
prepareForIncremental()
|
||||
|
||||
val dirtyFiles =
|
||||
cache.invalidateAndGetDirtyFiles(listOf(File("TwoTypes.java").absoluteFile), emptyList(), compiledSources) as SourcesToReprocess.Incremental
|
||||
cache.invalidateAndGetDirtyFiles(
|
||||
listOf(File("TwoTypes.java").absoluteFile),
|
||||
emptyList(),
|
||||
compiledSources
|
||||
) as SourcesToReprocess.Incremental
|
||||
assertEquals(
|
||||
listOf(
|
||||
File("TwoTypes.java").absoluteFile,
|
||||
@@ -146,7 +152,8 @@ class JavaClassCacheManagerTest {
|
||||
}
|
||||
prepareForIncremental()
|
||||
|
||||
val dirtyFiles = cache.invalidateAndGetDirtyFiles(listOf(), listOf("test/Mentioned"), compiledSources) as SourcesToReprocess.Incremental
|
||||
val dirtyFiles =
|
||||
cache.invalidateAndGetDirtyFiles(listOf(), listOf("test/Mentioned"), compiledSources) as SourcesToReprocess.Incremental
|
||||
assertEquals(listOf(File("Src.java").absoluteFile), dirtyFiles.toReprocess)
|
||||
}
|
||||
|
||||
@@ -187,4 +194,4 @@ class JavaClassCacheManagerTest {
|
||||
}
|
||||
}
|
||||
|
||||
private const val TEST_PACKAGE_NAME = "test"
|
||||
private const val TEST_PACKAGE_NAME = "test"
|
||||
|
||||
+15
-21
@@ -3,16 +3,15 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.JavaClassCacheManager
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.MentionedTypesTaskListener
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.SourceFileStructure
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newCacheFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newGeneratedSourcesFolder
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
|
||||
private val MY_TEST_DIR = File("plugins/kapt3/kapt3-base/testData/runner/incremental/constants")
|
||||
@@ -20,21 +19,17 @@ private val MY_TEST_DIR = File("plugins/kapt3/kapt3-base/testData/runner/increme
|
||||
class ReferencedConstantsTest {
|
||||
|
||||
companion object {
|
||||
@ClassRule
|
||||
@JvmField
|
||||
var tmp = TemporaryFolder()
|
||||
|
||||
private lateinit var cache: JavaClassCacheManager
|
||||
private lateinit var generatedSources: File
|
||||
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setUp() {
|
||||
val compiledClasses = tmp.newFolder()
|
||||
@BeforeAll
|
||||
fun setUp(@TempDir tmp: File) {
|
||||
val compiledClasses = tmp.newFolder("compiledClasses")
|
||||
compileSources(listOf(MY_TEST_DIR.resolve("CKlass.java")), compiledClasses)
|
||||
|
||||
cache = JavaClassCacheManager(tmp.newFolder())
|
||||
generatedSources = tmp.newFolder()
|
||||
cache = JavaClassCacheManager(tmp.newCacheFolder())
|
||||
generatedSources = tmp.newGeneratedSourcesFolder()
|
||||
cache.close()
|
||||
val processor = SimpleProcessor().toAggregating()
|
||||
val srcFiles = listOf(
|
||||
@@ -77,8 +72,7 @@ class ReferencedConstantsTest {
|
||||
assertEquals(emptySet<String>(), annotationA.getMentionedAnnotations())
|
||||
assertEquals(emptySet<String>(), annotationA.getPrivateTypes())
|
||||
assertEquals(setOf("test.AnnotationA"), annotationA.getMentionedTypes())
|
||||
assertEquals(mapOf("test.B" to setOf("INT_VALUE")), annotationA.getMentionedConstants()
|
||||
)
|
||||
assertEquals(mapOf("test.B" to setOf("INT_VALUE")), annotationA.getMentionedConstants())
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,4 +90,4 @@ class ReferencedConstantsTest {
|
||||
), annotated.getMentionedConstants()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-18
@@ -3,16 +3,14 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.JavaClassCacheManager
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.MentionedTypesTaskListener
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.SourceFileStructure
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newCacheFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newGeneratedSourcesFolder
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
|
||||
private val MY_TEST_DIR = File("plugins/kapt3/kapt3-base/testData/runner/incremental/complex")
|
||||
@@ -20,18 +18,14 @@ private val MY_TEST_DIR = File("plugins/kapt3/kapt3-base/testData/runner/increme
|
||||
class TestComplexIncrementalAptCache {
|
||||
|
||||
companion object {
|
||||
@ClassRule
|
||||
@JvmField
|
||||
var tmp = TemporaryFolder()
|
||||
|
||||
private lateinit var cache: JavaClassCacheManager
|
||||
private lateinit var generatedSources: File
|
||||
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setUp() {
|
||||
cache = JavaClassCacheManager(tmp.newFolder())
|
||||
generatedSources = tmp.newFolder()
|
||||
@BeforeAll
|
||||
fun setUp(@TempDir tmp: File) {
|
||||
cache = JavaClassCacheManager(tmp.newCacheFolder())
|
||||
generatedSources = tmp.newGeneratedSourcesFolder()
|
||||
cache.close()
|
||||
val processor = SimpleProcessor().toAggregating()
|
||||
val srcFiles = listOf(
|
||||
@@ -199,4 +193,4 @@ class TestComplexIncrementalAptCache {
|
||||
), genericNumber.getMentionedTypes()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-18
@@ -3,31 +3,27 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.*
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newCacheFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newCompiledSourcesFolder
|
||||
import org.jetbrains.kotlin.kapt3.base.newGeneratedSourcesFolder
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.File
|
||||
|
||||
class TestSimpleIncrementalAptCache {
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
var tmp = TemporaryFolder()
|
||||
|
||||
private lateinit var cache: JavaClassCacheManager
|
||||
private lateinit var generatedSources: File
|
||||
private lateinit var compiledSources: List<File>
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
cache = JavaClassCacheManager(tmp.newFolder())
|
||||
generatedSources = tmp.newFolder()
|
||||
compiledSources = listOf(tmp.newFolder().also { it.resolve(TEST_PACKAGE_NAME).mkdir() })
|
||||
@BeforeEach
|
||||
fun setUp(@TempDir tmp: File) {
|
||||
cache = JavaClassCacheManager(tmp.newCacheFolder())
|
||||
generatedSources = tmp.newGeneratedSourcesFolder()
|
||||
compiledSources = listOf(tmp.newCompiledSourcesFolder().also { it.resolve(TEST_PACKAGE_NAME).mkdir() })
|
||||
cache.close()
|
||||
}
|
||||
|
||||
@@ -90,4 +86,4 @@ class TestSimpleIncrementalAptCache {
|
||||
}
|
||||
}
|
||||
|
||||
private const val TEST_PACKAGE_NAME = "test"
|
||||
private const val TEST_PACKAGE_NAME = "test"
|
||||
|
||||
+2
-5
@@ -3,14 +3,11 @@
|
||||
* 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.kapt.base.test.org.jetbrains.kotlin.kapt3.base.incremental
|
||||
package org.jetbrains.kotlin.kapt3.base.incremental
|
||||
|
||||
import com.sun.source.util.TaskListener
|
||||
import com.sun.source.util.Trees
|
||||
import com.sun.tools.javac.api.JavacTaskImpl
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.DeclaredProcType
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.RuntimeProcType
|
||||
import org.jetbrains.kotlin.kapt3.base.util.WriterBackedKaptLogger
|
||||
import java.io.File
|
||||
import javax.annotation.processing.AbstractProcessor
|
||||
@@ -164,4 +161,4 @@ open class ReportTwoOriginElements : SimpleProcessor() {
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,19 +9,23 @@ dependencies {
|
||||
compileOnly(intellijCore())
|
||||
|
||||
testImplementation(intellijCore())
|
||||
testApi(projectTests(":compiler:tests-common"))
|
||||
testApi(projectTests(":compiler"))
|
||||
testApi(commonDependency("junit:junit"))
|
||||
testApi(projectTests(":compiler:test-infrastructure-utils"))
|
||||
testApi(projectTests(":compiler:tests-common-new"))
|
||||
testApiJUnit5()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { projectDefault() }
|
||||
"test" {
|
||||
projectDefault()
|
||||
generatedTestDir()
|
||||
}
|
||||
}
|
||||
|
||||
testsJar()
|
||||
|
||||
projectTest {
|
||||
useJUnitPlatform()
|
||||
workingDir = rootDir
|
||||
dependsOn(":dist")
|
||||
}
|
||||
|
||||
+4
-8
@@ -4,21 +4,17 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.kapt.cli.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.kapt.cli.transformArgs
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.runner.RunWith
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions
|
||||
import java.io.File
|
||||
|
||||
private val LINE_SEPARATOR: String = System.getProperty("line.separator")
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners::class)
|
||||
abstract class AbstractArgumentParsingTest : TestCase() {
|
||||
fun doTest(filePath: String) {
|
||||
abstract class AbstractArgumentParsingTest {
|
||||
fun runTest(filePath: String) {
|
||||
val testFile = File(filePath)
|
||||
|
||||
val sections = Section.parse(testFile)
|
||||
@@ -29,7 +25,7 @@ abstract class AbstractArgumentParsingTest : TestCase() {
|
||||
val actualAfter = if (messageCollector.hasErrors()) messageCollector.toString() else transformedArgs.joinToString(LINE_SEPARATOR)
|
||||
val actual = sections.replacingSection("after", actualAfter).render()
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(testFile, actual)
|
||||
JUnit5Assertions.assertEqualsToFile(testFile, actual)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+24
-11
@@ -7,21 +7,34 @@ package org.jetbrains.kotlin.kapt.cli.test
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import org.jetbrains.kotlin.cli.common.arguments.readArgumentsFromArgFile
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
import org.junit.runner.RunWith
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.TestInfo
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners::class)
|
||||
abstract class AbstractKaptToolIntegrationTest : TestCaseWithTmpdir() {
|
||||
fun doTest(filePath: String) {
|
||||
abstract class AbstractKaptToolIntegrationTest {
|
||||
private lateinit var tmpdir: File
|
||||
private lateinit var testInfo: TestInfo
|
||||
|
||||
@BeforeEach
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun setUp(testInfo: TestInfo) {
|
||||
this.testInfo = testInfo
|
||||
tmpdir = KtTestUtil.tmpDirForTest(
|
||||
testInfo.testClass.getOrNull()?.simpleName ?: "TEST",
|
||||
testInfo.displayName
|
||||
)
|
||||
}
|
||||
|
||||
fun runTest(filePath: String) {
|
||||
val testDir = File(filePath)
|
||||
val testFile = File(testDir, "build.txt")
|
||||
assert(testFile.isFile) { "build.txt doesn't exist" }
|
||||
|
||||
testDir.listFiles().forEach { it.copyRecursively(File(tmpdir, it.name)) }
|
||||
testDir.listFiles()?.forEach { it.copyRecursively(File(tmpdir, it.name)) }
|
||||
doTestInTempDirectory(testFile, File(tmpdir, testFile.name))
|
||||
}
|
||||
|
||||
@@ -44,7 +57,7 @@ abstract class AbstractKaptToolIntegrationTest : TestCaseWithTmpdir() {
|
||||
}
|
||||
} catch (e: GotResult) {
|
||||
val actual = sections.replacingSection("after", e.actual).render()
|
||||
KotlinTestUtils.assertEqualsToFile(originalTestFile, actual)
|
||||
JUnit5Assertions.assertEqualsToFile(originalTestFile, actual)
|
||||
return
|
||||
} catch (e: Throwable) {
|
||||
throw RuntimeException("Section ${section.name} failed:\n${section.content}", e)
|
||||
@@ -82,7 +95,7 @@ abstract class AbstractKaptToolIntegrationTest : TestCaseWithTmpdir() {
|
||||
}
|
||||
|
||||
private fun runProcess(executablePath: String, args: List<String>, outputFile: File = File(tmpdir, "processOutput.txt")) {
|
||||
fun err(message: String): Nothing = error("$message: $name (${args.joinToString(" ")})")
|
||||
fun err(message: String): Nothing = error("$message: ${testInfo.displayName} (${args.joinToString(" ")})")
|
||||
|
||||
outputFile.delete()
|
||||
|
||||
@@ -126,4 +139,4 @@ private fun preprocessPathSeparators(text: String): String = buildString {
|
||||
val transformed = if (line.startsWith("-cp ")) line.replace(':', File.pathSeparatorChar) else line
|
||||
appendLine(transformed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -6,49 +6,49 @@
|
||||
package org.jetbrains.kotlin.kapt.cli.test;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("plugins/kapt3/kapt3-cli/testData/argumentParsing")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class ArgumentParsingTestGenerated extends AbstractArgumentParsingTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInArgumentParsing() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/kapt3/kapt3-cli/testData/argumentParsing"), Pattern.compile("^(.+)\\.txt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("errorFlag.txt")
|
||||
public void testErrorFlag() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/errorFlag.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("errorKeyValue.txt")
|
||||
public void testErrorKeyValue() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/errorKeyValue.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("errorValue.txt")
|
||||
public void testErrorValue() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/errorValue.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlincHelp.txt")
|
||||
public void testKotlincHelp() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/kotlincHelp.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.txt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/simple.txt");
|
||||
+15
-9
@@ -6,79 +6,85 @@
|
||||
package org.jetbrains.kotlin.kapt.cli.test;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("plugins/kapt3/kapt3-cli/testData/integration")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KaptToolIntegrationTestGenerated extends AbstractKaptToolIntegrationTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInIntegration() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/kapt3/kapt3-cli/testData/integration"), Pattern.compile("^([^\\.]+)$"), null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argfile")
|
||||
public void testArgfile() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/argfile/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("correctErrorTypesOff")
|
||||
public void testCorrectErrorTypesOff() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/correctErrorTypesOff/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("correctErrorTypesOn")
|
||||
public void testCorrectErrorTypesOn() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/correctErrorTypesOn/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultPackage")
|
||||
public void testDefaultPackage() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/defaultPackage/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinFileGeneration")
|
||||
public void testKotlinFileGeneration() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGeneration/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinFileGenerationCorrectErrorTypes")
|
||||
public void testKotlinFileGenerationCorrectErrorTypes() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinFileGenerationDefaultOutput")
|
||||
public void testKotlinFileGenerationDefaultOutput() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationDefaultOutput/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt33800")
|
||||
public void testKt33800() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/kt33800/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("separateStubAptCompilation")
|
||||
public void testSeparateStubAptCompilation() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/separateStubAptCompilation/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/simple/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withoutService")
|
||||
public void testWithoutService() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/withoutService/");
|
||||
Reference in New Issue
Block a user