JS backend: improve test generator, support for backend header in test files
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.generators.tests
|
||||
|
||||
import org.jetbrains.jet.generators.tests.generator.TestGenerator
|
||||
import org.jetbrains.jet.generators.tests.generator.TestGenerator.TargetBackend
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.generators.tests.generator.SimpleTestClassModel
|
||||
import java.io.File
|
||||
@@ -674,15 +675,16 @@ private class TestGroup(val testsRoot: String, val testDataRoot: String) {
|
||||
pattern: String = if (extension == null) """^([^\.]+)$""" else "^(.+)\\.$extension\$",
|
||||
testMethod: String = "doTest",
|
||||
singleClass: Boolean = false,
|
||||
testClassName: String? = null
|
||||
testClassName: String? = null,
|
||||
targetBackend: TargetBackend = TargetBackend.ANY
|
||||
) {
|
||||
val rootFile = File(testDataRoot + "/" + relativeRootPath)
|
||||
val compiledPattern = Pattern.compile(pattern)
|
||||
val className = testClassName ?: TestGeneratorUtil.fileNameToJavaIdentifier(rootFile)
|
||||
testModels.add(if (singleClass)
|
||||
SingleClassTestModel(rootFile, compiledPattern, testMethod, className)
|
||||
SingleClassTestModel(rootFile, compiledPattern, testMethod, className, targetBackend)
|
||||
else
|
||||
SimpleTestClassModel(rootFile, recursive, excludeParentDirs, compiledPattern, testMethod, className))
|
||||
SimpleTestClassModel(rootFile, recursive, excludeParentDirs, compiledPattern, testMethod, className, targetBackend))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-4
@@ -32,6 +32,8 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jetbrains.jet.generators.tests.generator.TestGenerator.TargetBackend;
|
||||
|
||||
public class SimpleTestClassModel implements TestClassModel {
|
||||
private static final Comparator<TestEntityModel> BY_NAME = new Comparator<TestEntityModel>() {
|
||||
@Override
|
||||
@@ -49,6 +51,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
private final String doTestMethodName;
|
||||
@NotNull
|
||||
private final String testClassName;
|
||||
@NotNull
|
||||
private final TargetBackend targetBackend;
|
||||
@Nullable
|
||||
private Collection<TestClassModel> innerTestClasses;
|
||||
@Nullable
|
||||
@@ -60,7 +64,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
boolean excludeParentDirs,
|
||||
@NotNull Pattern filenamePattern,
|
||||
@NotNull String doTestMethodName,
|
||||
@NotNull String testClassName
|
||||
@NotNull String testClassName,
|
||||
@NotNull TargetBackend targetBackend
|
||||
) {
|
||||
this.rootFile = rootFile;
|
||||
this.recursive = recursive;
|
||||
@@ -68,6 +73,7 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
this.filenamePattern = filenamePattern;
|
||||
this.doTestMethodName = doTestMethodName;
|
||||
this.testClassName = testClassName;
|
||||
this.targetBackend = targetBackend;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -85,7 +91,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
if (file.isDirectory()) {
|
||||
if (dirHasFilesInside(file)) {
|
||||
String innerTestClassName = TestGeneratorUtil.fileNameToJavaIdentifier(file);
|
||||
children.add(new SimpleTestClassModel(file, true, excludeParentDirs, filenamePattern, doTestMethodName, innerTestClassName));
|
||||
children.add(new SimpleTestClassModel(file, true, excludeParentDirs, filenamePattern, doTestMethodName, innerTestClassName,
|
||||
targetBackend));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +130,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
public Collection<TestMethodModel> getTestMethods() {
|
||||
if (testMethods == null) {
|
||||
if (!rootFile.isDirectory()) {
|
||||
testMethods = Collections.<TestMethodModel>singletonList(new SimpleTestMethodModel(rootFile, rootFile, doTestMethodName, filenamePattern));
|
||||
testMethods = Collections.<TestMethodModel>singletonList(new SimpleTestMethodModel(rootFile, rootFile, doTestMethodName, filenamePattern,
|
||||
targetBackend));
|
||||
}
|
||||
else {
|
||||
List<TestMethodModel> result = Lists.newArrayList();
|
||||
@@ -139,7 +147,7 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.add(new SimpleTestMethodModel(rootFile, file, doTestMethodName, filenamePattern));
|
||||
result.add(new SimpleTestMethodModel(rootFile, file, doTestMethodName, filenamePattern, targetBackend));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-2
@@ -19,13 +19,18 @@ package org.jetbrains.jet.generators.tests.generator;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.utils.Printer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jetbrains.jet.generators.tests.generator.TestGenerator.TargetBackend;
|
||||
|
||||
public class SimpleTestMethodModel implements TestMethodModel {
|
||||
@NotNull
|
||||
private final File rootDir;
|
||||
@@ -35,17 +40,21 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
||||
private final String doTestMethodName;
|
||||
@NotNull
|
||||
private final Pattern filenamePattern;
|
||||
@NotNull
|
||||
private final TargetBackend targetBackend;
|
||||
|
||||
public SimpleTestMethodModel(
|
||||
@NotNull File rootDir,
|
||||
@NotNull File file,
|
||||
@NotNull String doTestMethodName,
|
||||
@NotNull Pattern filenamePattern
|
||||
@NotNull Pattern filenamePattern,
|
||||
@NotNull TargetBackend targetBackend
|
||||
) {
|
||||
this.rootDir = rootDir;
|
||||
this.file = file;
|
||||
this.doTestMethodName = doTestMethodName;
|
||||
this.filenamePattern = filenamePattern;
|
||||
this.targetBackend = targetBackend;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,6 +69,18 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
||||
return JetTestUtils.getFilePath(new File(FileUtil.getRelativePath(rootDir, file)));
|
||||
}
|
||||
|
||||
private boolean isIgnored() {
|
||||
if (targetBackend == TargetBackend.ANY) return false;
|
||||
|
||||
try {
|
||||
String fileText = FileUtil.loadFile(file);
|
||||
List<String> backends = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "// TARGET_BACKEND: ");
|
||||
return backends.size() > 0 && !targetBackend.name().equals(backends.get(0));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
Matcher matcher = filenamePattern.matcher(file.getName());
|
||||
@@ -77,6 +98,6 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
||||
String relativePath = FileUtil.getRelativePath(rootDir, file.getParentFile());
|
||||
unescapedName = relativePath + "-" + StringUtil.capitalize(extractedName);
|
||||
}
|
||||
return "test" + StringUtil.capitalize(TestGeneratorUtil.escapeForJavaIdentifier(unescapedName));
|
||||
return (isIgnored() ? "ignored" : "test") + StringUtil.capitalize(TestGeneratorUtil.escapeForJavaIdentifier(unescapedName));
|
||||
}
|
||||
}
|
||||
|
||||
+9
-2
@@ -33,6 +33,8 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jetbrains.jet.generators.tests.generator.TestGenerator.TargetBackend;
|
||||
|
||||
public class SingleClassTestModel implements TestClassModel {
|
||||
@NotNull
|
||||
private final File rootFile;
|
||||
@@ -42,6 +44,8 @@ public class SingleClassTestModel implements TestClassModel {
|
||||
private final String doTestMethodName;
|
||||
@NotNull
|
||||
private final String testClassName;
|
||||
@NotNull
|
||||
private final TargetBackend targetBackend;
|
||||
@Nullable
|
||||
private Collection<TestMethodModel> testMethods;
|
||||
|
||||
@@ -49,12 +53,14 @@ public class SingleClassTestModel implements TestClassModel {
|
||||
@NotNull File rootFile,
|
||||
@NotNull Pattern filenamePattern,
|
||||
@NotNull String doTestMethodName,
|
||||
@NotNull String testClassName
|
||||
@NotNull String testClassName,
|
||||
@NotNull TargetBackend targetBackend
|
||||
) {
|
||||
this.rootFile = rootFile;
|
||||
this.filenamePattern = filenamePattern;
|
||||
this.doTestMethodName = doTestMethodName;
|
||||
this.testClassName = testClassName;
|
||||
this.targetBackend = targetBackend;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -97,7 +103,8 @@ public class SingleClassTestModel implements TestClassModel {
|
||||
|
||||
@NotNull
|
||||
protected Collection<TestMethodModel> getTestMethodsFromFile(File file) {
|
||||
return Collections.<TestMethodModel>singletonList(new SimpleTestMethodModel(rootFile, file, doTestMethodName, filenamePattern));
|
||||
return Collections.<TestMethodModel>singletonList(new SimpleTestMethodModel(rootFile, file, doTestMethodName, filenamePattern,
|
||||
targetBackend));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,6 +34,13 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestGenerator {
|
||||
|
||||
public static enum TargetBackend {
|
||||
ANY,
|
||||
ONLY_JVM,
|
||||
ONLY_JS
|
||||
}
|
||||
|
||||
public static final String NAVIGATION_METADATA = "navigationMetadata";
|
||||
|
||||
private static final Set<String> GENERATED_FILES = ContainerUtil.newHashSet();
|
||||
|
||||
Reference in New Issue
Block a user