JetControlFlowTest -> JetLiteFixture

This commit is contained in:
Dmitry Jemerov
2011-10-27 17:59:45 +02:00
parent 12da406850
commit e52cfef3a9
2 changed files with 28 additions and 12 deletions
@@ -14,6 +14,7 @@ import com.intellij.testFramework.LightVirtualFile;
import com.intellij.testFramework.TestDataFile; import com.intellij.testFramework.TestDataFile;
import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.UsefulTestCase;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.plugin.JetLanguage; import org.jetbrains.jet.plugin.JetLanguage;
import java.io.File; import java.io.File;
@@ -71,8 +72,16 @@ public abstract class JetLiteFixture extends UsefulTestCase {
return text; return text;
} }
protected PsiFile createPsiFile(String name, String text) { protected JetFile createPsiFile(String name, String text) {
return createFile(name + ".jet", text); return (JetFile) createFile(name + ".jet", text);
}
protected JetFile loadPsiFile(String name) {
try {
return createPsiFile(name, loadFile(name));
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
protected PsiFile createFile(@NonNls String name, String text) { protected PsiFile createFile(@NonNls String name, String text) {
@@ -8,6 +8,7 @@ import com.intellij.openapi.util.text.StringUtil;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestCaseBase; import org.jetbrains.jet.JetTestCaseBase;
import org.jetbrains.jet.lang.cfg.LoopInfo; import org.jetbrains.jet.lang.cfg.LoopInfo;
import org.jetbrains.jet.lang.cfg.pseudocode.*; import org.jetbrains.jet.lang.cfg.pseudocode.*;
@@ -20,19 +21,25 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.*; import java.util.*;
public class JetControlFlowTest extends JetTestCaseBase { public class JetControlFlowTest extends JetLiteFixture {
static { static {
System.setProperty("idea.platform.prefix", "Idea"); System.setProperty("idea.platform.prefix", "Idea");
} }
private String myName;
public JetControlFlowTest(String dataPath, String name) { public JetControlFlowTest(String dataPath, String name) {
super(dataPath, name); super(dataPath);
myName = name;
} }
protected String getTestFilePath() {
return myFullDataPath + "/" + myName;
}
@Override @Override
protected void runTest() throws Throwable { protected void runTest() throws Throwable {
configureByFile(getTestFilePath()); JetFile file = loadPsiFile(myName + ".jet");
JetFile file = (JetFile) getFile();
final Map<JetElement, Pseudocode> data = new LinkedHashMap<JetElement, Pseudocode>(); final Map<JetElement, Pseudocode> data = new LinkedHashMap<JetElement, Pseudocode>();
final JetPseudocodeTrace pseudocodeTrace = new JetPseudocodeTrace() { final JetPseudocodeTrace pseudocodeTrace = new JetPseudocodeTrace() {
@@ -68,14 +75,14 @@ public class JetControlFlowTest extends JetTestCaseBase {
}); });
try { try {
processCFData(name, data); processCFData(myName, data);
} }
catch (IOException e) { catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
finally { finally {
if ("true".equals(System.getProperty("jet.control.flow.test.dump.graphs"))) { if ("true".equals(System.getProperty("jet.control.flow.test.dump.graphs"))) {
dumpDot(name, data.values()); dumpDot(myName, data.values());
} }
} }
} }
@@ -120,7 +127,7 @@ public class JetControlFlowTest extends JetTestCaseBase {
} }
} }
String expectedInstructionsFileName = getTestDataPath() + "/" + getTestFilePath().replace(".jet", ".instructions"); String expectedInstructionsFileName = getTestFilePath() + ".instructions";
File expectedInstructionsFile = new File(expectedInstructionsFileName); File expectedInstructionsFile = new File(expectedInstructionsFileName);
if (!expectedInstructionsFile.exists()) { if (!expectedInstructionsFile.exists()) {
FileUtil.writeToFile(expectedInstructionsFile, instructionDump.toString()); FileUtil.writeToFile(expectedInstructionsFile, instructionDump.toString());
@@ -352,7 +359,7 @@ public class JetControlFlowTest extends JetTestCaseBase {
} }
private void dumpDot(String name, Collection<Pseudocode> pseudocodes) throws FileNotFoundException { private void dumpDot(String name, Collection<Pseudocode> pseudocodes) throws FileNotFoundException {
String graphFileName = getTestDataPath() + "/" + getTestFilePath().replace(".jet", ".dot"); String graphFileName = getTestDataPath() + "/" + getTestFilePath() + ".dot";
File target = new File(graphFileName); File target = new File(graphFileName);
PrintStream out = new PrintStream(target); PrintStream out = new PrintStream(target);
@@ -387,7 +394,7 @@ public class JetControlFlowTest extends JetTestCaseBase {
public static TestSuite suite() { public static TestSuite suite() {
TestSuite suite = new TestSuite(); TestSuite suite = new TestSuite();
suite.addTest(JetTestCaseBase.suiteForDirectory(getTestDataPathBase(), "/cfg/", true, new JetTestCaseBase.NamedTestFactory() { suite.addTest(JetTestCaseBase.suiteForDirectory(JetTestCaseBase.getTestDataPathBase(), "/cfg/", true, new JetTestCaseBase.NamedTestFactory() {
@NotNull @NotNull
@Override @Override
public Test createTest(@NotNull String dataPath, @NotNull String name) { public Test createTest(@NotNull String dataPath, @NotNull String name) {