Minor, add path utility to codegen tests

This commit is contained in:
Alexander Udalov
2014-06-26 20:56:34 +04:00
parent aea230d677
commit 16ec4c3805
4 changed files with 16 additions and 10 deletions
@@ -20,10 +20,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.MockLibraryUtil;
import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.*;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import java.io.File;
@@ -45,7 +42,7 @@ public abstract class AbstractTopLevelMembersInvocationTest extends AbstractByte
@Override
public boolean process(File file) {
if (file.getName().endsWith(".kt")) {
sourceFiles.add(file.getPath().substring("compiler/testData/codegen/".length()));
sourceFiles.add(relativePath(file));
return true;
}
return true;
@@ -70,7 +67,8 @@ public abstract class AbstractTopLevelMembersInvocationTest extends AbstractByte
loadFiles(ArrayUtil.toStringArray(sourceFiles));
List<OccurrenceInfo> expected = readExpectedOccurrences("compiler/testData/codegen/" + sourceFiles.get(0));
List<OccurrenceInfo> expected =
readExpectedOccurrences(JetTestCaseBuilder.getTestDataPathBase() + "/codegen/" + sourceFiles.get(0));
countAndCompareActualOccurrences(expected);
}
}
@@ -108,6 +108,13 @@ public abstract class CodegenTestCase extends UsefulTestCase {
loadFile(getPrefix() + "/" + getTestName(true) + ".kt");
}
@NotNull
protected String relativePath(@NotNull File file) {
String stringToCut = "compiler/testData/codegen/";
assert file.getPath().startsWith(stringToCut) : "File path is not absolute: " + file;
return file.getPath().substring(stringToCut.length());
}
@NotNull
protected String getPrefix() {
throw new UnsupportedOperationException();
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiFile;
import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
@@ -122,7 +123,7 @@ public class CodegenTestUtil {
"-d", javaClassesTempDirectory.getPath()
);
File javaFile = new File("compiler/testData/codegen/" + filename);
File javaFile = new File(JetTestCaseBuilder.getTestDataPathBase() + "/codegen/" + filename);
JetTestUtils.compileJavaFiles(Collections.singleton(javaFile), options);
return javaClassesTempDirectory;
@@ -75,7 +75,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
@Override
public boolean process(File file) {
if (file.getName().endsWith(".kt")) {
files.add(file.getPath().substring("compiler/testData/codegen/".length()));
files.add(relativePath(file));
}
return true;
}
@@ -93,7 +93,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
}
private void blackBoxFileAgainstJavaByFullPath(@NotNull String ktFileFullPath) {
String ktFile = ktFileFullPath.substring("compiler/testData/codegen/".length());
String ktFile = relativePath(new File(ktFileFullPath));
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
@@ -111,7 +111,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
FileUtil.processFilesRecursively(dirFile, new Processor<File>() {
@Override
public boolean process(File file) {
String path = file.getPath().substring("compiler/testData/codegen/".length());
String path = relativePath(file);
if (path.endsWith(".kt")) {
ktFilePaths.add(path);
}