use of com.intellij.rt.execution.junit.FileComparisonFailure in project intellij-community by JetBrains.
the class SkeletonTestTask method runTestOn.
@Override
public void runTestOn(@NotNull final String sdkHome) throws IOException, InvalidSdkException {
final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
final File skeletonsPath = new File(PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath()));
// File with module skeleton
File skeletonFileOrDirectory = new File(skeletonsPath, myModuleNameToBeGenerated);
// Module may be stored in "moduleName.py" or "moduleName/__init__.py"
if (skeletonFileOrDirectory.isDirectory()) {
skeletonFileOrDirectory = new File(skeletonFileOrDirectory, PyNames.INIT_DOT_PY);
} else {
skeletonFileOrDirectory = new File(skeletonFileOrDirectory.getAbsolutePath() + PyNames.DOT_PY);
}
final File skeletonFile = skeletonFileOrDirectory;
if (skeletonFile.exists()) {
// To make sure we do not reuse it
assert skeletonFile.delete() : "Failed to delete file " + skeletonFile;
}
ApplicationManager.getApplication().invokeAndWait(() -> {
// File that uses CLR library
myFixture.copyFileToProject("dotNet/" + mySourceFileToRunGenerationOn, mySourceFileToRunGenerationOn);
// Library itself
myFixture.copyFileToProject("dotNet/PythonLibs.dll", "PythonLibs.dll");
// Another library
myFixture.copyFileToProject("dotNet/SingleNameSpace.dll", "SingleNameSpace.dll");
myFixture.configureByFile(mySourceFileToRunGenerationOn);
}, ModalityState.NON_MODAL);
// This inspection should suggest us to generate stubs
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments();
final String intentionName = PyBundle.message("sdk.gen.stubs.for.binary.modules", myUseQuickFixWithThisModuleOnly);
final IntentionAction intention = myFixture.findSingleIntention(intentionName);
Assert.assertNotNull("No intention found to generate skeletons!", intention);
Assert.assertThat("Intention should be quick fix to run", intention, Matchers.instanceOf(QuickFixWrapper.class));
final LocalQuickFix quickFix = ((QuickFixWrapper) intention).getFix();
Assert.assertThat("Quick fix should be 'generate binary skeletons' fix to run", quickFix, Matchers.instanceOf(GenerateBinaryStubsFix.class));
final Task fixTask = ((GenerateBinaryStubsFix) quickFix).getFixTask(myFixture.getFile());
fixTask.run(new AbstractProgressIndicatorBase());
}
});
FileUtil.copy(skeletonFile, new File(myFixture.getTempDirPath(), skeletonFile.getName()));
if (myExpectedSkeletonFile != null) {
final String actual = StreamUtil.readText(new FileInputStream(skeletonFile), Charset.defaultCharset());
final String skeletonText = StreamUtil.readText(new FileInputStream(new File(getTestDataPath(), myExpectedSkeletonFile)), Charset.defaultCharset());
// TODO: Move to separate method ?
if (!Matchers.equalToIgnoringWhiteSpace(removeGeneratorVersion(skeletonText)).matches(removeGeneratorVersion(actual))) {
throw new FileComparisonFailure("asd", skeletonText, actual, skeletonFile.getAbsolutePath());
}
}
myFixture.configureByFile(skeletonFile.getName());
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project kotlin by JetBrains.
the class WordSelectionTest method doTest.
private void doTest() {
String dirName = getTestName(false);
File dir = new File(myFixture.getTestDataPath() + dirName);
int filesCount = dir.listFiles().length;
String[] afterFiles = new String[filesCount - 1];
for (int i = 1; i < filesCount; i++) {
afterFiles[i - 1] = dirName + File.separator + i + ".kt";
}
try {
CodeInsightTestUtil.doWordSelectionTest(myFixture, dirName + File.separator + "0.kt", afterFiles);
} catch (FileComparisonFailure error) {
wrapToFileComparisonFailure(error.getFilePath());
} catch (AssertionError error) {
String message = error.getMessage();
String path = message.substring(0, message.indexOf(":"));
String fullPath = new File(new File(PluginTestCaseBase.getTestDataPathBase(), TEST_RELATIVE_DIR), path).getPath();
wrapToFileComparisonFailure(fullPath);
}
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project kotlin by JetBrains.
the class AbstractLineMarkersTest method doTest.
public void doTest(String path) {
try {
String fileText = FileUtil.loadFile(new File(path));
ConfigLibraryUtil.configureLibrariesByDirective(myFixture.getModule(), PlatformTestUtil.getCommunityPath(), fileText);
myFixture.configureByFile(path);
Project project = myFixture.getProject();
Document document = myFixture.getEditor().getDocument();
ExpectedHighlightingData data = new ExpectedHighlightingData(document, false, false, false, myFixture.getFile());
data.init();
PsiDocumentManager.getInstance(project).commitAllDocuments();
myFixture.doHighlighting();
List<LineMarkerInfo> markers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project);
try {
data.checkLineMarkers(markers, document.getText());
// the latter doesn't throw assertion error when some line markers are expected, but none are present.
if (FileUtil.loadFile(new File(path)).contains("<lineMarker") && markers.isEmpty()) {
throw new AssertionError("Some line markers are expected, but nothing is present at all");
}
} catch (AssertionError error) {
try {
String actualTextWithTestData = TagsTestDataUtil.insertInfoTags(markers, true, myFixture.getFile().getText());
KotlinTestUtils.assertEqualsToFile(new File(path), actualTextWithTestData);
} catch (FileComparisonFailure failure) {
throw new FileComparisonFailure(error.getMessage() + "\n" + failure.getMessage(), failure.getExpected(), failure.getActual(), failure.getFilePath());
}
}
assertNavigationElements(markers);
} catch (Exception exc) {
throw new RuntimeException(exc);
}
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project kotlin by JetBrains.
the class AbstractQuickDocProviderTest method doTest.
public void doTest(@NotNull String path) throws Exception {
IdeaTestUtilsKt.configureWithExtraFileAbs(myFixture, path, "_Data");
PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
assertNotNull("Can't find element at caret in file: " + path, element);
DocumentationManager documentationManager = DocumentationManager.getInstance(myFixture.getProject());
PsiElement targetElement = documentationManager.findTargetElement(myFixture.getEditor(), myFixture.getFile());
PsiElement originalElement = DocumentationManager.getOriginalElement(targetElement);
String info = DocumentationManager.getProviderFromElement(targetElement).generateDoc(targetElement, originalElement);
if (info != null) {
info = StringUtil.convertLineSeparators(info);
}
if (info != null && !info.endsWith("\n")) {
info += "\n";
}
File testDataFile = new File(path);
String textData = FileUtil.loadFile(testDataFile, true);
List<String> directives = InTextDirectivesUtils.findLinesWithPrefixesRemoved(textData, false, "INFO:");
if (directives.isEmpty()) {
throw new FileComparisonFailure("'// INFO:' directive was expected", textData, textData + "\n\n//INFO: " + info, testDataFile.getAbsolutePath());
} else {
StringBuilder expectedInfoBuilder = new StringBuilder();
for (String directive : directives) {
expectedInfoBuilder.append(directive).append("\n");
}
String expectedInfo = expectedInfoBuilder.toString();
if (expectedInfo.endsWith("...\n")) {
if (!info.startsWith(StringUtil.trimEnd(expectedInfo, "...\n"))) {
wrapToFileComparisonFailure(info, path, textData);
}
} else if (!expectedInfo.equals(info)) {
wrapToFileComparisonFailure(info, path, textData);
}
}
}
use of com.intellij.rt.execution.junit.FileComparisonFailure in project kotlin by JetBrains.
the class AbstractHighlightingTest method doTest.
protected void doTest(String filePath) throws Exception {
String fileText = FileUtil.loadFile(new File(filePath), true);
boolean checkInfos = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_INFOS");
boolean checkWeakWarnings = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_WEAK_WARNINGS");
boolean checkWarnings = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_WARNINGS");
myFixture.configureByFile(filePath);
try {
myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings);
} catch (FileComparisonFailure e) {
List<HighlightInfo> highlights = DaemonCodeAnalyzerImpl.getHighlights(myFixture.getDocument(myFixture.getFile()), null, myFixture.getProject());
String text = myFixture.getFile().getText();
System.out.println(TagsTestDataUtil.insertInfoTags(highlights, text));
throw e;
}
}
Aggregations