[KAPT] Migrate tests in kapt3-base and kapt3-cli to JUnit 5

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