Check errors and are all actions are expected in quick fixes tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
// "Import" "true"
|
// "Import" "true"
|
||||||
|
// ERROR: Unresolved reference: TestSample
|
||||||
|
|
||||||
import TestData.TestSample
|
import TestData.TestSample
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Import" "true"
|
// "Import" "true"
|
||||||
|
// ERROR: Unresolved reference: TestSample
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val a = <caret>TestSample
|
val a = <caret>TestSample
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Import" "true"
|
// "Import" "true"
|
||||||
|
// ERROR: Unresolved reference: someFun
|
||||||
package testingExtensionFunctionsImport
|
package testingExtensionFunctionsImport
|
||||||
|
|
||||||
import testingExtensionFunctionsImport.data.someFun
|
import testingExtensionFunctionsImport.data.someFun
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Import" "true"
|
// "Import" "true"
|
||||||
|
// ERROR: Unresolved reference: someFun
|
||||||
package testingExtensionFunctionsImport
|
package testingExtensionFunctionsImport
|
||||||
|
|
||||||
fun some() {
|
fun some() {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
// "Import" "true"
|
// "Import" "true"
|
||||||
|
// ERROR: Unresolved reference: someTestFun
|
||||||
|
|
||||||
package functionimporttest
|
package functionimporttest
|
||||||
|
|
||||||
import functionimporttest.data.someTestFun
|
import functionimporttest.data.someTestFun
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
// "Import" "true"
|
// "Import" "true"
|
||||||
|
// ERROR: Unresolved reference: someTestFun
|
||||||
|
|
||||||
package functionimporttest
|
package functionimporttest
|
||||||
|
|
||||||
fun functionImportTest() {
|
fun functionImportTest() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Import Class" "false"
|
// "Import Class" "false"
|
||||||
|
// ERROR: Unresolved reference: PrivateClass
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
PrivateClass
|
PrivateClass
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Import" "false"
|
// "Import" "false"
|
||||||
|
// ERROR: Unresolved reference: PrivateClass
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
<caret>PrivateClass
|
<caret>PrivateClass
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// "Import" "false"
|
// "Import" "false"
|
||||||
// ACTION: Change to constructor invocation
|
|
||||||
// ERROR: Unresolved reference: SomeTest
|
// ERROR: Unresolved reference: SomeTest
|
||||||
|
|
||||||
package testing
|
package testing
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// "Import" "false"
|
// "Import" "false"
|
||||||
// ACTION: Change to constructor invocation
|
|
||||||
// ERROR: Unresolved reference: SomeTest
|
// ERROR: Unresolved reference: SomeTest
|
||||||
|
|
||||||
package testing
|
package testing
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
// "Specify return type explicitly" "false"
|
// "Specify return type explicitly" "false"
|
||||||
// ERROR: Function 'foo' without a body must be abstract
|
// ERROR: Function 'foo' without a body must be abstract
|
||||||
|
// ACTION: Add function body
|
||||||
|
// ACTION: Make 'foo' abstract
|
||||||
|
|
||||||
package a
|
package a
|
||||||
|
|
||||||
class A() {
|
class A() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Specify type explicitly" "true"
|
// "Specify type explicitly" "true"
|
||||||
|
// ERROR: Public or protected member should have specified type
|
||||||
|
|
||||||
package a
|
package a
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// "Specify type explicitly" "true"
|
// "Specify type explicitly" "true"
|
||||||
|
// ERROR: Public or protected member should have specified type
|
||||||
|
|
||||||
package a
|
package a
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.quickfix;
|
package org.jetbrains.jet.plugin.quickfix;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||||
@@ -27,13 +26,12 @@ import com.intellij.openapi.projectRoots.Sdk;
|
|||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.util.ui.UIUtil;
|
import com.intellij.util.ui.UIUtil;
|
||||||
import junit.framework.ComparisonFailure;
|
import junit.framework.ComparisonFailure;
|
||||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nikolay Krasko
|
* @author Nikolay Krasko
|
||||||
@@ -64,9 +62,11 @@ public abstract class JetQuickFixMultiFileTest extends DaemonAnalyzerTestCase {
|
|||||||
|
|
||||||
final boolean actionShouldBeAvailable = pair.getSecond();
|
final boolean actionShouldBeAvailable = pair.getSecond();
|
||||||
|
|
||||||
|
QuickFixActionsUtils.checkForUnexpectedErrors((JetFile) getFile());
|
||||||
|
|
||||||
doAction(text, actionShouldBeAvailable, getTestDataPath());
|
doAction(text, actionShouldBeAvailable, getTestDataPath());
|
||||||
}
|
}
|
||||||
catch (ComparisonFailure e){
|
catch (ComparisonFailure e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
@@ -93,13 +93,7 @@ public abstract class JetQuickFixMultiFileTest extends DaemonAnalyzerTestCase {
|
|||||||
"Infos:" + infos);
|
"Infos:" + infos);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Set<String> validActions = Sets.newHashSet(InTextDirectivesUtils.findLinesWithPrefixRemoved("// ACTION:", getFile().getText()));
|
QuickFixActionsUtils.checkAvailableActionsAreExpected((JetFile) getFile(), availableActions);
|
||||||
for (IntentionAction availableAction : availableActions) {
|
|
||||||
if (!validActions.contains(availableAction.getText())) {
|
|
||||||
fail(String.format("Unexpected action available at current position: %s. Use // ACTION: directive",
|
|
||||||
availableAction.getText()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -18,27 +18,25 @@ package org.jetbrains.jet.plugin.quickfix;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||||
|
import com.intellij.codeInsight.intention.IntentionAction;
|
||||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
import com.intellij.openapi.projectRoots.Sdk;
|
||||||
import junit.framework.Assert;
|
import com.intellij.openapi.util.Pair;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
import org.apache.commons.lang.SystemUtils;
|
import org.apache.commons.lang.SystemUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
import org.jetbrains.jet.plugin.highlighter.IdeErrorMessages;
|
|
||||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
|
||||||
import org.jetbrains.jet.testing.ConfigRuntimeUtil;
|
import org.jetbrains.jet.testing.ConfigRuntimeUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
@@ -117,45 +115,35 @@ public class JetQuickFixTest extends LightQuickFixTestCase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
doSingleTest(name.substring("before".length()) + ".kt");
|
doSingleTest(name.substring("before".length()) + ".kt");
|
||||||
|
checkAvailableActionsAreExpected();
|
||||||
checkForUnexpectedErrors();
|
checkForUnexpectedErrors();
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
if (isWithRuntime) {
|
if (isWithRuntime) {
|
||||||
ConfigRuntimeUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
|
ConfigRuntimeUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkForUnexpectedErrors() {
|
public void checkAvailableActionsAreExpected() {
|
||||||
AnalyzeExhaust exhaust = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile((JetFile) getFile());
|
List<IntentionAction> actions = getAvailableActions();
|
||||||
Collection<Diagnostic> diagnostics = exhaust.getBindingContext().getDiagnostics();
|
final Pair<String, Boolean> pair = parseActionHintImpl(getFile(), getEditor().getDocument().getText());
|
||||||
|
if (!pair.getSecond()) {
|
||||||
if (diagnostics.size() != 0) {
|
// Action shouldn't be found. Check that other actions are expected and thus tested action isn't there under another name.
|
||||||
List<String> expectedErrorStrings = InTextDirectivesUtils.findLinesWithPrefixRemoved("// ERROR:", getFile().getText());
|
QuickFixActionsUtils.checkAvailableActionsAreExpected((JetFile) getFile(), actions);
|
||||||
|
|
||||||
Collection<String> expectedErrors = new HashSet<String>(expectedErrorStrings);
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
boolean hasErrors = false;
|
|
||||||
|
|
||||||
for (Diagnostic diagnostic : diagnostics) {
|
|
||||||
if (diagnostic.getSeverity() == Severity.ERROR) {
|
|
||||||
String errorText = IdeErrorMessages.RENDERER.render(diagnostic);
|
|
||||||
if (!expectedErrors.contains(errorText)) {
|
|
||||||
hasErrors = true;
|
|
||||||
builder.append("// ERROR: ").append(errorText).append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.assertFalse("There should be no unexpected errors after applying fix (Use \"// ERROR:\" directive): \n" + builder.toString(), hasErrors);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkForUnexpectedErrors() {
|
||||||
|
QuickFixActionsUtils.checkForUnexpectedErrors((JetFile) getFile());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBasePath() {
|
protected String getBasePath() {
|
||||||
return "/quickfix/" + dataPath;
|
return "/quickfix/" + dataPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected String getTestDataPath() {
|
protected String getTestDataPath() {
|
||||||
return PluginTestCaseBase.getTestDataPathBase();
|
return PluginTestCaseBase.getTestDataPathBase();
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.jet.plugin.quickfix;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Collections2;
|
||||||
|
import com.google.common.collect.Ordering;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import com.intellij.codeInsight.intention.IntentionAction;
|
||||||
|
import com.intellij.testFramework.UsefulTestCase;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.plugin.highlighter.IdeErrorMessages;
|
||||||
|
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class QuickFixActionsUtils {
|
||||||
|
private QuickFixActionsUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkForUnexpectedErrors(JetFile file) {
|
||||||
|
AnalyzeExhaust exhaust = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
||||||
|
|
||||||
|
Collection<Diagnostic> diagnostics = exhaust.getBindingContext().getDiagnostics();
|
||||||
|
Collection<Diagnostic> errorDiagnostics = Collections2.filter(diagnostics, new Predicate<Diagnostic>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(@Nullable Diagnostic diagnostic) {
|
||||||
|
assert (diagnostic != null);
|
||||||
|
return diagnostic.getSeverity() == Severity.ERROR;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Collection<String> actualErrorStrings = Collections2.transform(errorDiagnostics, new Function<Diagnostic, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(@Nullable Diagnostic diagnostic) {
|
||||||
|
assert (diagnostic != null);
|
||||||
|
return IdeErrorMessages.RENDERER.render(diagnostic);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
List<String> expectedErrorStrings = InTextDirectivesUtils.findLinesWithPrefixRemoved("// ERROR:", file.getText());
|
||||||
|
Collections.sort(expectedErrorStrings);
|
||||||
|
|
||||||
|
UsefulTestCase.assertOrderedEquals(
|
||||||
|
"All actual errors should be mentioned in test data with // ERROR: directive. But no unnecessary errors should be me mentioned",
|
||||||
|
Ordering.natural().sortedCopy(actualErrorStrings), expectedErrorStrings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkAvailableActionsAreExpected(JetFile file, Collection<IntentionAction> availableActions) {
|
||||||
|
List<String> validActions = Ordering.natural().sortedCopy(
|
||||||
|
Sets.newHashSet(InTextDirectivesUtils.findLinesWithPrefixRemoved("// ACTION:", file.getText())));
|
||||||
|
|
||||||
|
Collection<String> actualActions = Ordering.natural().sortedCopy(
|
||||||
|
Collections2.transform(availableActions, new Function<IntentionAction, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(@Nullable IntentionAction input) {
|
||||||
|
assert input != null;
|
||||||
|
return input.getText();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
UsefulTestCase.assertOrderedEquals("Some unexpected actions available at current position: %s. Use // ACTION: directive",
|
||||||
|
actualActions, validActions);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user