[Test] Remove dependencies on IDEA classes from test modules
Some of IDEA services (like in `com.intellij/execution`) was copied, because they are used in tests but jars with them compiled with jdk 11 and we run our tests on jdk 8, so their bytecode can not be read
This commit is contained in:
+3
-4
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.utils.KotlinPaths;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@WithMutedInDatabaseRunTest
|
||||
@@ -97,7 +96,7 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
|
||||
return content;
|
||||
}
|
||||
|
||||
private void check(String testDataDir, String baseName, String content) throws IOException {
|
||||
private void check(String testDataDir, String baseName, String content) {
|
||||
File expectedFile = new File(testDataDir, baseName + ".expected");
|
||||
String normalizedContent = normalizeOutput(new File(testDataDir), content);
|
||||
|
||||
@@ -162,7 +161,7 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextAvailable(ProcessEvent event, Key outputType) {
|
||||
public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
|
||||
if (outputType == ProcessOutputTypes.STDERR) {
|
||||
err.append(event.getText());
|
||||
}
|
||||
@@ -175,6 +174,6 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processTerminated(ProcessEvent event) {}
|
||||
public void processTerminated(@NotNull ProcessEvent event) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,7 @@ package org.jetbrains.kotlin.test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -130,16 +126,6 @@ public class KotlinTestUtils {
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, TEST_MODULE_NAME);
|
||||
|
||||
if ("true".equals(System.getProperty("kotlin.ni"))) {
|
||||
// Enable new inference for tests which do not declare their own language version settings
|
||||
CommonConfigurationKeysKt.setLanguageVersionSettings(configuration, new CompilerTestLanguageVersionSettings(
|
||||
Collections.emptyMap(),
|
||||
LanguageVersionSettingsImpl.DEFAULT.getApiVersion(),
|
||||
LanguageVersionSettingsImpl.DEFAULT.getLanguageVersion(),
|
||||
Collections.emptyMap()
|
||||
));
|
||||
}
|
||||
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, new MessageCollector() {
|
||||
@Override
|
||||
public void clear() {
|
||||
@@ -250,29 +236,6 @@ public class KotlinTestUtils {
|
||||
JvmResolveUtil.analyze(ktFiles, environment);
|
||||
}
|
||||
|
||||
public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) {
|
||||
assertEqualsToFile(expectedFile, editor, true);
|
||||
}
|
||||
|
||||
public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor, Boolean enableSelectionTags) {
|
||||
Caret caret = editor.getCaretModel().getCurrentCaret();
|
||||
List<TagsTestDataUtil.TagInfo> tags = Lists.newArrayList(
|
||||
new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret")
|
||||
);
|
||||
|
||||
if (enableSelectionTags) {
|
||||
int selectionStart = caret.getSelectionStart();
|
||||
int selectionEnd = caret.getSelectionEnd();
|
||||
|
||||
tags.add(new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"));
|
||||
tags.add(new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection"));
|
||||
}
|
||||
|
||||
String afterText = TagsTestDataUtil.insertTagsInText(tags, editor.getDocument().getText(), (TagsTestDataUtil.TagInfo t) -> null);
|
||||
|
||||
assertEqualsToFile(expectedFile, afterText);
|
||||
}
|
||||
|
||||
public static void assertEqualsToFile(@NotNull Path expectedFile, @NotNull String actual) {
|
||||
assertEqualsToFile(expectedFile.toFile(), actual);
|
||||
}
|
||||
@@ -389,31 +352,6 @@ public class KotlinTestUtils {
|
||||
return files;
|
||||
}
|
||||
|
||||
public static String getLastCommentedLines(@NotNull Document document) {
|
||||
List<CharSequence> resultLines = new ArrayList<>();
|
||||
for (int i = document.getLineCount() - 1; i >= 0; i--) {
|
||||
int lineStart = document.getLineStartOffset(i);
|
||||
int lineEnd = document.getLineEndOffset(i);
|
||||
if (document.getCharsSequence().subSequence(lineStart, lineEnd).toString().trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("//".equals(document.getCharsSequence().subSequence(lineStart, lineStart + 2).toString())) {
|
||||
resultLines.add(document.getCharsSequence().subSequence(lineStart + 2, lineEnd));
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Collections.reverse(resultLines);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (CharSequence line : resultLines) {
|
||||
result.append(line).append("\n");
|
||||
}
|
||||
result.delete(result.length() - 1, result.length());
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public enum CommentType {
|
||||
ALL,
|
||||
LINE_COMMENT,
|
||||
|
||||
@@ -1,241 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TagsTestDataUtil {
|
||||
public static String insertInfoTags(List<LineMarkerInfo> lineMarkers, boolean withDescription, String text) {
|
||||
List<LineMarkerTagPoint> lineMarkerPoints = toLineMarkerTagPoints(lineMarkers, withDescription);
|
||||
|
||||
return insertTagsInText(lineMarkerPoints, text, (TagInfo t) -> null);
|
||||
}
|
||||
|
||||
public static String insertInfoTags(List<HighlightInfo> highlights, String text) {
|
||||
List<HighlightTagPoint> highlightPoints = toHighlightTagPoints(highlights);
|
||||
|
||||
return insertTagsInText(highlightPoints, text, (TagInfo t) -> null);
|
||||
}
|
||||
|
||||
public static String generateTextWithCaretAndSelection(@NotNull Editor editor) {
|
||||
List<TagInfo> points = Lists.newArrayList();
|
||||
points.add(new TagInfo<String>(editor.getCaretModel().getOffset(), true, "caret"));
|
||||
if (editor.getSelectionModel().hasSelection()) {
|
||||
points.add(new TagInfo<String>(editor.getSelectionModel().getSelectionStart(), true, "selection"));
|
||||
points.add(new TagInfo<String>(editor.getSelectionModel().getSelectionEnd(), false, "selection"));
|
||||
}
|
||||
|
||||
return insertTagsInText(points, editor.getDocument().getText(), (TagInfo t) -> null);
|
||||
}
|
||||
|
||||
public static String insertTagsInText(List<? extends TagInfo> tags, String text, Function<TagInfo, String> computeExtraAttributes) {
|
||||
StringBuilder builder = new StringBuilder(text);
|
||||
|
||||
// Need to sort tags for inserting them in reverse order to have valid offsets for yet not inserted tags.
|
||||
// Can't just sort in reverse order but do sort plus reverse instead to preserve final order for tags with the same offset.
|
||||
List<? extends TagInfo> sortedTagPoints = Lists.reverse(tags.stream().sorted().collect(Collectors.toList()));
|
||||
|
||||
// Insert tags into text starting from the end for preventing invalidating previous tags offsets
|
||||
for (TagInfo point : sortedTagPoints) {
|
||||
String tagText;
|
||||
if (point.isStart) {
|
||||
String attributesString = point.getAttributesString();
|
||||
String extraAttributes = computeExtraAttributes.apply(point);
|
||||
|
||||
String allAttributes;
|
||||
if (extraAttributes != null) {
|
||||
allAttributes = attributesString + " " + extraAttributes;
|
||||
} else {
|
||||
allAttributes = attributesString;
|
||||
}
|
||||
|
||||
String closeSuffix = point.isClosed ? "/" : "";
|
||||
if (attributesString.isEmpty()) {
|
||||
tagText = String.format("<%s%s>", point.getName(), closeSuffix);
|
||||
}
|
||||
else {
|
||||
tagText = String.format("<%s %s%s>", point.getName(), allAttributes, closeSuffix);
|
||||
}
|
||||
}
|
||||
else {
|
||||
tagText = String.format("</%s>", point.getName());
|
||||
}
|
||||
|
||||
builder.insert(point.offset, tagText);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<LineMarkerTagPoint> toLineMarkerTagPoints(
|
||||
Collection<LineMarkerInfo> lineMarkers,
|
||||
boolean withDescription
|
||||
) {
|
||||
List<LineMarkerTagPoint> lineMarkerPoints = Lists.newArrayList();
|
||||
for (LineMarkerInfo markerInfo : lineMarkers) {
|
||||
lineMarkerPoints.add(new LineMarkerTagPoint(markerInfo.startOffset, true, markerInfo, withDescription));
|
||||
lineMarkerPoints.add(new LineMarkerTagPoint(markerInfo.endOffset, false, markerInfo, withDescription));
|
||||
}
|
||||
return lineMarkerPoints;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<HighlightTagPoint> toHighlightTagPoints(Collection<HighlightInfo> highlights) {
|
||||
List<HighlightTagPoint> highlightPoints = Lists.newArrayList();
|
||||
for (HighlightInfo highlight : highlights) {
|
||||
highlightPoints.add(new HighlightTagPoint(highlight.startOffset, true, highlight));
|
||||
highlightPoints.add(new HighlightTagPoint(highlight.endOffset, false, highlight));
|
||||
}
|
||||
return highlightPoints;
|
||||
}
|
||||
|
||||
public static class TagInfo<Data> implements Comparable<TagInfo<?>> {
|
||||
protected final int offset;
|
||||
protected final boolean isStart;
|
||||
protected final boolean isClosed;
|
||||
protected final boolean isFixed;
|
||||
public final Data data;
|
||||
|
||||
public TagInfo(int offset, boolean start, Data data) {
|
||||
this(offset, start, false, false, data);
|
||||
}
|
||||
|
||||
public TagInfo(int offset, boolean isStart, boolean isClosed, boolean isFixed, Data data) {
|
||||
if (isClosed && !isStart) {
|
||||
throw new IllegalArgumentException("isClosed should be true only for start tags");
|
||||
}
|
||||
|
||||
this.offset = offset;
|
||||
this.isStart = isStart;
|
||||
this.isClosed = isClosed;
|
||||
this.isFixed = isFixed;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull TagInfo<?> other) {
|
||||
if (offset != other.offset) {
|
||||
return ((Integer) offset).compareTo(other.offset);
|
||||
}
|
||||
|
||||
if (isStart != other.isStart) {
|
||||
// All "starts" should go after "ends" for same offset
|
||||
return isStart ? -1 : 1;
|
||||
}
|
||||
|
||||
if (isFixed || other.isFixed) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String thisTag = this.getName();
|
||||
String otherTag = other.getName();
|
||||
|
||||
// Invert order for end tags
|
||||
return thisTag.compareTo(otherTag) * (isStart ? -1 : 1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getAttributesString() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static class HighlightTagPoint extends TagInfo<HighlightInfo> {
|
||||
private final HighlightInfo highlightInfo;
|
||||
|
||||
private HighlightTagPoint(int offset, boolean start, HighlightInfo info) {
|
||||
super(offset, start, info);
|
||||
highlightInfo = info;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return highlightInfo.getSeverity().equals(HighlightSeverity.INFORMATION)
|
||||
? "info"
|
||||
: highlightInfo.getSeverity().toString().toLowerCase();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getAttributesString() {
|
||||
if (isStart) {
|
||||
if (highlightInfo.getDescription() != null) {
|
||||
return String.format("descr=\"%s\" textAttributesKey=\"%s\"",
|
||||
sanitizeLineBreaks(highlightInfo.getDescription()),
|
||||
highlightInfo.forcedTextAttributesKey
|
||||
);
|
||||
}
|
||||
else {
|
||||
return String.format("textAttributesKey=\"%s\"", highlightInfo.forcedTextAttributesKey);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LineMarkerTagPoint extends TagInfo<LineMarkerInfo> {
|
||||
private final boolean withDescription;
|
||||
|
||||
public LineMarkerTagPoint(int offset, boolean start, LineMarkerInfo info, boolean withDescription) {
|
||||
super(offset, start, info);
|
||||
this.withDescription = withDescription;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "lineMarker";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getAttributesString() {
|
||||
return withDescription ? String.format("descr=\"%s\"", sanitizeLineMarkerTooltip(data.getLineMarkerTooltip())) : "descr=\"*\"";
|
||||
}
|
||||
}
|
||||
|
||||
private static @NotNull String sanitizeLineMarkerTooltip(@Nullable String originalText) {
|
||||
if (originalText == null) return "null";
|
||||
String noHtmlTags = StringUtil.removeHtmlTags(originalText);
|
||||
return sanitizeLineBreaks(noHtmlTags);
|
||||
}
|
||||
|
||||
private static String sanitizeLineBreaks(String originalText) {
|
||||
return StringUtil.replace(originalText, "\n", " ");
|
||||
}
|
||||
}
|
||||
+16
-222
@@ -16,63 +16,35 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.testFramework;
|
||||
|
||||
import com.intellij.ide.util.AppPropertiesComponentImpl;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.lang.*;
|
||||
import com.intellij.lang.impl.PsiBuilderFactoryImpl;
|
||||
import com.intellij.mock.*;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.lang.ParserDefinition;
|
||||
import com.intellij.mock.MockProject;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.FileTypeRegistry;
|
||||
import com.intellij.openapi.options.SchemeManagerFactory;
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.impl.CoreProgressManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.pom.PomModel;
|
||||
import com.intellij.pom.core.impl.PomModelImpl;
|
||||
import com.intellij.pom.tree.TreeAspect;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.*;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.testFramework.MockSchemeManagerFactory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
import com.intellij.util.CachedValuesManagerImpl;
|
||||
import com.intellij.util.Function;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType;
|
||||
import org.picocontainer.ComponentAdapter;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public abstract class KtParsingTestCase extends KtPlatformLiteFixture {
|
||||
public static final Key<Document> HARD_REF_TO_DOCUMENT_KEY = Key.create("HARD_REF_TO_DOCUMENT_KEY");
|
||||
protected String myFilePrefix = "";
|
||||
protected String myFileExt;
|
||||
protected final String myFullDataPath;
|
||||
protected PsiFile myFile;
|
||||
private MockPsiManager myPsiManager;
|
||||
private PsiFileFactoryImpl myFileFactory;
|
||||
protected Language myLanguage;
|
||||
private final ParserDefinition[] myDefinitions;
|
||||
private final boolean myLowercaseFirstLetter;
|
||||
|
||||
private KotlinCoreEnvironment myEnvironment;
|
||||
|
||||
protected KtParsingTestCase(@NonNls @NotNull String dataPath, @NotNull String fileExt, @NotNull ParserDefinition... definitions) {
|
||||
this(dataPath, fileExt, false, definitions);
|
||||
}
|
||||
@@ -87,88 +59,9 @@ public abstract class KtParsingTestCase extends KtPlatformLiteFixture {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
initApplication();
|
||||
ComponentAdapter component = getApplication().getPicoContainer().getComponentAdapter(ProgressManager.class.getName());
|
||||
|
||||
myProject = new MockProjectEx(getTestRootDisposable());
|
||||
myPsiManager = new MockPsiManager(myProject);
|
||||
myFileFactory = new PsiFileFactoryImpl(myPsiManager);
|
||||
MutablePicoContainer appContainer = getApplication().getPicoContainer();
|
||||
final MockEditorFactory editorFactory = new MockEditorFactory();
|
||||
MockFileTypeManager mockFileTypeManager = new MockFileTypeManager(KotlinFileType.INSTANCE);
|
||||
MockFileDocumentManagerImpl mockFileDocumentManager = new MockFileDocumentManagerImpl(new Function<CharSequence, Document>() {
|
||||
@Override
|
||||
public Document fun(CharSequence charSequence) {
|
||||
return editorFactory.createDocument(charSequence);
|
||||
}
|
||||
}, HARD_REF_TO_DOCUMENT_KEY);
|
||||
|
||||
registerApplicationService(PropertiesComponent.class, new AppPropertiesComponentImpl());
|
||||
registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
|
||||
registerApplicationService(DefaultASTFactory.class, new DefaultASTFactoryImpl());
|
||||
registerApplicationService(SchemeManagerFactory.class, new MockSchemeManagerFactory());
|
||||
registerApplicationService(FileTypeManager.class, mockFileTypeManager);
|
||||
registerApplicationService(FileDocumentManager.class, mockFileDocumentManager);
|
||||
|
||||
registerApplicationService(ProgressManager.class, new CoreProgressManager());
|
||||
|
||||
registerComponentInstance(appContainer, FileTypeRegistry.class, mockFileTypeManager);
|
||||
registerComponentInstance(appContainer, FileTypeManager.class, mockFileTypeManager);
|
||||
registerComponentInstance(appContainer, EditorFactory.class, editorFactory);
|
||||
registerComponentInstance(appContainer, FileDocumentManager.class, mockFileDocumentManager);
|
||||
registerComponentInstance(appContainer, PsiDocumentManager.class, new MockPsiDocumentManager());
|
||||
|
||||
myProject.registerService(PsiManager.class, myPsiManager);
|
||||
myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myProject)));
|
||||
myProject.registerService(TreeAspect.class, new TreeAspect());
|
||||
|
||||
for (ParserDefinition definition : myDefinitions) {
|
||||
addExplicitExtension(LanguageParserDefinitions.INSTANCE, definition.getFileNodeType().getLanguage(), definition);
|
||||
}
|
||||
if (myDefinitions.length > 0) {
|
||||
configureFromParserDefinition(myDefinitions[0], myFileExt);
|
||||
}
|
||||
|
||||
// That's for reparse routines
|
||||
final PomModelImpl pomModel = new PomModelImpl(myProject);
|
||||
myProject.registerService(PomModel.class, pomModel);
|
||||
}
|
||||
|
||||
public void configureFromParserDefinition(ParserDefinition definition, String extension) {
|
||||
myLanguage = definition.getFileNodeType().getLanguage();
|
||||
myFileExt = extension;
|
||||
addExplicitExtension(LanguageParserDefinitions.INSTANCE, this.myLanguage, definition);
|
||||
registerComponentInstance(
|
||||
getApplication().getPicoContainer(), FileTypeManager.class,
|
||||
new MockFileTypeManager(new MockLanguageFileType(myLanguage, myFileExt)));
|
||||
}
|
||||
|
||||
protected <T> void addExplicitExtension(final LanguageExtension<T> instance, final Language language, final T object) {
|
||||
instance.addExplicitExtension(language, object);
|
||||
Disposer.register(myProject, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
instance.removeExplicitExtension(language, object);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected <T> void registerApplicationService(final Class<T> aClass, T object) {
|
||||
getApplication().registerService(aClass, object);
|
||||
Disposer.register(myProject, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
getApplication().getPicoContainer().unregisterComponent(aClass.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public MockProjectEx getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
public MockPsiManager getPsiManager() {
|
||||
return myPsiManager;
|
||||
myEnvironment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), CompilerConfiguration.EMPTY,
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
myProject = (MockProject) myEnvironment.getProject();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,7 +69,7 @@ public abstract class KtParsingTestCase extends KtPlatformLiteFixture {
|
||||
super.tearDown();
|
||||
myFile = null;
|
||||
myProject = null;
|
||||
myPsiManager = null;
|
||||
myEnvironment = null;
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
@@ -200,92 +93,12 @@ public abstract class KtParsingTestCase extends KtPlatformLiteFixture {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doTest(boolean checkResult) {
|
||||
String name = getTestName();
|
||||
try {
|
||||
String text = loadFile(name + "." + myFileExt);
|
||||
myFile = createPsiFile(name, text);
|
||||
ensureParsed(myFile);
|
||||
assertEquals("light virtual file text mismatch", text, ((LightVirtualFile)myFile.getVirtualFile()).getContent().toString());
|
||||
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(myFile.getVirtualFile()));
|
||||
assertEquals("doc text mismatch", text, myFile.getViewProvider().getDocument().getText());
|
||||
assertEquals("psi text mismatch", text, myFile.getText());
|
||||
ensureCorrectReparse(myFile);
|
||||
if (checkResult){
|
||||
checkResult(name, myFile);
|
||||
}
|
||||
else{
|
||||
toParseTreeText(myFile, skipSpaces(), includeRanges());
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doTest(String suffix) throws IOException {
|
||||
String name = getTestName();
|
||||
String text = loadFile(name + "." + myFileExt);
|
||||
myFile = createPsiFile(name, text);
|
||||
ensureParsed(myFile);
|
||||
assertEquals(text, myFile.getText());
|
||||
checkResult(name + suffix, myFile);
|
||||
}
|
||||
|
||||
protected void doCodeTest(String code) throws IOException {
|
||||
String name = getTestName();
|
||||
myFile = createPsiFile("a", code);
|
||||
ensureParsed(myFile);
|
||||
assertEquals(code, myFile.getText());
|
||||
checkResult(myFilePrefix + name, myFile);
|
||||
}
|
||||
|
||||
protected PsiFile createPsiFile(String name, String text) {
|
||||
return createFile(name + "." + myFileExt, text);
|
||||
}
|
||||
|
||||
protected PsiFile createFile(@NonNls String name, String text) {
|
||||
LightVirtualFile virtualFile = new LightVirtualFile(name, myLanguage, text);
|
||||
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
||||
return createFile(virtualFile);
|
||||
}
|
||||
|
||||
protected PsiFile createFile(LightVirtualFile virtualFile) {
|
||||
return myFileFactory.trySetupPsiForFile(virtualFile, myLanguage, true, false);
|
||||
}
|
||||
|
||||
protected void checkResult(@NonNls @TestDataFile String targetDataName, final PsiFile file) throws IOException {
|
||||
doCheckResult(myFullDataPath, file, checkAllPsiRoots(), targetDataName, skipSpaces(), includeRanges());
|
||||
}
|
||||
|
||||
public static void doCheckResult(String testDataDir,
|
||||
PsiFile file,
|
||||
boolean checkAllPsiRoots,
|
||||
String targetDataName,
|
||||
boolean skipSpaces,
|
||||
boolean printRanges) throws IOException {
|
||||
FileViewProvider provider = file.getViewProvider();
|
||||
Set<Language> languages = provider.getLanguages();
|
||||
|
||||
if (!checkAllPsiRoots || languages.size() == 1) {
|
||||
doCheckResult(testDataDir, targetDataName + ".txt", toParseTreeText(file, skipSpaces, printRanges).trim());
|
||||
return;
|
||||
}
|
||||
|
||||
for (Language language : languages) {
|
||||
PsiFile root = provider.getPsi(language);
|
||||
String expectedName = targetDataName + "." + language.getID() + ".txt";
|
||||
doCheckResult(testDataDir, expectedName, toParseTreeText(root, skipSpaces, printRanges).trim());
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkResult(String actual) throws IOException {
|
||||
String name = getTestName();
|
||||
doCheckResult(myFullDataPath, myFilePrefix + name + ".txt", actual);
|
||||
}
|
||||
|
||||
protected void checkResult(@TestDataFile @NonNls String targetDataName, String actual) throws IOException {
|
||||
doCheckResult(myFullDataPath, targetDataName, actual);
|
||||
return KtTestUtil.createFile(name, text, myProject);
|
||||
}
|
||||
|
||||
public static void doCheckResult(String fullPath, String targetDataName, String actual) throws IOException {
|
||||
@@ -304,23 +117,4 @@ public abstract class KtParsingTestCase extends KtPlatformLiteFixture {
|
||||
public static String loadFileDefault(String dir, String name) throws IOException {
|
||||
return FileUtil.loadFile(new File(dir, name), CharsetToolkit.UTF8, true).trim();
|
||||
}
|
||||
|
||||
public static void ensureParsed(PsiFile file) {
|
||||
file.accept(new PsiElementVisitor() {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
element.acceptChildren(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void ensureCorrectReparse(@NotNull PsiFile file) {
|
||||
String psiToStringDefault = DebugUtil.psiToString(file, false, false);
|
||||
String fileText = file.getText();
|
||||
DiffLog diffLog = (new BlockSupportImpl()).reparseRange(
|
||||
file, file.getNode(), TextRange.allOf(fileText), fileText, new EmptyProgressIndicator(), fileText);
|
||||
diffLog.performActualPsiChange(file);
|
||||
|
||||
TestCase.assertEquals(psiToStringDefault, DebugUtil.psiToString(file, false, false));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-25
@@ -16,25 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.testFramework;
|
||||
|
||||
import com.intellij.core.CoreEncodingProjectManager;
|
||||
import com.intellij.mock.MockApplication;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
import com.intellij.mock.MockProject;
|
||||
|
||||
public abstract class KtPlatformLiteFixture extends KtUsefulTestCase {
|
||||
protected MockProjectEx myProject;
|
||||
|
||||
public static MockApplication getApplication() {
|
||||
return (MockApplication) ApplicationManager.getApplication();
|
||||
}
|
||||
|
||||
public void initApplication() {
|
||||
MockApplication instance = new MockApplication(getTestRootDisposable());
|
||||
ApplicationManager.setApplication(instance, FileTypeManager::getInstance, getTestRootDisposable());
|
||||
getApplication().registerService(EncodingManager.class, CoreEncodingProjectManager.class);
|
||||
}
|
||||
protected MockProject myProject;
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@@ -42,12 +27,4 @@ public abstract class KtPlatformLiteFixture extends KtUsefulTestCase {
|
||||
clearFields(this);
|
||||
myProject = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T registerComponentInstance(MutablePicoContainer container, Class<T> key, T implementation) {
|
||||
Object old = container.getComponentInstance(key);
|
||||
container.unregisterComponent(key);
|
||||
container.registerComponentInstance(key, implementation);
|
||||
return (T)old;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-83
@@ -5,38 +5,28 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.testFramework;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.concurrency.IdeaForkJoinWorkerThreadFactory;
|
||||
import com.intellij.diagnostic.PerformanceWatcher;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileVisitor;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.impl.DocumentCommitProcessor;
|
||||
import com.intellij.psi.impl.DocumentCommitThread;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.*;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.PeekableIterator;
|
||||
import com.intellij.util.containers.PeekableIteratorWrapper;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
import com.intellij.util.indexing.FileBasedIndexImpl;
|
||||
import com.intellij.util.lang.CompoundRuntimeException;
|
||||
import gnu.trove.Equality;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -63,7 +53,6 @@ import java.lang.reflect.Modifier;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@@ -79,9 +68,6 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
|
||||
private Application application;
|
||||
|
||||
static {
|
||||
IdeaForkJoinWorkerThreadFactory.setupPoisonFactory();
|
||||
}
|
||||
protected static final Logger LOG = Logger.getInstance(KtUsefulTestCase.class);
|
||||
|
||||
@NotNull
|
||||
@@ -93,14 +79,12 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
private String myTempDir;
|
||||
|
||||
private static final String DEFAULT_SETTINGS_EXTERNALIZED;
|
||||
private static final CodeInsightSettings defaultSettings = new CodeInsightSettings();
|
||||
static {
|
||||
// Radar #5755208: Command line Java applications need a way to launch without a Dock icon.
|
||||
System.setProperty("apple.awt.UIElement", "true");
|
||||
|
||||
try {
|
||||
Element oldS = new Element("temp");
|
||||
defaultSettings.writeExternal(oldS);
|
||||
DEFAULT_SETTINGS_EXTERNALIZED = JDOMUtil.writeElement(oldS);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -176,7 +160,7 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
|
||||
boolean isStressTest = isStressTest();
|
||||
ApplicationInfoImpl.setInStressTest(isStressTest);
|
||||
|
||||
Registry.getInstance().markAsLoaded();
|
||||
// turn off Disposer debugging for performance tests
|
||||
Disposer.setDebugMode(!isStressTest);
|
||||
}
|
||||
@@ -287,39 +271,6 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
containerMap.clear();
|
||||
}
|
||||
|
||||
static void doCheckForSettingsDamage(@NotNull CodeStyleSettings oldCodeStyleSettings, @NotNull CodeStyleSettings currentCodeStyleSettings) {
|
||||
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
|
||||
// don't use method references here to make stack trace reading easier
|
||||
//noinspection Convert2MethodRef
|
||||
new RunAll()
|
||||
.append(() -> {
|
||||
try {
|
||||
checkCodeInsightSettingsEqual(defaultSettings, settings);
|
||||
}
|
||||
catch (AssertionError error) {
|
||||
CodeInsightSettings clean = new CodeInsightSettings();
|
||||
for (Field field : clean.getClass().getFields()) {
|
||||
try {
|
||||
ReflectionUtil.copyFieldValue(clean, settings, field);
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
.append(() -> {
|
||||
currentCodeStyleSettings.getIndentOptions(StdFileTypes.JAVA);
|
||||
try {
|
||||
checkCodeStyleSettingsEqual(oldCodeStyleSettings, currentCodeStyleSettings);
|
||||
}
|
||||
finally {
|
||||
currentCodeStyleSettings.clearCodeStyleSettings();
|
||||
}
|
||||
})
|
||||
.run();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Disposable getTestRootDisposable() {
|
||||
return myTestRootDisposable;
|
||||
@@ -725,10 +676,6 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
Assert.fail(value + " should be equal to one of " + Arrays.toString(values));
|
||||
}
|
||||
|
||||
public static void printThreadDump() {
|
||||
PerformanceWatcher.dumpThreadsToConsole("Thread dump:");
|
||||
}
|
||||
|
||||
public static void assertEmpty(@NotNull Object[] array) {
|
||||
assertOrderedEquals(array);
|
||||
}
|
||||
@@ -885,27 +832,6 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkCodeStyleSettingsEqual(@NotNull CodeStyleSettings expected, @NotNull CodeStyleSettings settings) {
|
||||
if (!expected.equals(settings)) {
|
||||
Element oldS = new Element("temp");
|
||||
expected.writeExternal(oldS);
|
||||
Element newS = new Element("temp");
|
||||
settings.writeExternal(newS);
|
||||
|
||||
String newString = JDOMUtil.writeElement(newS);
|
||||
String oldString = JDOMUtil.writeElement(oldS);
|
||||
Assert.assertEquals("Code style settings damaged", oldString, newString);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkCodeInsightSettingsEqual(@NotNull CodeInsightSettings oldSettings, @NotNull CodeInsightSettings settings) {
|
||||
if (!oldSettings.equals(settings)) {
|
||||
Element newS = new Element("temp");
|
||||
settings.writeExternal(newS);
|
||||
Assert.assertEquals("Code insight settings damaged", DEFAULT_SETTINGS_EXTERNALIZED, JDOMUtil.writeElement(newS));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true for a test which performs A LOT of computations.
|
||||
* Such test should typically avoid performing expensive checks, e.g. data structure consistency complex validations.
|
||||
@@ -925,13 +851,6 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
return name != null && (name.contains("Stress") || name.contains("Slow"));
|
||||
}
|
||||
|
||||
public static void doPostponedFormatting(@NotNull Project project) {
|
||||
DocumentUtil.writeInRunUndoTransparentAction(() -> {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
PostprocessReformattingAspect.getInstance(project).doPostponedFormatting();
|
||||
});
|
||||
}
|
||||
|
||||
protected void assertNoThrowable(@NotNull Runnable closure) {
|
||||
String throwableName = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user