Search in sources :

Example 11 with FileComparisonFailure

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);
}
Also used : Project(com.intellij.openapi.project.Project) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure) ComparisonFailure(junit.framework.ComparisonFailure) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) EditorWindow(com.intellij.injected.editor.EditorWindow) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 12 with FileComparisonFailure

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);
    }
}
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 13 with FileComparisonFailure

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);
            }
        }
    }, "", "");
}
Also used : List(java.util.List) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) 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