[Test] Migrate tests of foreign annotations to new infrastructure

This commit includes:
- test runners for foreign annotation tests
- minor changes testdata related to changed directives syntax
- dropping tests with javac integration: old javac tests actually ran
    compiler without javac because of bug in configuration, so some
    nullability annotations features are not supported in javac mode.
    It's fine to drop it since javac mode is not fully supported
    by compiler
This commit is contained in:
Dmitriy Novozhilov
2020-12-22 16:08:14 +03:00
committed by TeamCityServer
parent ef3d966d53
commit 660c438ebe
176 changed files with 2451 additions and 2970 deletions
@@ -1,32 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.checkers.javac
import org.jetbrains.kotlin.checkers.AbstractForeignAnnotationsTest
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import java.io.File
abstract class AbstractJavacForeignAnnotationsTest : AbstractForeignAnnotationsTest() {
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: List<TestFile>) {
val groupedByModule = files.groupBy(TestFile::module)
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
environment.registerJavac(kotlinFiles = allKtFiles)
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
}
}
@@ -1,37 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.checkers.javac
import org.jetbrains.kotlin.checkers.AbstractForeignJava8AnnotationsTest
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import java.io.File
abstract class AbstractJavacForeignJava8AnnotationsTest : AbstractForeignJava8AnnotationsTest() {
override fun shouldSkipTest(wholeFile: File, files: List<TestFile>): Boolean {
return isSkipJavacTest(wholeFile)
}
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: List<TestFile>) {
val groupedByModule = files.groupBy(TestFile::module)
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
environment.registerJavac(kotlinFiles = allKtFiles)
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
}
}
@@ -1,53 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.checkers
import org.jetbrains.kotlin.codegen.CodegenTestUtil
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.util.JUnit4Assertions
import org.jetbrains.kotlin.test.util.KtTestUtil
import java.io.File
abstract class AbstractForeignAnnotationsNoAnnotationInClasspathTest : AbstractForeignAnnotationsTest() {
// This should be executed after setUp runs, since setUp changes the root folder
// for temporary files.
private val compiledJavaPath by lazy {
KtTestUtil.tmpDir("java-compiled-files")
}
override fun getExtraClasspath(): List<File> {
val foreignAnnotations = createJarWithForeignAnnotations()
val testAnnotations = compileTestAnnotations(foreignAnnotations)
val additionalClasspath = (foreignAnnotations + testAnnotations).map { it.path }
CodegenTestUtil.compileJava(
CodegenTestUtil.findJavaSourcesInDirectory(javaFilesDir),
additionalClasspath, emptyList(),
compiledJavaPath,
JUnit4Assertions
)
return listOf(compiledJavaPath) + testAnnotations
}
override fun shouldSkipTest(wholeFile: File, files: List<TestFile>): Boolean {
return files.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.expectedText, "// SOURCE_RETENTION_ANNOTATIONS") }
}
override fun isJavaSourceRootNeeded() = false
override fun skipDescriptorsValidation() = true
}
@@ -1,98 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.checkers
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.MockLibraryUtilExt
import org.jetbrains.kotlin.utils.JavaTypeEnhancementState
import org.jetbrains.kotlin.utils.ReportLevel
import java.io.File
const val FOREIGN_ANNOTATIONS_SOURCES_PATH = "third-party/annotations"
const val FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH = "third-party/jdk8-annotations"
const val TEST_ANNOTATIONS_SOURCE_PATH = "compiler/testData/foreignAnnotations/testAnnotations"
abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() {
override fun getExtraClasspath(): List<File> {
val foreignAnnotations = createJarWithForeignAnnotations()
return foreignAnnotations + compileTestAnnotations(foreignAnnotations)
}
protected fun compileTestAnnotations(extraClassPath: List<File>): List<File> =
listOf(MockLibraryUtilExt.compileJavaFilesLibraryToJar(
TEST_ANNOTATIONS_SOURCE_PATH,
"test-foreign-annotations",
extraOptions = listOf("-Xallow-kotlin-package"),
extraClasspath = extraClassPath.map { it.path }
))
protected fun createJarWithForeignAnnotations(): List<File> = listOf(
MockLibraryUtilExt.compileJavaFilesLibraryToJar(annotationsPath, "foreign-annotations"),
ForTestCompileRuntime.jvmAnnotationsForTests()
)
protected open val annotationsPath: String
get() = FOREIGN_ANNOTATIONS_SOURCES_PATH
override fun loadLanguageVersionSettings(module: List<TestFile>): LanguageVersionSettings {
val analysisFlags = loadAnalysisFlags(module)
return CompilerTestLanguageVersionSettings(
DEFAULT_DIAGNOSTIC_TESTS_FEATURES,
ApiVersion.LATEST_STABLE,
LanguageVersion.LATEST_STABLE,
analysisFlags = analysisFlags
)
}
private fun loadAnalysisFlags(module: List<TestFile>): Map<AnalysisFlag<*>, Any?> {
val globalState = module.getDirectiveValue(JSR305_GLOBAL_DIRECTIVE) ?: ReportLevel.STRICT
val migrationState = module.getDirectiveValue(JSR305_MIGRATION_DIRECTIVE)
val userAnnotationsState = module.flatMap {
InTextDirectivesUtils.findListWithPrefixes(it.expectedText, JSR305_SPECIAL_DIRECTIVE)
}.mapNotNull {
val (name, stateDescription) = it.split(":").takeIf { it.size == 2 } ?: return@mapNotNull null
val state = ReportLevel.findByDescription(stateDescription) ?: return@mapNotNull null
name to state
}.toMap()
val jspecifyReportLevel = module.getDirectiveValue(JSPECIFY_STATE_SPECIAL_DIRECTIVE) ?: ReportLevel.STRICT
return mapOf(
JvmAnalysisFlags.javaTypeEnhancementState to JavaTypeEnhancementState(
globalState,
migrationState,
userAnnotationsState,
jspecifyReportLevel = jspecifyReportLevel
)
)
}
private fun List<TestFile>.getDirectiveValue(directive: String): ReportLevel? = mapNotNull {
InTextDirectivesUtils.findLinesWithPrefixesRemoved(it.expectedText, directive).firstOrNull()
}.firstOrNull().let { ReportLevel.findByDescription(it) }
companion object {
private const val JSR305_GLOBAL_DIRECTIVE = "JSR305_GLOBAL_REPORT"
private const val JSR305_MIGRATION_DIRECTIVE = "JSR305_MIGRATION_REPORT"
private const val JSR305_SPECIAL_DIRECTIVE = "JSR305_SPECIAL_REPORT"
private const val JSPECIFY_STATE_SPECIAL_DIRECTIVE = "JSPECIFY_STATE"
}
}
@@ -1,50 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.checkers
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import java.io.File
abstract class AbstractForeignJava8AnnotationsTest : AbstractForeignAnnotationsTest() {
override val annotationsPath: String
get() = JAVA8_ANNOTATION_SOURCES_PATH
}
abstract class AbstractForeignJava8AnnotationsNoAnnotationInClasspathTest : AbstractForeignAnnotationsNoAnnotationInClasspathTest() {
override val annotationsPath: String
get() = JAVA8_ANNOTATION_SOURCES_PATH
override fun shouldSkipTest(wholeFile: File, files: List<TestFile>): Boolean {
return skipForCompiledVersion(files)
}
}
abstract class AbstractForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTest :
AbstractForeignAnnotationsNoAnnotationInClasspathWithPsiClassReadingTest() {
override val annotationsPath: String
get() = JAVA8_ANNOTATION_SOURCES_PATH
override fun shouldSkipTest(wholeFile: File, files: List<TestFile>): Boolean {
return skipForCompiledVersion(files)
}
}
private fun skipForCompiledVersion(files: List<BaseDiagnosticsTest.TestFile>) =
files.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.expectedText, "// SKIP_COMPILED_JAVA") }
private const val JAVA8_ANNOTATION_SOURCES_PATH = "third-party/jdk8-annotations"
@@ -16,13 +16,5 @@
package org.jetbrains.kotlin.checkers
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
abstract class AbstractForeignAnnotationsNoAnnotationInClasspathWithPsiClassReadingTest :
AbstractForeignAnnotationsNoAnnotationInClasspathTest() {
override fun updateConfiguration(configuration: CompilerConfiguration) {
super.updateConfiguration(configuration)
configuration.put(JVMConfigurationKeys.USE_PSI_CLASS_FILES_READING, true)
}
}
const val FOREIGN_ANNOTATIONS_SOURCES_PATH = "third-party/annotations"
const val FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH = "third-party/jdk8-annotations"
@@ -24,7 +24,7 @@ import kotlin.io.FilesKt;
import kotlin.io.path.PathsKt;
import kotlin.text.Charsets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.checkers.AbstractForeignAnnotationsTestKt;
import org.jetbrains.kotlin.checkers.ThirdPartyAnnotationPathsKt;
import org.jetbrains.kotlin.cli.common.CLITool;
import org.jetbrains.kotlin.cli.common.ExitCode;
import org.jetbrains.kotlin.cli.common.Usage;
@@ -261,7 +261,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
.replace(TESTDATA_DIR, testDataDir)
.replace(
"$FOREIGN_ANNOTATIONS_DIR$",
new File(AbstractForeignAnnotationsTestKt.FOREIGN_ANNOTATIONS_SOURCES_PATH).getPath()
new File(ThirdPartyAnnotationPathsKt.FOREIGN_ANNOTATIONS_SOURCES_PATH).getPath()
).replace(
"$JDK_15$",
KtTestUtil.getJdk15Home().getPath()
@@ -53,7 +53,7 @@ import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static org.jetbrains.kotlin.checkers.AbstractForeignAnnotationsTestKt.FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH;
import static org.jetbrains.kotlin.checkers.ThirdPartyAnnotationPathsKt.FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH;
public class LoadDescriptorUtil {
@NotNull