use of junit.framework.ComparisonFailure 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 junit.framework.ComparisonFailure in project kotlin by JetBrains.
the class AbstractQuickFixMultiFileTest method doMultiFileTest.
protected void doMultiFileTest(final String beforeFileName) throws Exception {
String multifileText = FileUtil.loadFile(new File(beforeFileName), true);
boolean withRuntime = InTextDirectivesUtils.isDirectiveDefined(multifileText, "// WITH_RUNTIME");
if (withRuntime) {
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk());
}
try {
final List<TestFile> subFiles = KotlinTestUtils.createTestFiles("single.kt", multifileText, new KotlinTestUtils.TestFileFactoryNoModules<TestFile>() {
@NotNull
@Override
public TestFile create(@NotNull String fileName, @NotNull String text, @NotNull Map<String, String> directives) {
if (text.startsWith("// FILE")) {
String firstLineDropped = StringUtil.substringAfter(text, "\n");
assert firstLineDropped != null;
text = firstLineDropped;
}
return new TestFile(fileName, text);
}
});
final TestFile afterFile = CollectionsKt.firstOrNull(subFiles, new Function1<TestFile, Boolean>() {
@Override
public Boolean invoke(TestFile file) {
return file.path.contains(".after");
}
});
final TestFile beforeFile = CollectionsKt.firstOrNull(subFiles, new Function1<TestFile, Boolean>() {
@Override
public Boolean invoke(TestFile file) {
return file.path.contains(".before");
}
});
assert beforeFile != null;
subFiles.remove(beforeFile);
if (afterFile != null) {
subFiles.remove(afterFile);
}
configureMultiFileTest(subFiles, beforeFile);
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
try {
PsiFile psiFile = getFile();
Pair<String, Boolean> pair = LightQuickFixTestCase.parseActionHint(psiFile, beforeFile.content);
String text = pair.getFirst();
boolean actionShouldBeAvailable = pair.getSecond();
if (psiFile instanceof KtFile) {
DirectiveBasedActionUtils.INSTANCE.checkForUnexpectedErrors((KtFile) psiFile);
}
doAction(text, actionShouldBeAvailable, getTestName(false));
String actualText = getFile().getText();
String afterText = new StringBuilder(actualText).insert(getEditor().getCaretModel().getOffset(), "<caret>").toString();
if (pair.second) {
assertNotNull(".after file should exist", afterFile);
if (!afterText.equals(afterFile.content)) {
StringBuilder actualTestFile = new StringBuilder();
actualTestFile.append("// FILE: ").append(beforeFile.path).append("\n").append(beforeFile.content);
for (TestFile file : subFiles) {
actualTestFile.append("// FILE: ").append(file.path).append("\n").append(file.content);
}
actualTestFile.append("// FILE: ").append(afterFile.path).append("\n").append(afterText);
KotlinTestUtils.assertEqualsToFile(new File(beforeFileName), actualTestFile.toString());
}
} else {
assertNull(".after file should not exist", afterFile);
}
} catch (ComparisonFailure e) {
throw e;
} catch (AssertionError e) {
throw e;
} catch (Throwable e) {
e.printStackTrace();
fail(getTestName(true));
}
}
}, "", "");
} finally {
if (withRuntime) {
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk());
}
}
}
use of junit.framework.ComparisonFailure in project kotlin by JetBrains.
the class AbstractIntentionTest method doTestFor.
private void doTestFor(String mainFilePath, Map<String, PsiFile> pathToFiles, final IntentionAction intentionAction, String fileText) throws Exception {
String isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// " + isApplicableDirectiveName() + ": ");
boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");
boolean isApplicableOnPooled = ApplicationManager.getApplication().executeOnPooledThread(new java.util.concurrent.Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return intentionAction.isAvailable(getProject(), getEditor(), getFile());
}
});
}
}).get();
boolean isApplicableOnEdt = intentionAction.isAvailable(getProject(), getEditor(), getFile());
Assert.assertEquals("There should not be any difference what thread isApplicable is called from", isApplicableOnPooled, isApplicableOnEdt);
Assert.assertTrue("isAvailable() for " + intentionAction.getClass() + " should return " + isApplicableExpected, isApplicableExpected == isApplicableOnEdt);
String intentionTextString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// " + intentionTextDirectiveName() + ": ");
if (intentionTextString != null) {
assertEquals("Intention text mismatch.", intentionTextString, intentionAction.getText());
}
String shouldFailString = StringUtil.join(InTextDirectivesUtils.findListWithPrefixes(fileText, "// SHOULD_FAIL_WITH: "), ", ");
try {
if (isApplicableExpected) {
ApplicationUtilsKt.executeWriteCommand(getProject(), intentionAction.getText(), null, new Function0<Object>() {
@Override
public Object invoke() {
intentionAction.invoke(getProject(), getEditor(), getFile());
return null;
}
});
// Don't bother checking if it should have failed.
if (shouldFailString.isEmpty()) {
for (Map.Entry<String, PsiFile> entry : pathToFiles.entrySet()) {
String filePath = entry.getKey();
String canonicalPathToExpectedFile = PathUtil.getCanonicalPath(filePath + afterFileNameSuffix());
if (filePath.equals(mainFilePath)) {
try {
checkResultByFile(canonicalPathToExpectedFile);
} catch (ComparisonFailure e) {
KotlinTestUtils.assertEqualsToFile(new File(canonicalPathToExpectedFile), getEditor().getDocument().getText());
}
} else {
KotlinTestUtils.assertEqualsToFile(new File(canonicalPathToExpectedFile), entry.getValue().getText());
}
}
}
}
assertEquals("Expected test to fail.", "", shouldFailString);
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
assertEquals("Failure message mismatch.", shouldFailString, StringUtil.join(e.getMessages(), ", "));
} catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
assertEquals("Failure message mismatch.", shouldFailString, e.getMessage().replace('\n', ' '));
}
}
use of junit.framework.ComparisonFailure in project poi by apache.
the class TestSharedFormulaRecord method confirmOperandClasses.
private static void confirmOperandClasses(Ptg[] originalPtgs, Ptg[] convertedPtgs) {
assertEquals(originalPtgs.length, convertedPtgs.length);
for (int i = 0; i < convertedPtgs.length; i++) {
Ptg originalPtg = originalPtgs[i];
Ptg convertedPtg = convertedPtgs[i];
if (originalPtg.getPtgClass() != convertedPtg.getPtgClass()) {
throw new ComparisonFailure("Different operand class for token[" + i + "]", String.valueOf(originalPtg.getPtgClass()), String.valueOf(convertedPtg.getPtgClass()));
}
}
}
use of junit.framework.ComparisonFailure in project poi by apache.
the class TestNumberToTextConverter method testAll.
/**
* Confirms that <tt>ExcelNumberToTextConverter.toText(d)</tt> produces the right results.
* As part of preparing this test class, the <tt>ExampleConversion</tt> instances should be set
* up to contain the rendering as produced by Excel.
*/
public void testAll() {
int failureCount = 0;
ExampleConversion[] examples = NumberToTextConversionExamples.getExampleConversions();
for (int i = 0; i < examples.length; i++) {
ExampleConversion example = examples[i];
try {
if (example.isNaN()) {
confirmNaN(example.getRawDoubleBits(), example.getExcelRendering());
continue;
}
String actual = NumberToTextConverter.toText(example.getDoubleValue());
if (!example.getExcelRendering().equals(actual)) {
failureCount++;
String msg = "Error rendering for examples[" + i + "] " + formatExample(example) + " " + " bad-result='" + actual + "' " + new ComparisonFailure(null, example.getExcelRendering(), actual).getMessage();
System.err.println(msg);
continue;
}
} catch (RuntimeException e) {
failureCount++;
System.err.println("Error in excel rendering for examples[" + i + "] " + formatExample(example) + "':" + e.getMessage());
e.printStackTrace();
}
}
if (failureCount > 0) {
throw new AssertionFailedError(failureCount + " error(s) in excel number to text conversion (see std-err)");
}
}
Aggregations