[LL FIR] add LL FIR tests based on AbstractFirPsiNativeDiagnosticsTest

^KT-62910 fixed
This commit is contained in:
Ilya Kirillov
2023-10-27 12:11:21 +02:00
committed by Space Team
parent a4564351d7
commit bffbbe6293
11 changed files with 466 additions and 1 deletions
@@ -0,0 +1,38 @@
plugins {
kotlin("jvm")
id("jps-compatible")
}
dependencies {
testImplementation(project(":analysis:low-level-api-fir"))
testImplementation(project(":analysis:analysis-api-standalone:analysis-api-fir-standalone-base"))
testImplementation(projectTests(":compiler:tests-common"))
testImplementation(projectTests(":analysis:analysis-api-impl-barebone"))
testImplementation(projectTests(":analysis:analysis-test-framework"))
testImplementation(projectTests(":analysis:analysis-api-impl-base"))
testImplementation(projectTests(":analysis:low-level-api-fir"))
testImplementation(projectTests(":native:native.tests"))
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
}
sourceSets {
"main" { none() }
"test" {
projectDefault()
generatedTestDir()
}
}
projectTest(jUnitMode = JUnitMode.JUnit5) {
dependsOn(":dist")
workingDir = rootDir
useJUnitPlatform()
}
nativeTest("llFirNativeTests", "llFirNative")
testsJar()
@@ -0,0 +1,112 @@
/*
* Copyright 2010-2023 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.analysis.low.level.api.fir.konan.compiler.based;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.junit.jupiter.api.Tag;
import org.jetbrains.kotlin.test.TestMetadata;
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.analysis.api.konan.GenerateAnalysisApiNativeTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/diagnostics/nativeTests")
@TestDataPath("$PROJECT_ROOT")
@Tag("llFirNative")
public class LLFirNativeTestGenerated extends AbstractLLFirNativeTest {
@Test
public void testAllFilesPresentInNativeTests() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/nativeTests"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("arrays_after.kt")
public void testArrays_after() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/arrays_after.kt");
}
@Test
@TestMetadata("cloneableInNative.kt")
public void testCloneableInNative() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/cloneableInNative.kt");
}
@Test
@TestMetadata("forwardDeclarations.kt")
public void testForwardDeclarations() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/forwardDeclarations.kt");
}
@Test
@TestMetadata("identifiers.kt")
public void testIdentifiers() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/identifiers.kt");
}
@Test
@TestMetadata("isInitialized.kt")
public void testIsInitialized() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/isInitialized.kt");
}
@Test
@TestMetadata("isInitializedError.kt")
public void testIsInitializedError() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/isInitializedError.kt");
}
@Test
@TestMetadata("nativeProtectedFunCall.kt")
public void testNativeProtectedFunCall() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/nativeProtectedFunCall.kt");
}
@Test
@TestMetadata("objCName.kt")
public void testObjCName() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
}
@Test
@TestMetadata("objCRefinement.kt")
public void testObjCRefinement() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/objCRefinement.kt");
}
@Test
@TestMetadata("sharedImmutable.kt")
public void testSharedImmutable() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/sharedImmutable.kt");
}
@Test
@TestMetadata("threadLocal.kt")
public void testThreadLocal() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/threadLocal.kt");
}
@Test
@TestMetadata("throws.kt")
public void testThrows() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/throws.kt");
}
@Test
@TestMetadata("throwsClash.kt")
public void testThrowsClash() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/throwsClash.kt");
}
@Test
@TestMetadata("topLevelSingleton.kt")
public void testTopLevelSingleton() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/topLevelSingleton.kt");
}
}
@@ -0,0 +1,112 @@
/*
* Copyright 2010-2023 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.analysis.low.level.api.fir.konan.compiler.based;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.junit.jupiter.api.Tag;
import org.jetbrains.kotlin.test.TestMetadata;
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.analysis.api.konan.GenerateAnalysisApiNativeTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/diagnostics/nativeTests")
@TestDataPath("$PROJECT_ROOT")
@Tag("llFirNative")
public class LLFirReversedNativeTestGenerated extends AbstractLLFirReversedNativeTest {
@Test
public void testAllFilesPresentInNativeTests() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/nativeTests"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("arrays_after.kt")
public void testArrays_after() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/arrays_after.kt");
}
@Test
@TestMetadata("cloneableInNative.kt")
public void testCloneableInNative() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/cloneableInNative.kt");
}
@Test
@TestMetadata("forwardDeclarations.kt")
public void testForwardDeclarations() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/forwardDeclarations.kt");
}
@Test
@TestMetadata("identifiers.kt")
public void testIdentifiers() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/identifiers.kt");
}
@Test
@TestMetadata("isInitialized.kt")
public void testIsInitialized() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/isInitialized.kt");
}
@Test
@TestMetadata("isInitializedError.kt")
public void testIsInitializedError() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/isInitializedError.kt");
}
@Test
@TestMetadata("nativeProtectedFunCall.kt")
public void testNativeProtectedFunCall() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/nativeProtectedFunCall.kt");
}
@Test
@TestMetadata("objCName.kt")
public void testObjCName() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
}
@Test
@TestMetadata("objCRefinement.kt")
public void testObjCRefinement() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/objCRefinement.kt");
}
@Test
@TestMetadata("sharedImmutable.kt")
public void testSharedImmutable() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/sharedImmutable.kt");
}
@Test
@TestMetadata("threadLocal.kt")
public void testThreadLocal() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/threadLocal.kt");
}
@Test
@TestMetadata("throws.kt")
public void testThrows() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/throws.kt");
}
@Test
@TestMetadata("throwsClash.kt")
public void testThrowsClash() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/throwsClash.kt");
}
@Test
@TestMetadata("topLevelSingleton.kt")
public void testTopLevelSingleton() throws Exception {
runTest("compiler/testData/diagnostics/nativeTests/topLevelSingleton.kt");
}
}
@@ -0,0 +1,47 @@
/*
* Copyright 2010-2023 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.analysis.low.level.api.fir.konan.compiler.based
import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirOnlyNonReversedTestSuppressor
import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirOnlyReversedTestSuppressor
import org.jetbrains.kotlin.analysis.low.level.api.fir.compiler.based.AbstractCompilerBasedTestForFir
import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.ReversedFirIdenticalChecker
import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.facades.LLFirAnalyzerFacadeFactoryWithPreresolveInReversedOrder
import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.facades.LLFirAnalyzerFacadeFactoryWithoutPreresolve
import org.jetbrains.kotlin.konan.test.diagnostics.baseFirNativeDiagnosticTestConfiguration
import org.jetbrains.kotlin.konan.test.diagnostics.baseNativeDiagnosticTestConfiguration
import org.jetbrains.kotlin.platform.konan.NativePlatforms
import org.jetbrains.kotlin.test.bind
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.runners.configurationForClassicAndFirTestsAlongside
abstract class AbstractLLFirNativeTestBase : AbstractCompilerBasedTestForFir() {
protected fun TestConfigurationBuilder.baseConfiguration() {
globalDefaults {
targetPlatform = NativePlatforms.unspecifiedNativePlatform
}
baseFirNativeDiagnosticTestConfiguration()
configurationForClassicAndFirTestsAlongside(::ReversedFirIdenticalChecker)
}
}
abstract class AbstractLLFirNativeTest : AbstractLLFirNativeTestBase() {
override fun TestConfigurationBuilder.configureTest() {
baseNativeDiagnosticTestConfiguration(::LowLevelFirFrontendFacade.bind(LLFirAnalyzerFacadeFactoryWithoutPreresolve))
baseConfiguration()
useAfterAnalysisCheckers(::LLFirOnlyNonReversedTestSuppressor)
}
}
abstract class AbstractLLFirReversedNativeTest : AbstractLLFirNativeTestBase() {
override fun TestConfigurationBuilder.configureTest() {
baseNativeDiagnosticTestConfiguration(::LowLevelFirFrontendFacade.bind(LLFirAnalyzerFacadeFactoryWithPreresolveInReversedOrder))
baseConfiguration()
useAfterAnalysisCheckers(::LLFirOnlyReversedTestSuppressor)
}
}
@@ -0,0 +1,9 @@
// LL_FIR_DIVERGENCE
// KT-62935
// LL_FIR_DIVERGENCE
// ISSUE: KT-58549
fun main() {
val x: kotlin.Cloneable = if (true) intArrayOf(1) else longArrayOf(1)
x
}
@@ -0,0 +1,109 @@
// LL_FIR_DIVERGENCE
// KT-62936
// LL_FIR_DIVERGENCE
// WITH_STDLIB
// FILE: stdlib.kt
package kotlinx.cinterop
abstract class CStructVar
interface ObjCObject
abstract class ObjCObjectBase : ObjCObject
// FILE: cnames.kt
package cnames.structs
class FwdStruct {}
// FILE: objcnamesClasses.kt
package objcnames.classes
class FwdObjcClass {}
// FILE: objcnamesProtocols.kt
package objcnames.protocols
interface FwdProtocol {}
// FILE: lib.kt
package lib
import kotlinx.cinterop.*
class FwdStruct : CStructVar()
class FwdObjcClass : ObjCObjectBase()
interface FwdProtocol : ObjCObject
// FILE: lib2.kt
package lib2
class FwdStruct
class FwdObjcClass
interface FwdProtocol
// FILE: main.kt
// this inspections differs in K1/K2, but unrelated to what is tested in this test
@file:Suppress("UNUSED_PARAMETER", "UNUSED_EXPRESSION", "UNUSED_VARIABLE", <!ERROR_SUPPRESSION!>"INCOMPATIBLE_TYPES"<!>)
fun testUnckeckedAsFromAny(x: Any) {
x as? cnames.structs.FwdStruct
x as? objcnames.classes.FwdObjcClass
x as? objcnames.protocols.FwdProtocol
if (1 > 0) { x as cnames.structs.FwdStruct }
if (1 > 0) { x as objcnames.classes.FwdObjcClass }
if (1 > 0) { x as objcnames.protocols.FwdProtocol }
}
fun testIs(x: Any) : Int {
return when {
x is cnames.structs.FwdStruct -> 1
x is objcnames.classes.FwdObjcClass -> 2
x is objcnames.protocols.FwdProtocol -> 3
else -> 4
}
}
fun testIs2(x: lib.FwdStruct) = x is cnames.structs.FwdStruct
fun testIs3(x: lib.FwdObjcClass) = x is objcnames.classes.FwdObjcClass
fun testIs4(x: lib.FwdProtocol) = x is objcnames.protocols.FwdProtocol
fun testClass1(x : cnames.structs.FwdStruct) = x::class
fun testClass2(x : objcnames.classes.FwdObjcClass) = x::class
fun testClass3(x : objcnames.protocols.FwdProtocol) = x::class
fun testClass4() {
cnames.structs.FwdStruct::class
objcnames.classes.FwdObjcClass::class
objcnames.protocols.FwdProtocol::class
}
inline fun <reified T> inlineF(x: T) {}
fun testInline1(x : cnames.structs.FwdStruct) = inlineF(x)
fun testInline2(x : objcnames.classes.FwdObjcClass) = inlineF(x)
fun testInline3(x : objcnames.protocols.FwdProtocol) = inlineF(x)
fun testInline4() {
val a : (cnames.structs.FwdStruct) -> Unit = ::inlineF
val b : (objcnames.classes.FwdObjcClass) -> Unit = ::inlineF
val c : (objcnames.protocols.FwdProtocol) -> Unit = ::inlineF
}
fun testCheckedAs1(x : lib.FwdStruct) = x <!CAST_NEVER_SUCCEEDS!>as<!> cnames.structs.FwdStruct
fun testCheckedAs2(x : lib.FwdObjcClass) = x <!CAST_NEVER_SUCCEEDS!>as<!> objcnames.classes.FwdObjcClass
fun testCheckedAs3(x : lib.FwdProtocol) = x as objcnames.protocols.FwdProtocol
fun testCheckedSafeAs4(x : lib.FwdStruct) = x <!CAST_NEVER_SUCCEEDS!>as?<!> cnames.structs.FwdStruct
fun testCheckedSafeAs5(x : lib.FwdObjcClass) = x <!CAST_NEVER_SUCCEEDS!>as?<!> objcnames.classes.FwdObjcClass
fun testCheckedSafeAs6(x : lib.FwdProtocol) = x as? objcnames.protocols.FwdProtocol
fun testUnCheckedAs1(x : lib2.FwdStruct) = x <!CAST_NEVER_SUCCEEDS!>as<!> cnames.structs.FwdStruct
fun testUnCheckedAs2(x : lib2.FwdObjcClass) = x <!CAST_NEVER_SUCCEEDS!>as<!> objcnames.classes.FwdObjcClass
fun testUnCheckedAs3(x : lib2.FwdProtocol) = x as objcnames.protocols.FwdProtocol
fun testUnCheckedAs4(x : lib.FwdStruct) = x <!CAST_NEVER_SUCCEEDS!>as<!> objcnames.classes.FwdObjcClass
@@ -1,3 +1,4 @@
// IGNORE_NON_REVERSED_RESOLVE: KT-62937
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -MISSING_DEPENDENCY_SUPERCLASS
@@ -16,6 +16,10 @@ dependencies {
testImplementation(projectTests(":compiler:tests-spec"))
testImplementation(projectTests(":generators:analysis-api-generator"))
testImplementation(projectTests(":analysis:low-level-api-fir"))
testImplementation(projectTests(":analysis:analysis-api-impl-barebone"))
testImplementation(projectTests(":analysis:low-level-api-fir:low-level-api-fir-native"))
testImplementation(intellijCore())
testApi(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter.api)
@@ -16,4 +16,7 @@ fun main(args: Array<String>) {
}
private fun AnalysisApiTestGroup.generateTests() {
suiteBasedTests {
generateFirNativeLowLevelTests()
}
}
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2023 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.generators.tests.analysis.api.konan
import org.jetbrains.kotlin.analysis.low.level.api.fir.konan.compiler.based.AbstractLLFirNativeTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.konan.compiler.based.AbstractLLFirReversedNativeTest
import org.jetbrains.kotlin.generators.TestGroupSuite
import org.jetbrains.kotlin.generators.model.annotation
import org.jetbrains.kotlin.test.utils.CUSTOM_TEST_DATA_EXTENSION_PATTERN
import org.junit.jupiter.api.Tag
internal fun TestGroupSuite.generateFirNativeLowLevelTests() {
testGroup("analysis/low-level-api-fir/low-level-api-fir-native/tests-gen", "compiler/testData/diagnostics") {
testClass<AbstractLLFirNativeTest>(
annotations = listOf(annotation(Tag::class.java, "llFirNative"))
) {
model("nativeTests", testMethod = "doTest", excludedPattern = CUSTOM_TEST_DATA_EXTENSION_PATTERN)
}
testClass<AbstractLLFirReversedNativeTest>(
annotations = listOf(annotation(Tag::class.java, "llFirNative"))
) {
model("nativeTests", testMethod = "doTest", excludedPattern = CUSTOM_TEST_DATA_EXTENSION_PATTERN)
}
}
}
+2 -1
View File
@@ -578,7 +578,8 @@ include ":generators:analysis-api-generator",
":tools:ide-plugin-dependencies-validator"
if (buildProperties.isKotlinNativeEnabled) {
include ":generators:analysis-api-generator:generator-kotlin-native"
include ":generators:analysis-api-generator:generator-kotlin-native",
":analysis:low-level-api-fir:low-level-api-fir-native"
}