JetDiagnosticsTest: no hardcoded paths and .jet extension
This commit is contained in:
@@ -31,10 +31,12 @@ import com.intellij.testFramework.TestDataFile;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -103,18 +105,25 @@ public abstract class JetLiteFixture extends UsefulTestCase {
|
||||
|
||||
protected static String doLoadFile(String myFullDataPath, String name) throws IOException {
|
||||
String fullName = myFullDataPath + File.separatorChar + name;
|
||||
String text = FileUtil.loadFile(new File(fullName), CharsetToolkit.UTF8).trim();
|
||||
text = StringUtil.convertLineSeparators(text);
|
||||
return text;
|
||||
return doLoadFile(new File(fullName));
|
||||
}
|
||||
|
||||
protected JetFile createPsiFile(String name, String text) {
|
||||
return (JetFile) createFile(name + ".jet", text);
|
||||
protected static String doLoadFile(@NotNull File file) throws IOException {
|
||||
String text = FileUtil.loadFile(file, CharsetToolkit.UTF8).trim();
|
||||
return StringUtil.convertLineSeparators(text);
|
||||
}
|
||||
|
||||
protected JetFile createPsiFile(@Nullable String testName, @Nullable String fileName, String text) {
|
||||
if (fileName == null) {
|
||||
Assert.assertNotNull(testName);
|
||||
fileName = testName + ".jet";
|
||||
}
|
||||
return (JetFile) createFile(fileName, text);
|
||||
}
|
||||
|
||||
protected JetFile loadPsiFile(String name) {
|
||||
try {
|
||||
return createPsiFile(name, loadFile(name));
|
||||
return createPsiFile(name, null, loadFile(name));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -141,11 +150,11 @@ public abstract class JetLiteFixture extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void createAndCheckPsiFile(String name, String text) {
|
||||
myFile = createCheckAndReturnPsiFile(name, text);
|
||||
myFile = createCheckAndReturnPsiFile(name, null, text);
|
||||
}
|
||||
|
||||
protected JetFile createCheckAndReturnPsiFile(String name, String text) {
|
||||
JetFile myFile = createPsiFile(name, text);
|
||||
protected JetFile createCheckAndReturnPsiFile(String testName, String fileName, String text) {
|
||||
JetFile myFile = createPsiFile(testName, fileName, 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()));
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
@@ -46,11 +45,13 @@ import java.util.List;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetDiagnosticsTest extends JetLiteFixture {
|
||||
private String name;
|
||||
@NotNull
|
||||
private final String name;
|
||||
private final File file;
|
||||
|
||||
public JetDiagnosticsTest(@NonNls String dataPath, String name) {
|
||||
super(dataPath);
|
||||
this.name = name;
|
||||
public JetDiagnosticsTest(@NotNull File file) {
|
||||
this.name = file.getName().replaceFirst("\\.[^.]+$", "");
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +84,7 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
||||
expectedText = textWithMarkers;
|
||||
clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
||||
this.javaFile = null;
|
||||
this.jetFile = createCheckAndReturnPsiFile(fileName, clearText);
|
||||
this.jetFile = createCheckAndReturnPsiFile(null, fileName, clearText);
|
||||
for (CheckerTestUtil.DiagnosedRange diagnosedRange : diagnosedRanges) {
|
||||
diagnosedRange.setFile(jetFile);
|
||||
}
|
||||
@@ -144,11 +145,9 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
||||
public void runTest() throws Exception {
|
||||
javaFilesDir = new File(FileUtil.getTempDirectory(), "java-files");
|
||||
|
||||
String testFileName = name + ".jet";
|
||||
String expectedText = doLoadFile(file);
|
||||
|
||||
String expectedText = loadFile(testFileName);
|
||||
|
||||
List<TestFile> testFileFiles = JetTestUtils.createTestFiles(testFileName, expectedText, new JetTestUtils.TestFileFactory<TestFile>() {
|
||||
List<TestFile> testFileFiles = JetTestUtils.createTestFiles(file.getName(), expectedText, new JetTestUtils.TestFileFactory<TestFile>() {
|
||||
@Override
|
||||
public TestFile create(String fileName, String text) {
|
||||
if (fileName.endsWith(".java")) {
|
||||
@@ -224,7 +223,7 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name, @NotNull File file) {
|
||||
return new JetDiagnosticsTest(dataPath, name);
|
||||
return new JetDiagnosticsTest(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class DescriptorRendererTest extends JetLiteFixture {
|
||||
|
||||
private void doTest() throws IOException {
|
||||
String fileName = getTestName(false) + ".kt";
|
||||
JetFile psiFile = createPsiFile(fileName, loadFile(fileName));
|
||||
JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName));
|
||||
AnalyzeExhaust analyzeExhaust =
|
||||
AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(
|
||||
(JetFile) psiFile, JetControlFlowDataTraceFactory.EMPTY,
|
||||
|
||||
@@ -103,7 +103,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
return new ExpectedResolveData(nameToDescriptor, nameToDeclaration, myEnvironment) {
|
||||
@Override
|
||||
protected JetFile createJetFile(String fileName, String text) {
|
||||
return createCheckAndReturnPsiFile(fileName, text);
|
||||
return createCheckAndReturnPsiFile(fileName, null, text);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user