From 21c2268f709069c1d976c653aa91eadbf96a4cc4 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 21 Sep 2016 22:08:19 +0300 Subject: [PATCH] Protection against "" missing in test data Many incorrect tests fixed --- .../test/KotlinFixtureCompletionBaseTestCase.kt | 1 + .../branched/ifThenToSafeAccess/thenAndElseBothNull.kt | 2 +- .../convertLambdaToReference/wrongParameterOrder.kt | 2 +- .../inapplicableSingleExpression.kt | 2 +- .../convertToExpressionBody/expressionWithReturns1.kt | 2 +- .../iterationOverMap/DataClassDependentLocal.kt | 2 +- .../loopToCallChain/filter/inputVarNotUsed.kt | 2 +- .../removeUnnecessaryLateinit/normalLateinit.kt | 2 +- .../intentions/replaceRangeToWithUntil/closedRange.kt | 2 +- idea/testData/intentions/swapBinaryExpression/notIn.kt | 2 +- idea/testData/intentions/swapBinaryExpression/notIs.kt | 2 +- idea/testData/quickfix/autoImports/namelessClass.kt | 2 +- idea/testData/quickfix/autoImports/namelessFunction.kt | 2 +- idea/testData/quickfix/autoImports/namelessObject.kt | 2 +- .../testData/quickfix/autoImports/namelessParameter.kt | 2 +- idea/testData/quickfix/autoImports/namelessProperty.kt | 2 +- .../createFromUsage/createFunction/call/kt10983.kt | 10 +++++++++- idea/testData/quickfix/implement/finalClass.kt | 3 ++- .../quickfix/implement/noDefaultConstructor.kt | 3 ++- idea/testData/quickfix/implement/privateConstructor.kt | 3 ++- .../cantChangeReturnTypeOfOverriddenFunction.kt | 2 +- .../quickfix/suppress/declarationKinds/enumEntry.kt | 2 +- .../quickfix/suppress/forStatement/simpleName.kt | 2 +- .../typeAddition/propertyWithRecursiveGetter.kt | 5 ++++- .../quickfix/typeMismatch/casts/typeMismatch2.kt | 5 +++-- .../quickfix/typeMismatch/tooManyArgumentsException.kt | 8 ++++++-- .../kotlin/idea/intentions/AbstractIntentionTest.java | 2 ++ .../idea/quickfix/AbstractQuickFixMultiFileTest.java | 2 ++ .../kotlin/idea/quickfix/AbstractQuickFixTest.java | 1 + 29 files changed, 52 insertions(+), 27 deletions(-) diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt index 3f6764ea9cd..8c5c854e505 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt @@ -38,6 +38,7 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu try { val fileText = FileUtil.loadFile(File(testPath), true) + assertTrue("\"\" is missing in file \"$testPath\"", fileText.contains("")); if (ExpectedCompletionUtils.shouldRunHighlightingBeforeCompletion(fileText)) { myFixture.doHighlighting() diff --git a/idea/testData/intentions/branched/ifThenToSafeAccess/thenAndElseBothNull.kt b/idea/testData/intentions/branched/ifThenToSafeAccess/thenAndElseBothNull.kt index 98446403533..44c0f0cb891 100644 --- a/idea/testData/intentions/branched/ifThenToSafeAccess/thenAndElseBothNull.kt +++ b/idea/testData/intentions/branched/ifThenToSafeAccess/thenAndElseBothNull.kt @@ -1,7 +1,7 @@ // IS_APPLICABLE: false fun main(args: Array) { val foo: String? = "foo" - if (foo == null) { + if (foo == null) { null } else { diff --git a/idea/testData/intentions/convertLambdaToReference/wrongParameterOrder.kt b/idea/testData/intentions/convertLambdaToReference/wrongParameterOrder.kt index 7c2173b3034..052be5a05c3 100644 --- a/idea/testData/intentions/convertLambdaToReference/wrongParameterOrder.kt +++ b/idea/testData/intentions/convertLambdaToReference/wrongParameterOrder.kt @@ -2,4 +2,4 @@ fun foo(y: Int, z: Int) = y - z -val x = { second: Int, first: Int -> foo(first, second) } \ No newline at end of file +val x = { second: Int, first: Int -> foo(first, second) } \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableSingleExpression.kt b/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableSingleExpression.kt index 323547c090f..3b96d315304 100644 --- a/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableSingleExpression.kt +++ b/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableSingleExpression.kt @@ -1,4 +1,4 @@ // IS_APPLICABLE: false fun foo(a: Boolean): Boolean { - return !a + return !a } diff --git a/idea/testData/intentions/convertToExpressionBody/expressionWithReturns1.kt b/idea/testData/intentions/convertToExpressionBody/expressionWithReturns1.kt index a8dec334e9b..7b20bdbd2b8 100644 --- a/idea/testData/intentions/convertToExpressionBody/expressionWithReturns1.kt +++ b/idea/testData/intentions/convertToExpressionBody/expressionWithReturns1.kt @@ -1,7 +1,7 @@ // IS_APPLICABLE: false fun foo(p: Boolean): String { - return bar() ?: return "a" + return bar() ?: return "a" } fun bar(): String? = null \ No newline at end of file diff --git a/idea/testData/intentions/iterationOverMap/DataClassDependentLocal.kt b/idea/testData/intentions/iterationOverMap/DataClassDependentLocal.kt index 85922d7fa37..fbdbc11aa6f 100644 --- a/idea/testData/intentions/iterationOverMap/DataClassDependentLocal.kt +++ b/idea/testData/intentions/iterationOverMap/DataClassDependentLocal.kt @@ -3,7 +3,7 @@ data class XY(val x: Int, val y: Int) fun test(xys: Array) { - for (xy in xys) { + for (xy in xys) { val x = xy.x println(x) val y = xy.y + x diff --git a/idea/testData/intentions/loopToCallChain/filter/inputVarNotUsed.kt b/idea/testData/intentions/loopToCallChain/filter/inputVarNotUsed.kt index 1eb9055d8a9..cd412805c75 100644 --- a/idea/testData/intentions/loopToCallChain/filter/inputVarNotUsed.kt +++ b/idea/testData/intentions/loopToCallChain/filter/inputVarNotUsed.kt @@ -5,7 +5,7 @@ import java.util.* fun foo(list: List): String? { val random = Random() - for (s in list) { + for (s in list) { if (random.nextBoolean()) { return s } diff --git a/idea/testData/intentions/removeUnnecessaryLateinit/normalLateinit.kt b/idea/testData/intentions/removeUnnecessaryLateinit/normalLateinit.kt index b832a36b4b0..bb31f11ba94 100644 --- a/idea/testData/intentions/removeUnnecessaryLateinit/normalLateinit.kt +++ b/idea/testData/intentions/removeUnnecessaryLateinit/normalLateinit.kt @@ -1,7 +1,7 @@ // IS_APPLICABLE: false class Foo { - lateinit var bar: String + lateinit var bar: String fun init() { bar = "" diff --git a/idea/testData/intentions/replaceRangeToWithUntil/closedRange.kt b/idea/testData/intentions/replaceRangeToWithUntil/closedRange.kt index cd4ffc2c903..78702df65ff 100644 --- a/idea/testData/intentions/replaceRangeToWithUntil/closedRange.kt +++ b/idea/testData/intentions/replaceRangeToWithUntil/closedRange.kt @@ -2,5 +2,5 @@ // IS_APPLICABLE: false fun foo(a: Float) { - 1f..a - 1 + 1f..a - 1 } \ No newline at end of file diff --git a/idea/testData/intentions/swapBinaryExpression/notIn.kt b/idea/testData/intentions/swapBinaryExpression/notIn.kt index 907b3898e71..78855fa1311 100644 --- a/idea/testData/intentions/swapBinaryExpression/notIn.kt +++ b/idea/testData/intentions/swapBinaryExpression/notIn.kt @@ -2,7 +2,7 @@ fun doSomething(a: T) {} fun main(x: Int) { - if (x !in 5..6) { + if (x !in 5..6) { doSomething("test") } } diff --git a/idea/testData/intentions/swapBinaryExpression/notIs.kt b/idea/testData/intentions/swapBinaryExpression/notIs.kt index f0009995018..695217bb216 100644 --- a/idea/testData/intentions/swapBinaryExpression/notIs.kt +++ b/idea/testData/intentions/swapBinaryExpression/notIs.kt @@ -2,7 +2,7 @@ fun doSomething(a: T) {} fun main(x: Int) { - if (x !is Int) { + if (x !is Int) { doSomething("test") } } diff --git a/idea/testData/quickfix/autoImports/namelessClass.kt b/idea/testData/quickfix/autoImports/namelessClass.kt index c53d3f96c66..aedbd9ff1fb 100644 --- a/idea/testData/quickfix/autoImports/namelessClass.kt +++ b/idea/testData/quickfix/autoImports/namelessClass.kt @@ -2,5 +2,5 @@ // ERROR: Unresolved reference: TTT class { - val t: TTT = null + val t: TTT = null } diff --git a/idea/testData/quickfix/autoImports/namelessFunction.kt b/idea/testData/quickfix/autoImports/namelessFunction.kt index 8b92fac249d..4e73fb48866 100644 --- a/idea/testData/quickfix/autoImports/namelessFunction.kt +++ b/idea/testData/quickfix/autoImports/namelessFunction.kt @@ -3,5 +3,5 @@ // ERROR: Function declaration must have a name fun () { - val tttt : TTTTT = null + val tttt : TTTTT = null } diff --git a/idea/testData/quickfix/autoImports/namelessObject.kt b/idea/testData/quickfix/autoImports/namelessObject.kt index ce677d9f242..1938072ed42 100644 --- a/idea/testData/quickfix/autoImports/namelessObject.kt +++ b/idea/testData/quickfix/autoImports/namelessObject.kt @@ -2,5 +2,5 @@ // ERROR: Unresolved reference: TTT object { - val t : TTT = null + val t : TTT = null } \ No newline at end of file diff --git a/idea/testData/quickfix/autoImports/namelessParameter.kt b/idea/testData/quickfix/autoImports/namelessParameter.kt index 1b0c223b4c3..de0d08191af 100644 --- a/idea/testData/quickfix/autoImports/namelessParameter.kt +++ b/idea/testData/quickfix/autoImports/namelessParameter.kt @@ -2,5 +2,5 @@ // ERROR: Unresolved reference: TTT fun f(: Int) { - val t: TTT = null + val t: TTT = null } \ No newline at end of file diff --git a/idea/testData/quickfix/autoImports/namelessProperty.kt b/idea/testData/quickfix/autoImports/namelessProperty.kt index 7efbfc13744..429b4f87f3f 100644 --- a/idea/testData/quickfix/autoImports/namelessProperty.kt +++ b/idea/testData/quickfix/autoImports/namelessProperty.kt @@ -3,6 +3,6 @@ val : Int get() { - val t : TTT = null + val t : TTT = null return 1 } \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createFunction/call/kt10983.kt b/idea/testData/quickfix/createFromUsage/createFunction/call/kt10983.kt index 248efa48ce8..fe1b697b5e2 100644 --- a/idea/testData/quickfix/createFromUsage/createFunction/call/kt10983.kt +++ b/idea/testData/quickfix/createFromUsage/createFunction/call/kt10983.kt @@ -1,4 +1,12 @@ // "Create function" "false" +// ACTION: Create extension function 'Collection>.firstOrNull' +// ACTION: Create extension function 'Unit.equals' +// ACTION: Create local variable 'maximumSizeOfGroup' +// ACTION: Create object 'maximumSizeOfGroup' +// ACTION: Create parameter 'maximumSizeOfGroup' +// ACTION: Create property 'maximumSizeOfGroup' +// ACTION: Introduce local variable +// ACTION: Rename reference // ERROR: A 'return' expression required in a function with a block body ('{...}') // ERROR: The expression cannot be a selector (occur after a dot) // ERROR: Type inference failed: inline fun Iterable.firstOrNull(predicate: (T) -> Boolean): T?
cannot be applied to
receiver: Collection> arguments: ((List) -> () -> Boolean)
@@ -9,5 +17,5 @@ fun doSomethingStrangeWithCollection(collection: Collection): Collection val groupsByLength = collection.groupBy { s -> { s.length } } val maximumSizeOfGroup = groupsByLength.values.maxBy { it.size }. - return groupsByLength.values.firstOrNull { group -> {group.size == maximumSizeOfGroup} } + return groupsByLength.values.firstOrNull { group -> {group.size == maximumSizeOfGroup} } } diff --git a/idea/testData/quickfix/implement/finalClass.kt b/idea/testData/quickfix/implement/finalClass.kt index 4c5e65f11b5..b4d91eb74a6 100644 --- a/idea/testData/quickfix/implement/finalClass.kt +++ b/idea/testData/quickfix/implement/finalClass.kt @@ -1,3 +1,4 @@ // "Create subclass" "false" +// ACTION: Create test -class Base \ No newline at end of file +class Base \ No newline at end of file diff --git a/idea/testData/quickfix/implement/noDefaultConstructor.kt b/idea/testData/quickfix/implement/noDefaultConstructor.kt index 6bae6e65abe..3da97ce2853 100644 --- a/idea/testData/quickfix/implement/noDefaultConstructor.kt +++ b/idea/testData/quickfix/implement/noDefaultConstructor.kt @@ -1,3 +1,4 @@ // "class org.jetbrains.kotlin.idea.intentions.CreateKotlinSubClassIntention" "false" +// ACTION: Create test -abstract class Base(val x: Int) \ No newline at end of file +abstract class Base(val x: Int) \ No newline at end of file diff --git a/idea/testData/quickfix/implement/privateConstructor.kt b/idea/testData/quickfix/implement/privateConstructor.kt index 12be6b71e94..11492b98fb6 100644 --- a/idea/testData/quickfix/implement/privateConstructor.kt +++ b/idea/testData/quickfix/implement/privateConstructor.kt @@ -1,3 +1,4 @@ // "class org.jetbrains.kotlin.idea.intentions.CreateKotlinSubClassIntention" "false" +// ACTION: Create test -abstract class Base private constructor \ No newline at end of file +abstract class Base private constructor \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeReturnTypeOfOverriddenFunction.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeReturnTypeOfOverriddenFunction.kt index 375ec53bb47..a2fd8ca03c2 100644 --- a/idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeReturnTypeOfOverriddenFunction.kt +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeReturnTypeOfOverriddenFunction.kt @@ -9,5 +9,5 @@ interface B { } interface C : A, B { - override fun foo(): Long + override fun foo(): Long } diff --git a/idea/testData/quickfix/suppress/declarationKinds/enumEntry.kt b/idea/testData/quickfix/suppress/declarationKinds/enumEntry.kt index b31b568a035..962ba5e13d0 100644 --- a/idea/testData/quickfix/suppress/declarationKinds/enumEntry.kt +++ b/idea/testData/quickfix/suppress/declarationKinds/enumEntry.kt @@ -2,6 +2,6 @@ enum class E { A { - fun foo(): String?? = null + fun foo(): String?? = null } } \ No newline at end of file diff --git a/idea/testData/quickfix/suppress/forStatement/simpleName.kt b/idea/testData/quickfix/suppress/forStatement/simpleName.kt index 178b4ae00bb..2dcf20b6dd9 100644 --- a/idea/testData/quickfix/suppress/forStatement/simpleName.kt +++ b/idea/testData/quickfix/suppress/forStatement/simpleName.kt @@ -2,5 +2,5 @@ fun foo() { val a = 1 - a + a } \ No newline at end of file diff --git a/idea/testData/quickfix/typeAddition/propertyWithRecursiveGetter.kt b/idea/testData/quickfix/typeAddition/propertyWithRecursiveGetter.kt index 168a399aab7..a25bed2ec65 100644 --- a/idea/testData/quickfix/typeAddition/propertyWithRecursiveGetter.kt +++ b/idea/testData/quickfix/typeAddition/propertyWithRecursiveGetter.kt @@ -1,7 +1,10 @@ // "Specify type explicitly" "false" // ERROR: This property must either have a type annotation, be initialized or be delegated +// ACTION: Convert member to extension +// ACTION: Convert property to function +// ACTION: Move to companion object class A { - val a + val a get() = a } \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/casts/typeMismatch2.kt b/idea/testData/quickfix/typeMismatch/casts/typeMismatch2.kt index f603de373d0..cd03cdcaf4f 100644 --- a/idea/testData/quickfix/typeMismatch/casts/typeMismatch2.kt +++ b/idea/testData/quickfix/typeMismatch/casts/typeMismatch2.kt @@ -1,8 +1,9 @@ // "Cast expression 'Foo()' to 'Foo'" "false" -// ACTION: Create test +// ACTION: Change 'foo' function return type to 'Foo' +// ACTION: Convert to expression body // ERROR: Type mismatch: inferred type is Foo but Foo was expected class Foo fun foo(): Foo { - return Foo() + return Foo() } \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/tooManyArgumentsException.kt b/idea/testData/quickfix/typeMismatch/tooManyArgumentsException.kt index 528622d1109..98c17195779 100644 --- a/idea/testData/quickfix/typeMismatch/tooManyArgumentsException.kt +++ b/idea/testData/quickfix/typeMismatch/tooManyArgumentsException.kt @@ -1,12 +1,16 @@ // "???" "false" -//ERROR: Type mismatch: inferred type is Array but Array was expected +// ERROR: Type mismatch: inferred type is Array but Array was expected +// ACTION: Change parameter 't' type of function 'join' to 'Array' +// ACTION: Create function 'join' +// ACTION: Flip ',' +// ACTION: Introduce local variable //this test checks that there is no ArrayIndexOutOfBoundsException when there are more arguments than parameters fun array1(vararg a : T) = a fun main(args : Array) { val b = array1(1, 1) - join(1, "4", *b, "3") + join(1, "4", *b, "3") } fun join(x : Int, vararg t : String) : String = "$x$t" diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.java index 95c80d0acda..878e362762c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.java @@ -136,6 +136,8 @@ public abstract class AbstractIntentionTest extends KotlinCodeInsightTestCase { String fileText = FileUtil.loadFile(mainFile, true); + assertTrue("\"\" is missing in file \"" + mainFile + "\"", fileText.contains("")); + String minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: "); if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return; diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixMultiFileTest.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixMultiFileTest.java index aff168ecd89..c9eced5704f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixMultiFileTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixMultiFileTest.java @@ -220,6 +220,8 @@ public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzer configureByExistingFile(virtualFiles.get(beforeFile)); assertEquals(guessFileType(beforeFile), myFile.getVirtualFile().getFileType()); + + assertTrue("\"\" is probably missing in file \"" + beforeFile.path + "\"", myEditor.getCaretModel().getOffset() != 0); } catch (IOException e) { throw new RuntimeException(e); diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java index 8ad1cc3157d..39f9ddfc5ba 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java @@ -141,6 +141,7 @@ public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase { List fixtureClasses = Collections.emptyList(); try { fileText = FileUtil.loadFile(testFile, CharsetToolkit.UTF8_CHARSET); + assertTrue("\"\" is missing in file \"" + testName + "\"", fileText.contains("")); fixtureClasses = InTextDirectivesUtils.findListWithPrefixes(fileText, "// FIXTURE_CLASS: "); for (String fixtureClass : fixtureClasses) {