Search in sources :

Example 6 with FileComparisonFailure

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());
}
Also used : File(java.io.File) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 7 with FileComparisonFailure

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);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 8 with FileComparisonFailure

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);
    });
}
Also used : Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 9 with FileComparisonFailure

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());
}
Also used : TestDataFile(com.intellij.testFramework.TestDataFile) File(java.io.File) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 10 with FileComparisonFailure

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);
    });
}
Also used : Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Aggregations

FileComparisonFailure (com.intellij.rt.execution.junit.FileComparisonFailure)13 File (java.io.File)10 Document (com.intellij.openapi.editor.Document)3 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)2 Project (com.intellij.openapi.project.Project)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 List (java.util.List)2 AssertionFailedError (junit.framework.AssertionFailedError)2 KtFile (org.jetbrains.kotlin.psi.KtFile)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)1 Task (com.intellij.openapi.progress.Task)1 AbstractProgressIndicatorBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorBase)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 PsiElement (com.intellij.psi.PsiElement)1