Now possible to use // WITH_RUNTIME in multi file tests
This commit is contained in:
committed by
Dmitry Jemerov
parent
da2ebb1394
commit
b06bdcef75
@@ -232,94 +232,107 @@ public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzer
|
|||||||
protected void doMultiFileTest(final String beforeFileName) throws Exception {
|
protected void doMultiFileTest(final String beforeFileName) throws Exception {
|
||||||
String multifileText = FileUtil.loadFile(new File(beforeFileName), true);
|
String multifileText = FileUtil.loadFile(new File(beforeFileName), true);
|
||||||
|
|
||||||
final List<TestFile> subFiles = KotlinTestUtils.createTestFiles(
|
boolean withRuntime = InTextDirectivesUtils.isDirectiveDefined(multifileText, "// WITH_RUNTIME");
|
||||||
"single.kt",
|
if (withRuntime) {
|
||||||
multifileText,
|
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk());
|
||||||
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);
|
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;
|
||||||
|
|
||||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
text = firstLineDropped;
|
||||||
@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);
|
return new TestFile(fileName, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(new File(beforeFileName), actualTestFile.toString());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
catch (ComparisonFailure e) {
|
||||||
assertNull(".after file should not exist", afterFile);
|
throw e;
|
||||||
|
}
|
||||||
|
catch (AssertionError e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail(getTestName(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ComparisonFailure e) {
|
}, "", "");
|
||||||
throw e;
|
}
|
||||||
}
|
finally {
|
||||||
catch (AssertionError e) {
|
if (withRuntime) {
|
||||||
throw e;
|
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk());
|
||||||
}
|
|
||||||
catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
fail(getTestName(true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, "", "");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(final String beforeFileName, boolean withExtraFile) throws Exception {
|
private void doTest(final String beforeFileName, boolean withExtraFile) throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user