From fdf1b8b1c01e826cbecd2766fa9de6488e5d8be4 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 6 Jul 2022 12:59:32 +0300 Subject: [PATCH] [KAPT] Migrate tests in kapt3-base and kapt3-cli to JUnit 5 --- .../kotlin/generators/tests/GenerateTests.kt | 20 ++--- plugins/kapt3/kapt3-base/build.gradle.kts | 7 +- .../kapt3-base/test/JavaKaptContextTest.kt | 18 +++-- .../kapt3/kapt3-base/test/KaptPathsTest.kt | 12 +-- .../jetbrains/kotlin/kapt3/base/FileUtils.kt | 23 ++++++ .../kotlin/kapt3/base/ProcessorLoaderTest.kt | 60 +++++++------- .../AbstractTestWithGeneratedSourcesDir.kt | 17 ++++ .../AggregatingIncrementalProcessorTest.kt | 27 ++----- ...otationProcessorDependencyCollectorTest.kt | 14 ++-- .../DynamicIncrementalProcessorTest.kt | 28 ++----- .../base/incremental/IncrementalKaptTest.kt | 78 ++++++++++--------- .../IncrementalProcessorDiscoveryTest.kt | 34 ++++---- .../incremental/InheritedAnnotationTest.kt | 34 ++++---- .../IsolatingIncrementalProcessorTest.kt | 27 ++----- .../incremental/JavaClassCacheManagerTest.kt | 51 ++++++------ .../incremental/ReferencedContantsTest.kt | 36 ++++----- .../TestComplexIncrementalAptCache.kt | 30 +++---- .../TestSimpleIncrementalAptCache.kt | 32 ++++---- .../kotlin/kapt3/base/incremental/fixtures.kt | 7 +- plugins/kapt3/kapt3-cli/build.gradle.kts | 12 ++- .../cli/test/AbstractArgumentParsingTest.kt | 12 +-- .../test/AbstractKaptToolIntegrationTest.kt | 35 ++++++--- .../test/ArgumentParsingTestGenerated.java | 18 ++--- .../KaptToolIntegrationTestGenerated.java | 24 +++--- 24 files changed, 329 insertions(+), 327 deletions(-) create mode 100644 plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/FileUtils.kt create mode 100644 plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AbstractTestWithGeneratedSourcesDir.kt rename plugins/kapt3/kapt3-cli/{test => tests-gen}/org/jetbrains/kotlin/kapt/cli/test/ArgumentParsingTestGenerated.java (80%) rename plugins/kapt3/kapt3-cli/{test => tests-gen}/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java (87%) diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 31fc34a4b72..f7e9138d6c0 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -212,16 +212,6 @@ fun main(args: Array) { } } - testGroup("plugins/kapt3/kapt3-cli/test", "plugins/kapt3/kapt3-cli/testData") { - testClass { - model("argumentParsing", extension = "txt") - } - - testClass { - model("integration", recursive = false, extension = null) - } - } - testGroup("plugins/sam-with-receiver/tests-gen", "plugins/sam-with-receiver/testData") { testClass { model("script", extension = "kts") @@ -464,5 +454,15 @@ fun main(args: Array) { model("codegen", excludedPattern = excludedFirTestdataPattern) } } + + testGroup("plugins/kapt3/kapt3-cli/tests-gen", "plugins/kapt3/kapt3-cli/testData") { + testClass { + model("argumentParsing", extension = "txt") + } + + testClass { + model("integration", recursive = false, extension = null) + } + } } } diff --git a/plugins/kapt3/kapt3-base/build.gradle.kts b/plugins/kapt3/kapt3-base/build.gradle.kts index b929c44001a..8a07d3e9920 100644 --- a/plugins/kapt3/kapt3-base/build.gradle.kts +++ b/plugins/kapt3/kapt3-base/build.gradle.kts @@ -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") -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/JavaKaptContextTest.kt b/plugins/kapt3/kapt3-base/test/JavaKaptContextTest.kt index d1c7ec7a33e..8feae8d9dea 100644 --- a/plugins/kapt3/kapt3-base/test/JavaKaptContextTest.kt +++ b/plugins/kapt3/kapt3-base/test/JavaKaptContextTest.kt @@ -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) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/KaptPathsTest.kt b/plugins/kapt3/kapt3-base/test/KaptPathsTest.kt index 08e51822afb..02b52f7fe6b 100644 --- a/plugins/kapt3/kapt3-base/test/KaptPathsTest.kt +++ b/plugins/kapt3/kapt3-base/test/KaptPathsTest.kt @@ -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() } } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/FileUtils.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/FileUtils.kt new file mode 100644 index 00000000000..df8963b4121 --- /dev/null +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/FileUtils.kt @@ -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() } +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/ProcessorLoaderTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/ProcessorLoaderTest.kt index 63b958e9f88..ffb95965a97 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/ProcessorLoaderTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/ProcessorLoaderTest.kt @@ -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()) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AbstractTestWithGeneratedSourcesDir.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AbstractTestWithGeneratedSourcesDir.kt new file mode 100644 index 00000000000..f0bb7269aac --- /dev/null +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AbstractTestWithGeneratedSourcesDir.kt @@ -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!! +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AggregatingIncrementalProcessorTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AggregatingIncrementalProcessorTest.kt index 5e2bead77b8..887f6a7875f 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AggregatingIncrementalProcessorTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AggregatingIncrementalProcessorTest.kt @@ -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(), aggregating.getGeneratedToSources()) + assertEquals(emptyMap(), aggregating.getGeneratedToSources()) } @Test @@ -72,4 +57,4 @@ class AggregatingIncrementalProcessorTest { aggregating.getGeneratedToSources() ) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AnnotationProcessorDependencyCollectorTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AnnotationProcessorDependencyCollectorTest.kt index c714444746e..1c2fb27d4c4 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AnnotationProcessorDependencyCollectorTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/AnnotationProcessorDependencyCollectorTest.kt @@ -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()) + assertEquals(isolating.getGeneratedToSources(), emptyMap()) 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()) + assertEquals(nonIncremental.getGeneratedToSources(), emptyMap()) } } diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/DynamicIncrementalProcessorTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/DynamicIncrementalProcessorTest.kt index 3a47751a47d..664d8ead785 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/DynamicIncrementalProcessorTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/DynamicIncrementalProcessorTest.kt @@ -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(), + emptyMap(), dynamic.getGeneratedToSources() ) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IncrementalKaptTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IncrementalKaptTest.kt index 236b1afa84d..f57ee0b8542 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IncrementalKaptTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IncrementalKaptTest.kt @@ -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()) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IncrementalProcessorDiscoveryTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IncrementalProcessorDiscoveryTest.kt index 52ee769db55..21757bde16a 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IncrementalProcessorDiscoveryTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IncrementalProcessorDiscoveryTest.kt @@ -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 ) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/InheritedAnnotationTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/InheritedAnnotationTest.kt index 0ee61330b1a..dcc6d5111b7 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/InheritedAnnotationTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/InheritedAnnotationTest.kt @@ -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() ) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IsolatingIncrementalProcessorTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IsolatingIncrementalProcessorTest.kt index 06b28649244..4ad083b4e66 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IsolatingIncrementalProcessorTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/IsolatingIncrementalProcessorTest.kt @@ -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(), isolating.getGeneratedToSources()) + assertEquals(emptyMap(), isolating.getGeneratedToSources()) } @Test @@ -80,7 +65,7 @@ class IsolationgIncrementalProcessorTest { runAnnotationProcessing(srcFiles, listOf(isolating), generatedSources) assertEquals(RuntimeProcType.NON_INCREMENTAL, isolating.getRuntimeType()) - assertEquals(emptyMap(), isolating.getGeneratedToSources()) + assertEquals(emptyMap(), isolating.getGeneratedToSources()) } @Test diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/JavaClassCacheManagerTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/JavaClassCacheManagerTest.kt index 998c600e66e..a4ad7b0a84c 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/JavaClassCacheManagerTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/JavaClassCacheManagerTest.kt @@ -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 - @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" \ No newline at end of file +private const val TEST_PACKAGE_NAME = "test" diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/ReferencedContantsTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/ReferencedContantsTest.kt index 1aceb74552c..029aad11f9a 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/ReferencedContantsTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/ReferencedContantsTest.kt @@ -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(), annotationA.getMentionedAnnotations()) assertEquals(emptySet(), 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() ) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestComplexIncrementalAptCache.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestComplexIncrementalAptCache.kt index d5dbb5bb956..4027033b00a 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestComplexIncrementalAptCache.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestComplexIncrementalAptCache.kt @@ -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() ) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestSimpleIncrementalAptCache.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestSimpleIncrementalAptCache.kt index 7e786c5cf9b..2831ee08f72 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestSimpleIncrementalAptCache.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestSimpleIncrementalAptCache.kt @@ -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 - @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" \ No newline at end of file +private const val TEST_PACKAGE_NAME = "test" diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/fixtures.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/fixtures.kt index ed29352ce5d..01f6bbe406f 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/fixtures.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/fixtures.kt @@ -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 } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-cli/build.gradle.kts b/plugins/kapt3/kapt3-cli/build.gradle.kts index 18242223601..e6ecdd08e8c 100644 --- a/plugins/kapt3/kapt3-cli/build.gradle.kts +++ b/plugins/kapt3/kapt3-cli/build.gradle.kts @@ -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") } diff --git a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt index 6186619eb29..cb7c8d48e6d 100644 --- a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt +++ b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt @@ -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) } } diff --git a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractKaptToolIntegrationTest.kt b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractKaptToolIntegrationTest.kt index 5863eaadbb3..bb4c88b966e 100644 --- a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractKaptToolIntegrationTest.kt +++ b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractKaptToolIntegrationTest.kt @@ -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, 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) } -} \ No newline at end of file +} diff --git a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/ArgumentParsingTestGenerated.java b/plugins/kapt3/kapt3-cli/tests-gen/org/jetbrains/kotlin/kapt/cli/test/ArgumentParsingTestGenerated.java similarity index 80% rename from plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/ArgumentParsingTestGenerated.java rename to plugins/kapt3/kapt3-cli/tests-gen/org/jetbrains/kotlin/kapt/cli/test/ArgumentParsingTestGenerated.java index 8fc6d667ef1..4b564c26b24 100644 --- a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/ArgumentParsingTestGenerated.java +++ b/plugins/kapt3/kapt3-cli/tests-gen/org/jetbrains/kotlin/kapt/cli/test/ArgumentParsingTestGenerated.java @@ -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"); diff --git a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java b/plugins/kapt3/kapt3-cli/tests-gen/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java similarity index 87% rename from plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java rename to plugins/kapt3/kapt3-cli/tests-gen/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java index af01cdbe798..befbbcd6e2b 100644 --- a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java +++ b/plugins/kapt3/kapt3-cli/tests-gen/org/jetbrains/kotlin/kapt/cli/test/KaptToolIntegrationTestGenerated.java @@ -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/");