Add ability to test for expected errors in intentions
If an intention test contains `// SHOULD_FAIL_WITH: my_string`, the test
is expected to throw `IntentionTestException("my_string")`. This is
useful for testing whether or not a function that should be called, is
called (a pop-up dialog is displayed, etc.).
This commit is contained in:
@@ -170,9 +170,19 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes
|
|||||||
"isAvailable() for " + intentionAction.getClass() + " should return " + isApplicableExpected,
|
"isAvailable() for " + intentionAction.getClass() + " should return " + isApplicableExpected,
|
||||||
isApplicableExpected == intentionAction.isAvailable(getProject(), getEditor(), getFile()));
|
isApplicableExpected == intentionAction.isAvailable(getProject(), getEditor(), getFile()));
|
||||||
|
|
||||||
if (isApplicableExpected) {
|
String shouldFailString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// SHOULD_FAIL_WITH: ");
|
||||||
intentionAction.invoke(getProject(), getEditor(), getFile());
|
|
||||||
checkResultByFile(path + ".after");
|
try {
|
||||||
|
if (isApplicableExpected) {
|
||||||
|
intentionAction.invoke(getProject(), getEditor(), getFile());
|
||||||
|
// Don't bother checking if it should have failed.
|
||||||
|
if (shouldFailString == null) {
|
||||||
|
checkResultByFile(path + ".after");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertNull("Expected test to fail.", shouldFailString);
|
||||||
|
} catch (IntentionTestException e) {
|
||||||
|
assertEquals("Failure message mismatch.", shouldFailString, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.intentions;
|
||||||
|
|
||||||
|
public class IntentionTestException(message: String): RuntimeException(message)
|
||||||
Reference in New Issue
Block a user