use of com.intellij.rt.execution.junit.FileComparisonFailure in project intellij-community by JetBrains.
the class CodeInsightTestFixtureImpl method checkResult.
private void checkResult(@NotNull String expectedFile, boolean stripTrailingSpaces, @NotNull SelectionAndCaretMarkupLoader loader, @NotNull String actualText) {
assertInitialized();
Project project = getProject();
Editor editor = getEditor();
if (editor instanceof EditorWindow) {
editor = ((EditorWindow) editor).getDelegate();
}
UsefulTestCase.doPostponedFormatting(getProject());
if (stripTrailingSpaces) {
actualText = stripTrailingSpaces(actualText);
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
String newFileText1 = loader.newFileText;
if (stripTrailingSpaces) {
newFileText1 = stripTrailingSpaces(newFileText1);
}
actualText = StringUtil.convertLineSeparators(actualText);
if (!Comparing.equal(newFileText1, actualText)) {
if (loader.filePath != null) {
throw new FileComparisonFailure(expectedFile, newFileText1, actualText, loader.filePath);
} else {
throw new ComparisonFailure(expectedFile, newFileText1, actualText);
}
}
EditorTestUtil.verifyCaretAndSelectionState(editor, loader.caretState, expectedFile);
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project kotlin by JetBrains.
the class KtUsefulTestCase method assertSameLinesWithFile.
public static void assertSameLinesWithFile(String filePath, String actualText, boolean trimBeforeComparing) {
String fileText;
try {
fileText = FileUtil.loadFile(new File(filePath), CharsetToolkit.UTF8_CHARSET);
} catch (FileNotFoundException e) {
VfsTestUtil.overwriteTestData(filePath, actualText);
throw new AssertionFailedError("No output text found. File " + filePath + " created.");
} catch (IOException e) {
throw new RuntimeException(e);
}
String expected = StringUtil.convertLineSeparators(trimBeforeComparing ? fileText.trim() : fileText);
String actual = StringUtil.convertLineSeparators(trimBeforeComparing ? actualText.trim() : actualText);
if (!Comparing.equal(expected, actual)) {
throw new FileComparisonFailure(null, expected, actual, filePath);
}
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project kotlin by JetBrains.
the class AbstractQuickFixTest method doKotlinQuickFixTest.
private void doKotlinQuickFixTest(final String testName, final QuickFixTestCase quickFixTestCase) {
String relativePath = notNull(quickFixTestCase.getBasePath(), "") + "/" + StringsKt.decapitalize(testName);
final String testFullPath = quickFixTestCase.getTestDataPath().replace(File.separatorChar, '/') + relativePath;
final File testFile = new File(testFullPath);
CommandProcessor.getInstance().executeCommand(quickFixTestCase.getProject(), new Runnable() {
@SuppressWarnings({ "AssignmentToStaticFieldFromInstanceMethod", "CallToPrintStackTrace" })
@Override
public void run() {
String fileText = "";
String expectedErrorMessage = "";
List<String> fixtureClasses = Collections.emptyList();
try {
fileText = FileUtil.loadFile(testFile, CharsetToolkit.UTF8_CHARSET);
assertTrue("\"<caret>\" is missing in file \"" + testName + "\"", fileText.contains("<caret>"));
fixtureClasses = InTextDirectivesUtils.findListWithPrefixes(fileText, "// FIXTURE_CLASS: ");
for (String fixtureClass : fixtureClasses) {
TestFixtureExtension.Companion.loadFixture(fixtureClass, getModule());
}
expectedErrorMessage = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// SHOULD_FAIL_WITH: ");
String contents = StringUtil.convertLineSeparators(fileText);
quickFixTestCase.configureFromFileText(testFile.getName(), contents);
quickFixTestCase.bringRealEditorBack();
checkForUnexpectedActions();
configExtra(fileText);
applyAction(contents, quickFixTestCase, testName, testFullPath);
assertEmpty(expectedErrorMessage);
} catch (FileComparisonFailure e) {
throw e;
} catch (AssertionError e) {
throw e;
} catch (Throwable e) {
if (expectedErrorMessage == null || !expectedErrorMessage.equals(e.getMessage())) {
e.printStackTrace();
fail(testName);
}
} finally {
for (String fixtureClass : fixtureClasses) {
TestFixtureExtension.Companion.unloadFixture(fixtureClass);
}
ConfigLibraryUtil.unconfigureLibrariesByDirective(getModule(), fileText);
}
}
}, "", "");
}
Aggregations