[Tests] Support language features from test data in .knm meta compiler
Mute test failure revealed by unblocked context receivers (KTIJ-28885) KTIJ-28668
This commit is contained in:
committed by
Space Team
parent
d17044515f
commit
00faa6fa01
+7
@@ -22,6 +22,7 @@ import java.nio.file.Paths
|
|||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
import kotlin.io.path.absolutePathString
|
import kotlin.io.path.absolutePathString
|
||||||
import kotlin.io.path.extension
|
import kotlin.io.path.extension
|
||||||
|
import kotlin.io.path.readText
|
||||||
|
|
||||||
abstract class AbstractDecompiledKnmFileTest : KotlinTestWithEnvironment() {
|
abstract class AbstractDecompiledKnmFileTest : KotlinTestWithEnvironment() {
|
||||||
abstract val knmTestSupport: KnmTestSupport
|
abstract val knmTestSupport: KnmTestSupport
|
||||||
@@ -60,10 +61,16 @@ abstract class AbstractDecompiledKnmFileTest : KotlinTestWithEnvironment() {
|
|||||||
private fun compileCommonKlib(testDirectory: Path): File {
|
private fun compileCommonKlib(testDirectory: Path): File {
|
||||||
val ktFiles = Files.list(testDirectory).filter { it.extension == "kt" }.collect(Collectors.toList())
|
val ktFiles = Files.list(testDirectory).filter { it.extension == "kt" }.collect(Collectors.toList())
|
||||||
val testKlib = KtTestUtil.tmpDir("testLibrary").resolve("library.klib")
|
val testKlib = KtTestUtil.tmpDir("testLibrary").resolve("library.klib")
|
||||||
|
val additionalArgumentsFromLanguageDirectives = ktFiles.flatMap { path ->
|
||||||
|
path.readText().let { fileText ->
|
||||||
|
InTextDirectivesUtils.findListWithPrefixes(fileText, "// !LANGUAGE: ").map { "-XXLanguage:$it" }
|
||||||
|
}
|
||||||
|
}
|
||||||
KlibTestUtil.compileCommonSourcesToKlib(
|
KlibTestUtil.compileCommonSourcesToKlib(
|
||||||
ktFiles.map(Path::toFile),
|
ktFiles.map(Path::toFile),
|
||||||
libraryName = "library",
|
libraryName = "library",
|
||||||
testKlib,
|
testKlib,
|
||||||
|
additionalArgumentsFromLanguageDirectives,
|
||||||
)
|
)
|
||||||
|
|
||||||
return testKlib
|
return testKlib
|
||||||
|
|||||||
-3
@@ -1,8 +1,5 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !LANGUAGE: +ContextReceivers
|
// !LANGUAGE: +ContextReceivers
|
||||||
/* Unsupported arguments in test metadata compiler */
|
|
||||||
// KNM_K2_IGNORE
|
|
||||||
// KNM_FE10_IGNORE
|
|
||||||
|
|
||||||
private open class ContextReceiversCallableMembers {
|
private open class ContextReceiversCallableMembers {
|
||||||
context(A, B)
|
context(A, B)
|
||||||
|
|||||||
-3
@@ -1,8 +1,5 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !LANGUAGE: +ContextReceivers
|
// !LANGUAGE: +ContextReceivers
|
||||||
/* Unsupported arguments in test metadata compiler */
|
|
||||||
// KNM_K2_IGNORE
|
|
||||||
// KNM_FE10_IGNORE
|
|
||||||
|
|
||||||
context(A, B)
|
context(A, B)
|
||||||
private open class ContextReceiversOnClass {
|
private open class ContextReceiversOnClass {
|
||||||
|
|||||||
+1
-2
@@ -1,9 +1,8 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// JVM_FILE_NAME: ContextReceiversOnFunctionTypeKt
|
// JVM_FILE_NAME: ContextReceiversOnFunctionTypeKt
|
||||||
// !LANGUAGE: +ContextReceivers
|
// !LANGUAGE: +ContextReceivers
|
||||||
/* Unsupported arguments in test metadata compiler */
|
/* KTIJ-28885 */
|
||||||
// KNM_K2_IGNORE
|
// KNM_K2_IGNORE
|
||||||
// KNM_FE10_IGNORE
|
|
||||||
|
|
||||||
fun f(g: context(A, B) Int.(Int) -> Int) {}
|
fun f(g: context(A, B) Int.(Int) -> Int) {}
|
||||||
|
|
||||||
|
|||||||
-3
@@ -1,9 +1,6 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// JVM_FILE_NAME: ContextReceiversOnTopLevelCallablesKt
|
// JVM_FILE_NAME: ContextReceiversOnTopLevelCallablesKt
|
||||||
// !LANGUAGE: +ContextReceivers
|
// !LANGUAGE: +ContextReceivers
|
||||||
/* Unsupported arguments in test metadata compiler */
|
|
||||||
// KNM_K2_IGNORE
|
|
||||||
// KNM_FE10_IGNORE
|
|
||||||
|
|
||||||
context(A, B)
|
context(A, B)
|
||||||
private fun Int.function(): Int = valueA + valueB
|
private fun Int.function(): Int = valueA + valueB
|
||||||
|
|||||||
@@ -13,10 +13,14 @@ import org.jetbrains.kotlin.analyzer.common.CommonResolverForModuleFactory
|
|||||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataMonolithicSerializer
|
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataMonolithicSerializer
|
||||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
|
||||||
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots
|
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots
|
||||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.FilteringMessageCollector
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||||
|
import org.jetbrains.kotlin.cli.common.setupCommonArguments
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot
|
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot
|
||||||
@@ -50,19 +54,27 @@ import java.nio.file.Path
|
|||||||
import org.jetbrains.kotlin.konan.file.File as KFile
|
import org.jetbrains.kotlin.konan.file.File as KFile
|
||||||
|
|
||||||
object KlibTestUtil {
|
object KlibTestUtil {
|
||||||
fun compileCommonSourcesToKlib(sourceFiles: Collection<File>, libraryName: String, klibFile: File) {
|
fun compileCommonSourcesToKlib(
|
||||||
|
sourceFiles: Collection<File>,
|
||||||
|
libraryName: String,
|
||||||
|
klibFile: File,
|
||||||
|
additionalArguments: List<String> = emptyList(),
|
||||||
|
) {
|
||||||
require(!Name.guessByFirstCharacter(libraryName).isSpecial) { "Invalid library name: $libraryName" }
|
require(!Name.guessByFirstCharacter(libraryName).isSpecial) { "Invalid library name: $libraryName" }
|
||||||
|
|
||||||
val configuration = KotlinTestUtils.newConfiguration()
|
val configuration = KotlinTestUtils.newConfiguration()
|
||||||
configuration.put(
|
configuration.put(
|
||||||
CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
|
CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
|
||||||
PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, false)
|
FilteringMessageCollector(
|
||||||
|
PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, false)
|
||||||
|
) /* decline = */ { !it.isError }
|
||||||
)
|
)
|
||||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, libraryName)
|
configuration.put(CommonConfigurationKeys.MODULE_NAME, libraryName)
|
||||||
configuration.addKotlinSourceRoots(sourceFiles.map { it.absolutePath })
|
configuration.addKotlinSourceRoots(sourceFiles.map { it.absolutePath })
|
||||||
val stdlibFile = ForTestCompileRuntime.stdlibCommonForTests()
|
val stdlibFile = ForTestCompileRuntime.stdlibCommonForTests()
|
||||||
// support for the legacy version of kotlin-stdlib-common (JAR with .kotlin_metadata)
|
// support for the legacy version of kotlin-stdlib-common (JAR with .kotlin_metadata)
|
||||||
configuration.addJvmClasspathRoot(stdlibFile)
|
configuration.addJvmClasspathRoot(stdlibFile)
|
||||||
|
configuration.setupCommonArguments(parseCommandLineArguments<K2MetadataCompilerArguments>(additionalArguments))
|
||||||
|
|
||||||
val rootDisposable = Disposer.newDisposable("Disposable for ${KlibTestUtil::class.simpleName}.compileCommonSourcesToKlib")
|
val rootDisposable = Disposer.newDisposable("Disposable for ${KlibTestUtil::class.simpleName}.compileCommonSourcesToKlib")
|
||||||
val module = try {
|
val module = try {
|
||||||
@@ -77,7 +89,7 @@ object KlibTestUtil {
|
|||||||
val analyzer = AnalyzerWithCompilerReport(
|
val analyzer = AnalyzerWithCompilerReport(
|
||||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY),
|
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY),
|
||||||
configuration.languageVersionSettings,
|
configuration.languageVersionSettings,
|
||||||
configuration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
|
renderDiagnosticName = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
analyzer.analyzeAndReport(environment.getSourceFiles()) {
|
analyzer.analyzeAndReport(environment.getSourceFiles()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user