Tests: use errors dump instead of ALLOW_UNRESOLVED_REFERENCE
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
// ERROR: Unresolved reference: s
|
||||
// ERROR: Unresolved reference: s
|
||||
// ERROR: Unresolved reference: s
|
||||
// ERROR: Unresolved reference: s
|
||||
fun foo() {
|
||||
s.extensionFun()
|
||||
for (i in s.indices) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// RUNTIME
|
||||
// ALLOW_UNRESOLVED
|
||||
|
||||
fun foo(s: String) {
|
||||
<selection> s.extensionFun()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Type mismatch: inferred type is kotlin.Unit but a.A was expected
|
||||
package to
|
||||
|
||||
import a.*
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// ERROR: Unresolved reference: c
|
||||
// ERROR: Unresolved reference: d
|
||||
// ERROR: Unresolved reference: g
|
||||
// ERROR: Unresolved reference: j
|
||||
package to
|
||||
|
||||
fun f() = c + d + g + j()
|
||||
@@ -1,7 +1,5 @@
|
||||
package a
|
||||
|
||||
// ALLOW_UNRESOLVED
|
||||
|
||||
class A(val c: Int = 1) {
|
||||
var d = 2
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: A 'return' expression required in a function with a block body ('{...}')
|
||||
package to
|
||||
|
||||
import a.A
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Unresolved reference: f
|
||||
package to
|
||||
|
||||
fun g() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package a
|
||||
|
||||
// ALLOW_UNRESOLVED
|
||||
//NOTE: is is an unsupported case
|
||||
class A {
|
||||
<selection>fun g() {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package a
|
||||
|
||||
// ALLOW_UNRESOLVED
|
||||
|
||||
class C {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Unresolved reference: A
|
||||
package to
|
||||
|
||||
val c = A()
|
||||
@@ -1,5 +1,3 @@
|
||||
// ALLOW_UNRESOLVED
|
||||
|
||||
class A {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// NO_ERRORS_DUMP
|
||||
package a
|
||||
|
||||
trait T
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Type mismatch: inferred type is kotlin.Unit but d.A was expected
|
||||
package to
|
||||
|
||||
import d.A
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// ERROR: Overload resolution ambiguity: internal fun a.A.ext(): kotlin.Unit defined in a internal fun a.A.ext(): kotlin.Unit defined in to
|
||||
// ERROR: Overload resolution ambiguity: internal var a.A.p: kotlin.Int defined in a internal var a.A.p: kotlin.Int defined in to
|
||||
// ERROR: Overload resolution ambiguity: internal var a.A.p: kotlin.Int defined in a internal var a.A.p: kotlin.Int defined in to
|
||||
package to
|
||||
|
||||
import a.A
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// ERROR: Overload resolution ambiguity: internal fun a.A.ext(): kotlin.Unit defined in a internal fun a.A.ext(): kotlin.Unit defined in to
|
||||
// ERROR: Overload resolution ambiguity: internal fun a.A.plus(a: a.A): kotlin.Unit defined in a internal fun a.A.plus(a: a.A): kotlin.Unit defined in to
|
||||
// ERROR: Overload resolution ambiguity: internal fun a.A.infix(a: a.A): kotlin.Unit defined in a internal fun a.A.infix(a: a.A): kotlin.Unit defined in to
|
||||
// ERROR: Overload resolution ambiguity: internal fun a.A.minus(): kotlin.Unit defined in a internal fun a.A.minus(): kotlin.Unit defined in to
|
||||
// ERROR: Overload resolution ambiguity: internal val a.A.p: kotlin.Int defined in a internal val a.A.p: kotlin.Int defined in to
|
||||
package to
|
||||
|
||||
import a.A
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// ERROR: Unresolved reference: T
|
||||
// ERROR: Unresolved reference: b
|
||||
// ERROR: Unresolved reference: c
|
||||
package to
|
||||
|
||||
fun f() {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//RUNTIME
|
||||
// ALLOW_UNRESOLVED
|
||||
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Type mismatch: inferred type is kotlin.Unit but d.A was expected
|
||||
package to
|
||||
|
||||
import d.A
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package to
|
||||
|
||||
package a
|
||||
|
||||
import a.A
|
||||
@@ -1,4 +1,4 @@
|
||||
// ALLOW_UNRESOLVED
|
||||
// NO_ERRORS_DUMP
|
||||
|
||||
<selection>package a
|
||||
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
package to
|
||||
|
||||
<caret>
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Nested class 'Nested' should be qualified as 'A.Nested'
|
||||
package to
|
||||
|
||||
import a.ext
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
// ERROR: Unresolved reference: Inner
|
||||
// ERROR: Unresolved reference: Nested
|
||||
// ERROR: Unresolved reference: NestedEnum
|
||||
// ERROR: Unresolved reference: NestedObj
|
||||
// ERROR: Unresolved reference: NestedTrait
|
||||
// ERROR: Unresolved reference: NestedAnnotation
|
||||
package to
|
||||
|
||||
class Outer {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package a
|
||||
|
||||
// ALLOW_UNRESOLVED
|
||||
//NOTE: This test shows a corner case which is not covered fully by current implementation
|
||||
// All we do now is avoid inserting wrong imports (we do not import anything for declaration from copied block)
|
||||
// To cover this case properly and insert good imports some other approach should be used (some sophisticated heuristic might do the job)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package a;
|
||||
|
||||
class JavaM {
|
||||
static void staticMethod() {
|
||||
public class JavaM {
|
||||
public static void staticMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
class JavaF {
|
||||
static int staticField = 0;
|
||||
public class JavaF {
|
||||
public static int staticField = 0;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Expression 'staticField' of type 'kotlin.Int' cannot be invoked as a function. The function invoke() is not found
|
||||
package to
|
||||
|
||||
import a.JavaF
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ERROR: Unresolved reference: A
|
||||
// ERROR: Unresolved reference: g
|
||||
package to
|
||||
|
||||
fun f() {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package a
|
||||
|
||||
// ALLOW_UNRESOLVED
|
||||
|
||||
fun f() {
|
||||
fun g(): Int {
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// ERROR: Cannot access 'd': it is 'private' in 'a'
|
||||
// ERROR: Cannot access 'd': it is 'private' in 'a'
|
||||
// ERROR: Cannot access 'b': it is 'private' in 'a'
|
||||
// ERROR: Cannot access 'b': it is 'private' in 'a'
|
||||
package to
|
||||
|
||||
import a.b
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: No value passed for parameter i
|
||||
package a
|
||||
|
||||
fun f(p: A, t: T) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ERROR: Type mismatch: inferred type is kotlin.Unit but to.A was expected
|
||||
// ERROR: Function 'ext' must have a body
|
||||
package to
|
||||
|
||||
trait T
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: No supertypes are accessible in this context
|
||||
package to
|
||||
|
||||
fun f() {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Function 'f' must have a body
|
||||
package to
|
||||
|
||||
import a.A
|
||||
|
||||
+9
-48
@@ -18,26 +18,18 @@ package org.jetbrains.kotlin.idea.codeInsight
|
||||
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.checkers.DebugInfoUtil
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.idea.AbstractCopyPasteTest
|
||||
import org.jetbrains.kotlin.idea.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
||||
import org.jetbrains.kotlin.idea.testUtils.dumpTextWithErrors
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.JetTestUtils
|
||||
import java.io.File
|
||||
import kotlin.test.fail
|
||||
|
||||
public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest() {
|
||||
private val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/imports"
|
||||
private val DEFAULT_TO_FILE_TEXT = "package to\n\n<caret>"
|
||||
private val ALLOW_UNRESOLVED_DIRECTIVE = "// ALLOW_UNRESOLVED"
|
||||
private val NO_ERRORS_DUMP_DIRECTIVE = "// NO_ERRORS_DUMP"
|
||||
|
||||
override fun getTestDataPath() = BASE_PATH
|
||||
|
||||
@@ -61,18 +53,18 @@ public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest()
|
||||
|
||||
KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested = emptyList()
|
||||
|
||||
val toFileName = testFileName.replace(".kt", ".to.kt")
|
||||
val toFile = configureToFile(toFileName)
|
||||
configureToFile(testFileName.replace(".kt", ".to.kt"))
|
||||
performNotWriteEditorAction(IdeActions.ACTION_PASTE)
|
||||
|
||||
val namesToImportDump = KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested.joinToString("\n")
|
||||
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.names")), namesToImportDump)
|
||||
|
||||
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.kt")), myFixture.getEditor().getDocument().getText())
|
||||
|
||||
if (!InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(testFile, true), ALLOW_UNRESOLVED_DIRECTIVE)) {
|
||||
checkNoUnresolvedReferences(toFile)
|
||||
}
|
||||
val resultFile = myFixture.getFile() as JetFile
|
||||
val resultText = if (InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(testFile, true), NO_ERRORS_DUMP_DIRECTIVE))
|
||||
resultFile.getText()
|
||||
else
|
||||
resultFile.dumpTextWithErrors()
|
||||
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.kt")), resultText)
|
||||
}
|
||||
|
||||
private fun configureToFile(toFileName: String): JetFile {
|
||||
@@ -96,35 +88,4 @@ public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkNoUnresolvedReferences(file: JetFile) {
|
||||
val bindingContext = file.analyzeFully()
|
||||
for (diagnostic in bindingContext.getDiagnostics()) {
|
||||
if (Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS.contains(diagnostic.getFactory())) {
|
||||
val textRanges = diagnostic.getTextRanges()
|
||||
val diagnosticText = DefaultErrorMessages.render(diagnostic)
|
||||
if (diagnostic.getPsiFile() == file) {
|
||||
fail(diagnostic.getFactory().getName() + ": " + diagnosticText + " " + DiagnosticUtils.atLocation(file, textRanges.get(0)))
|
||||
}
|
||||
}
|
||||
}
|
||||
DebugInfoUtil.markDebugAnnotations(file, bindingContext, object : DebugInfoUtil.DebugInfoReporter() {
|
||||
override fun preProcessReference(expression: JetReferenceExpression) {
|
||||
expression.analyze(BodyResolveMode.FULL)
|
||||
}
|
||||
|
||||
override fun reportElementWithErrorType(expression: JetReferenceExpression) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
override fun reportMissingUnresolved(expression: JetReferenceExpression) {
|
||||
// this may happen if incorrect psi transformations are done
|
||||
fail(expression.getText() + " is unresolved but not marked " + DiagnosticUtils.atLocation(file, expression.getTextRange()))
|
||||
}
|
||||
|
||||
override fun reportUnresolvedWithTarget(expression: JetReferenceExpression, target: String) {
|
||||
//do nothing
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,12 @@ import com.intellij.openapi.roots.ModifiableRootModel
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil.updateModel
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.util.Consumer
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.idea.JetStdJSProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.ProjectDescriptorWithStdlibSources
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
|
||||
public enum class ModuleKind {
|
||||
KOTLIN_JVM_WITH_STDLIB_SOURCES
|
||||
@@ -53,3 +57,11 @@ public fun Module.configureAs(kind: ModuleKind) {
|
||||
}
|
||||
}
|
||||
|
||||
public fun JetFile.dumpTextWithErrors(): String {
|
||||
val diagnostics = analyzeFullyAndGetResult().bindingContext.getDiagnostics()
|
||||
val errors = diagnostics.filter { it.getSeverity() == Severity.ERROR }
|
||||
if (errors.isEmpty()) return getText()
|
||||
val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n")
|
||||
return header + getText()
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.testFramework.LightPlatformTestCase
|
||||
import org.jetbrains.kotlin.idea.JetWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.j2k.IdeaResolverForConverter
|
||||
import org.jetbrains.kotlin.idea.j2k.J2kPostProcessor
|
||||
import org.jetbrains.kotlin.idea.testUtils.dumpTextWithErrors
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
@@ -71,13 +72,13 @@ public abstract class AbstractJavaToKotlinConverterMultiFileTest : AbstractJavaT
|
||||
}
|
||||
|
||||
for ((i, kotlinFile) in resultFiles.withIndex()) {
|
||||
JetTestUtils.assertEqualsToFile(expectedResultFile(i), addErrorsDump(kotlinFile))
|
||||
JetTestUtils.assertEqualsToFile(expectedResultFile(i), kotlinFile.dumpTextWithErrors())
|
||||
}
|
||||
|
||||
for ((externalFile, externalPsiFile) in externalFiles.zip(externalPsiFiles)) {
|
||||
val expectedFile = File(externalFile.getPath() + ".expected")
|
||||
var resultText = if (externalPsiFile is JetFile) {
|
||||
addErrorsDump(externalPsiFile)
|
||||
externalPsiFile.dumpTextWithErrors()
|
||||
}
|
||||
else {
|
||||
//TODO: errors dump for java files too
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.idea.JetWithJdkAndRuntimeLightProjectDescriptor
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.idea.j2k.IdeaResolverForConverter
|
||||
import org.jetbrains.kotlin.idea.testUtils.dumpTextWithErrors
|
||||
|
||||
public abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJavaToKotlinConverterTest() {
|
||||
val testHeaderPattern = Pattern.compile("//(element|expression|statement|method|class|file|comp)\n")
|
||||
@@ -80,7 +81,7 @@ public abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJava
|
||||
var actual = reformat(rawConverted, project, reformatInFun)
|
||||
|
||||
if (prefix == "file") {
|
||||
actual = addErrorsDump(createKotlinFile(actual))
|
||||
actual = createKotlinFile(actual).dumpTextWithErrors()
|
||||
}
|
||||
|
||||
val kotlinPath = javaPath.replace(".java", ".kt")
|
||||
|
||||
@@ -67,13 +67,5 @@ public abstract class AbstractJavaToKotlinConverterTest : LightCodeInsightFixtur
|
||||
protected fun deleteFile(virtualFile: VirtualFile) {
|
||||
runWriteAction { virtualFile.delete(this) }
|
||||
}
|
||||
|
||||
protected fun addErrorsDump(jetFile: JetFile): String {
|
||||
val diagnostics = jetFile.analyzeFullyAndGetResult().bindingContext.getDiagnostics()
|
||||
val errors = diagnostics.filter { it.getSeverity() == Severity.ERROR }
|
||||
if (errors.isEmpty()) return jetFile.getText()
|
||||
val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n")
|
||||
return header + jetFile.getText()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user