use of com.intellij.rt.execution.junit.FileComparisonFailure in project intellij-community by JetBrains.
the class ImmediatePainterTest method fail.
private void fail(@NotNull String message, @NotNull BufferedImage expectedImage, @NotNull BufferedImage actualImage) throws IOException {
File expectedImageFile = FileUtil.createTempFile(getName() + "-expected", ".png", false);
addTmpFileToKeep(expectedImageFile);
ImageIO.write(expectedImage, "png", expectedImageFile);
File actualImageFile = FileUtil.createTempFile(getName() + "-actual", ".png", false);
addTmpFileToKeep(actualImageFile);
ImageIO.write(actualImage, "png", actualImageFile);
throw new FileComparisonFailure(message, expectedImageFile.getAbsolutePath(), actualImageFile.getAbsolutePath(), expectedImageFile.getAbsolutePath(), actualImageFile.getAbsolutePath());
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project intellij-community by JetBrains.
the class UsefulTestCase method assertSameLinesWithFile.
public static void assertSameLinesWithFile(String filePath, String actualText, boolean trimBeforeComparing) {
String fileText;
try {
if (OVERWRITE_TESTDATA) {
VfsTestUtil.overwriteTestData(filePath, actualText);
//noinspection UseOfSystemOutOrSystemErr
System.out.println("File " + filePath + " created.");
}
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 intellij-community by JetBrains.
the class LightPlatformCodeInsightTestCase method checkResultByTextWithoutPSI.
protected static void checkResultByTextWithoutPSI(final String message, @NotNull final Editor editor, @NotNull final String fileText, final boolean ignoreTrailingSpaces, final String filePath) {
ApplicationManager.getApplication().runWriteAction(() -> {
final Document fakeDocument = EditorFactory.getInstance().createDocument(fileText);
if (ignoreTrailingSpaces) {
((DocumentImpl) fakeDocument).stripTrailingSpaces(getProject());
}
EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument);
String newFileText = fakeDocument.getText();
String fileText1 = editor.getDocument().getText();
String failMessage = getMessage("Text mismatch", message);
if (filePath != null && !newFileText.equals(fileText1)) {
throw new FileComparisonFailure(failMessage, newFileText, fileText1, filePath);
}
assertEquals(failMessage, newFileText, fileText1);
EditorTestUtil.verifyCaretAndSelectionState(editor, carets, message);
});
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project intellij-community by JetBrains.
the class EditorPaintingTest method fail.
private void fail(@NotNull String message, @NotNull File expectedResultsFile, BufferedImage actualImage) throws IOException {
File savedImage = FileUtil.createTempFile(getName(), ".png", false);
addTmpFileToKeep(savedImage);
ImageIO.write(actualImage, "png", savedImage);
throw new FileComparisonFailure(message, expectedResultsFile.getAbsolutePath(), savedImage.getAbsolutePath(), expectedResultsFile.getAbsolutePath(), savedImage.getAbsolutePath());
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project intellij-community by JetBrains.
the class LightPlatformCodeInsightTestCase method checkResultByText.
/**
* Same as checkResultByFile but text is provided directly.
* @param message - this check specific message. Added to text, caret position, selection checking. May be null
* @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
*/
protected void checkResultByText(final String message, @NotNull String expectedFileText, final boolean ignoreTrailingSpaces, final String filePath) {
bringRealEditorBack();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
ApplicationManager.getApplication().runWriteAction(() -> {
final Document document = EditorFactory.getInstance().createDocument(expectedFileText);
if (ignoreTrailingSpaces) {
((DocumentImpl) document).stripTrailingSpaces(getProject());
}
EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(document);
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
String newFileText = document.getText();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
String fileText1 = myFile.getText();
String failMessage = getMessage("Text mismatch", message);
if (filePath != null && !newFileText.equals(fileText1)) {
throw new FileComparisonFailure(failMessage, newFileText, fileText1, filePath);
}
assertEquals(failMessage, newFileText, fileText1);
EditorTestUtil.verifyCaretAndSelectionState(myEditor, carets, message);
});
}
Aggregations