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
|
package org.jetbrains.jet.generators.tests
|
||||||
|
|
||||||
import org.jetbrains.jet.generators.tests.generator.TestGenerator
|
import org.jetbrains.jet.generators.tests.generator.TestGenerator
|
||||||
|
import org.jetbrains.jet.generators.tests.generator.TestGenerator.TargetBackend
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import org.jetbrains.jet.generators.tests.generator.SimpleTestClassModel
|
import org.jetbrains.jet.generators.tests.generator.SimpleTestClassModel
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -674,15 +675,16 @@ private class TestGroup(val testsRoot: String, val testDataRoot: String) {
|
|||||||
pattern: String = if (extension == null) """^([^\.]+)$""" else "^(.+)\\.$extension\$",
|
pattern: String = if (extension == null) """^([^\.]+)$""" else "^(.+)\\.$extension\$",
|
||||||
testMethod: String = "doTest",
|
testMethod: String = "doTest",
|
||||||
singleClass: Boolean = false,
|
singleClass: Boolean = false,
|
||||||
testClassName: String? = null
|
testClassName: String? = null,
|
||||||
|
targetBackend: TargetBackend = TargetBackend.ANY
|
||||||
) {
|
) {
|
||||||
val rootFile = File(testDataRoot + "/" + relativeRootPath)
|
val rootFile = File(testDataRoot + "/" + relativeRootPath)
|
||||||
val compiledPattern = Pattern.compile(pattern)
|
val compiledPattern = Pattern.compile(pattern)
|
||||||
val className = testClassName ?: TestGeneratorUtil.fileNameToJavaIdentifier(rootFile)
|
val className = testClassName ?: TestGeneratorUtil.fileNameToJavaIdentifier(rootFile)
|
||||||
testModels.add(if (singleClass)
|
testModels.add(if (singleClass)
|
||||||
SingleClassTestModel(rootFile, compiledPattern, testMethod, className)
|
SingleClassTestModel(rootFile, compiledPattern, testMethod, className, targetBackend)
|
||||||
else
|
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.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.generators.tests.generator.TestGenerator.TargetBackend;
|
||||||
|
|
||||||
public class SimpleTestClassModel implements TestClassModel {
|
public class SimpleTestClassModel implements TestClassModel {
|
||||||
private static final Comparator<TestEntityModel> BY_NAME = new Comparator<TestEntityModel>() {
|
private static final Comparator<TestEntityModel> BY_NAME = new Comparator<TestEntityModel>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -49,6 +51,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
|||||||
private final String doTestMethodName;
|
private final String doTestMethodName;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String testClassName;
|
private final String testClassName;
|
||||||
|
@NotNull
|
||||||
|
private final TargetBackend targetBackend;
|
||||||
@Nullable
|
@Nullable
|
||||||
private Collection<TestClassModel> innerTestClasses;
|
private Collection<TestClassModel> innerTestClasses;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -60,7 +64,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
|||||||
boolean excludeParentDirs,
|
boolean excludeParentDirs,
|
||||||
@NotNull Pattern filenamePattern,
|
@NotNull Pattern filenamePattern,
|
||||||
@NotNull String doTestMethodName,
|
@NotNull String doTestMethodName,
|
||||||
@NotNull String testClassName
|
@NotNull String testClassName,
|
||||||
|
@NotNull TargetBackend targetBackend
|
||||||
) {
|
) {
|
||||||
this.rootFile = rootFile;
|
this.rootFile = rootFile;
|
||||||
this.recursive = recursive;
|
this.recursive = recursive;
|
||||||
@@ -68,6 +73,7 @@ public class SimpleTestClassModel implements TestClassModel {
|
|||||||
this.filenamePattern = filenamePattern;
|
this.filenamePattern = filenamePattern;
|
||||||
this.doTestMethodName = doTestMethodName;
|
this.doTestMethodName = doTestMethodName;
|
||||||
this.testClassName = testClassName;
|
this.testClassName = testClassName;
|
||||||
|
this.targetBackend = targetBackend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -85,7 +91,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
|||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
if (dirHasFilesInside(file)) {
|
if (dirHasFilesInside(file)) {
|
||||||
String innerTestClassName = TestGeneratorUtil.fileNameToJavaIdentifier(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() {
|
public Collection<TestMethodModel> getTestMethods() {
|
||||||
if (testMethods == null) {
|
if (testMethods == null) {
|
||||||
if (!rootFile.isDirectory()) {
|
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 {
|
else {
|
||||||
List<TestMethodModel> result = Lists.newArrayList();
|
List<TestMethodModel> result = Lists.newArrayList();
|
||||||
@@ -139,7 +147,7 @@ public class SimpleTestClassModel implements TestClassModel {
|
|||||||
continue;
|
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.io.FileUtil;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.utils.Printer;
|
import org.jetbrains.jet.utils.Printer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.generators.tests.generator.TestGenerator.TargetBackend;
|
||||||
|
|
||||||
public class SimpleTestMethodModel implements TestMethodModel {
|
public class SimpleTestMethodModel implements TestMethodModel {
|
||||||
@NotNull
|
@NotNull
|
||||||
private final File rootDir;
|
private final File rootDir;
|
||||||
@@ -35,17 +40,21 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
|||||||
private final String doTestMethodName;
|
private final String doTestMethodName;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Pattern filenamePattern;
|
private final Pattern filenamePattern;
|
||||||
|
@NotNull
|
||||||
|
private final TargetBackend targetBackend;
|
||||||
|
|
||||||
public SimpleTestMethodModel(
|
public SimpleTestMethodModel(
|
||||||
@NotNull File rootDir,
|
@NotNull File rootDir,
|
||||||
@NotNull File file,
|
@NotNull File file,
|
||||||
@NotNull String doTestMethodName,
|
@NotNull String doTestMethodName,
|
||||||
@NotNull Pattern filenamePattern
|
@NotNull Pattern filenamePattern,
|
||||||
|
@NotNull TargetBackend targetBackend
|
||||||
) {
|
) {
|
||||||
this.rootDir = rootDir;
|
this.rootDir = rootDir;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.doTestMethodName = doTestMethodName;
|
this.doTestMethodName = doTestMethodName;
|
||||||
this.filenamePattern = filenamePattern;
|
this.filenamePattern = filenamePattern;
|
||||||
|
this.targetBackend = targetBackend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -60,6 +69,18 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
|||||||
return JetTestUtils.getFilePath(new File(FileUtil.getRelativePath(rootDir, file)));
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
Matcher matcher = filenamePattern.matcher(file.getName());
|
Matcher matcher = filenamePattern.matcher(file.getName());
|
||||||
@@ -77,6 +98,6 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
|||||||
String relativePath = FileUtil.getRelativePath(rootDir, file.getParentFile());
|
String relativePath = FileUtil.getRelativePath(rootDir, file.getParentFile());
|
||||||
unescapedName = relativePath + "-" + StringUtil.capitalize(extractedName);
|
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.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.generators.tests.generator.TestGenerator.TargetBackend;
|
||||||
|
|
||||||
public class SingleClassTestModel implements TestClassModel {
|
public class SingleClassTestModel implements TestClassModel {
|
||||||
@NotNull
|
@NotNull
|
||||||
private final File rootFile;
|
private final File rootFile;
|
||||||
@@ -42,6 +44,8 @@ public class SingleClassTestModel implements TestClassModel {
|
|||||||
private final String doTestMethodName;
|
private final String doTestMethodName;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String testClassName;
|
private final String testClassName;
|
||||||
|
@NotNull
|
||||||
|
private final TargetBackend targetBackend;
|
||||||
@Nullable
|
@Nullable
|
||||||
private Collection<TestMethodModel> testMethods;
|
private Collection<TestMethodModel> testMethods;
|
||||||
|
|
||||||
@@ -49,12 +53,14 @@ public class SingleClassTestModel implements TestClassModel {
|
|||||||
@NotNull File rootFile,
|
@NotNull File rootFile,
|
||||||
@NotNull Pattern filenamePattern,
|
@NotNull Pattern filenamePattern,
|
||||||
@NotNull String doTestMethodName,
|
@NotNull String doTestMethodName,
|
||||||
@NotNull String testClassName
|
@NotNull String testClassName,
|
||||||
|
@NotNull TargetBackend targetBackend
|
||||||
) {
|
) {
|
||||||
this.rootFile = rootFile;
|
this.rootFile = rootFile;
|
||||||
this.filenamePattern = filenamePattern;
|
this.filenamePattern = filenamePattern;
|
||||||
this.doTestMethodName = doTestMethodName;
|
this.doTestMethodName = doTestMethodName;
|
||||||
this.testClassName = testClassName;
|
this.testClassName = testClassName;
|
||||||
|
this.targetBackend = targetBackend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -97,7 +103,8 @@ public class SingleClassTestModel implements TestClassModel {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected Collection<TestMethodModel> getTestMethodsFromFile(File file) {
|
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
|
@Override
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ import java.util.Collections;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TestGenerator {
|
public class TestGenerator {
|
||||||
|
|
||||||
|
public static enum TargetBackend {
|
||||||
|
ANY,
|
||||||
|
ONLY_JVM,
|
||||||
|
ONLY_JS
|
||||||
|
}
|
||||||
|
|
||||||
public static final String NAVIGATION_METADATA = "navigationMetadata";
|
public static final String NAVIGATION_METADATA = "navigationMetadata";
|
||||||
|
|
||||||
private static final Set<String> GENERATED_FILES = ContainerUtil.newHashSet();
|
private static final Set<String> GENERATED_FILES = ContainerUtil.newHashSet();
|
||||||
|
|||||||
Reference in New Issue
Block a user