Refactor codegen tests: no special box() result
box() shall always return "OK"
This commit is contained in:
+3
-16
@@ -36,7 +36,6 @@ import org.jetbrains.jet.utils.Printer;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -132,7 +131,6 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
|
||||
Set<String> excludedFiles = SpecialFiles.getExcludedFiles();
|
||||
Set<String> filesCompiledWithoutStdLib = SpecialFiles.getFilesCompiledWithoutStdLib();
|
||||
Set<String> filesCompiledWithJUnit = SpecialFiles.getFilesCompiledWithJUnit();
|
||||
Map<String, String> filesWithSpecialResult = SpecialFiles.getFilesWithSpecialResult();
|
||||
for (File file : files) {
|
||||
if (excludedFiles.contains(file.getName())) {
|
||||
continue;
|
||||
@@ -158,14 +156,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
|
||||
factory = getFactoryFromText(file.getAbsolutePath(), text, environmentWithFullJdk);
|
||||
}
|
||||
|
||||
String specialResult = filesWithSpecialResult.get(file.getName());
|
||||
if (specialResult != null) {
|
||||
generateTestMethodWithExpectedResult(p, generatedTestName, StringUtil.escapeStringCharacters(file.getPath()),
|
||||
specialResult);
|
||||
}
|
||||
else {
|
||||
generateTestMethod(p, generatedTestName, StringUtil.escapeStringCharacters(file.getPath()));
|
||||
}
|
||||
generateTestMethod(p, generatedTestName, StringUtil.escapeStringCharacters(file.getPath()));
|
||||
File outputDir = new File(pathManager.getOutputForCompiledFiles());
|
||||
if (!outputDir.exists()) {
|
||||
outputDir.mkdirs();
|
||||
@@ -204,19 +195,15 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateTestMethodWithExpectedResult(Printer p, String testName, String namespace, String expectedResult) {
|
||||
private static void generateTestMethod(Printer p, String testName, String namespace) {
|
||||
p.println("public void test" + testName + "() throws Exception {");
|
||||
p.pushIndent();
|
||||
p.println("invokeBoxMethod(\"" + namespace + "\", \"" + expectedResult + "\");");
|
||||
p.println("invokeBoxMethod(\"" + namespace + "\", \"OK\");");
|
||||
p.popIndent();
|
||||
p.println("}");
|
||||
p.println();
|
||||
}
|
||||
|
||||
private static void generateTestMethod(Printer p, String testName, String namespace) {
|
||||
generateTestMethodWithExpectedResult(p, testName, namespace, "OK");
|
||||
}
|
||||
|
||||
private String generateTestName(String fileName) {
|
||||
String result = FileUtil.getNameWithoutExtension(StringUtil.capitalize(fileName));
|
||||
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.jetbrains.jet.compiler.android;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -27,13 +25,11 @@ public class SpecialFiles {
|
||||
private static final Set<String> excludedFiles = Sets.newHashSet();
|
||||
private static final Set<String> filesCompiledWithoutStdLib = Sets.newHashSet();
|
||||
private static final Set<String> filesCompiledWithJUnit = Sets.newHashSet();
|
||||
private static final Map<String, String> filesWithSpecialResult = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
fillExcludedFiles();
|
||||
fillFilesCompiledWithoutStdLib();
|
||||
fillFilesCompiledWithJUnit();
|
||||
fillFilesWithSpecialResult();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,14 +45,6 @@ public class SpecialFiles {
|
||||
return filesCompiledWithoutStdLib;
|
||||
}
|
||||
|
||||
public static Map<String, String> getFilesWithSpecialResult() {
|
||||
return filesWithSpecialResult;
|
||||
}
|
||||
|
||||
private static void fillFilesWithSpecialResult() {
|
||||
filesWithSpecialResult.put("kt2398.kt", "OKKO");
|
||||
}
|
||||
|
||||
private static void fillFilesCompiledWithJUnit() {
|
||||
filesCompiledWithJUnit.add("kt2334.kt");
|
||||
}
|
||||
|
||||
@@ -12,4 +12,7 @@ class C {
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = C().Obj.o + C().Obj.InnerObj.k() + C().Obj.D().ko
|
||||
fun box(): String {
|
||||
val res = C().Obj.o + C().Obj.InnerObj.k() + C().Obj.D().ko
|
||||
return if (res == "OKKO") "OK" else "Fail: $res"
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.Progress;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
@@ -40,11 +41,13 @@ import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
import org.jetbrains.jet.codegen.state.Progress;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
@@ -152,16 +155,12 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void blackBoxFile(String filename) {
|
||||
blackBoxFile(filename, "OK");
|
||||
blackBoxFile(filename, false);
|
||||
}
|
||||
|
||||
protected void blackBoxFile(String filename, String expected) {
|
||||
blackBoxFile(filename, expected, false);
|
||||
}
|
||||
|
||||
protected void blackBoxFile(String filename, String expected, boolean classPathInTheSameClassLoader) {
|
||||
protected void blackBoxFile(String filename, boolean classPathInTheSameClassLoader) {
|
||||
loadFile(filename);
|
||||
blackBox(expected, classPathInTheSameClassLoader);
|
||||
blackBox(classPathInTheSameClassLoader);
|
||||
}
|
||||
|
||||
protected void blackBoxFileByFullPath(String filename) {
|
||||
@@ -174,9 +173,9 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
blackBox();
|
||||
}
|
||||
|
||||
protected void blackBoxMultiFile(String expected, boolean classPathInTheSameClassLoader, String... filenames) {
|
||||
protected void blackBoxMultiFile(boolean classPathInTheSameClassLoader, String... filenames) {
|
||||
loadFiles(filenames);
|
||||
blackBox(expected, classPathInTheSameClassLoader);
|
||||
blackBox(classPathInTheSameClassLoader);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -219,14 +218,10 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void blackBox() {
|
||||
blackBox("OK");
|
||||
blackBox(false);
|
||||
}
|
||||
|
||||
protected void blackBox(String expected) {
|
||||
blackBox(expected, false);
|
||||
}
|
||||
|
||||
protected void blackBox(String expected, boolean classPathInTheSameClassLoader) {
|
||||
protected void blackBox(boolean classPathInTheSameClassLoader) {
|
||||
GenerationState state = generateClassesInFileGetState();
|
||||
|
||||
GeneratedClassLoader loader = createClassLoader(state.getFactory(), classPathInTheSameClassLoader);
|
||||
@@ -269,7 +264,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
try {
|
||||
Method method = namespaceClass.getMethod("box");
|
||||
r = (String) method.invoke(null);
|
||||
assertEquals(expected, r);
|
||||
assertEquals("OK", r);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
Method method = namespaceClass.getMethod("main",String[].class);
|
||||
@@ -299,7 +294,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||
|
||||
blackBoxFile(ktFile, "OK", classPathInTheSameClassLoader);
|
||||
blackBoxFile(ktFile, classPathInTheSameClassLoader);
|
||||
}
|
||||
|
||||
protected File compileJava(@NotNull String filename) throws IOException {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
|
||||
setUpEnvironment(generateAssertions, false, javaClassesTempDirectory);
|
||||
|
||||
blackBoxMultiFile("OK", false, "notNullAssertions/AssertionChecker.kt", ktFile);
|
||||
blackBoxMultiFile(false, "notNullAssertions/AssertionChecker.kt", ktFile);
|
||||
}
|
||||
|
||||
public void testGenerateAssertions() throws Exception {
|
||||
|
||||
@@ -94,7 +94,7 @@ public class ObjectGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testKt2398() {
|
||||
blackBoxFile("regressions/kt2398.kt", "OKKO");
|
||||
blackBoxFile("regressions/kt2398.kt");
|
||||
}
|
||||
|
||||
public void testKt2675() {
|
||||
|
||||
Reference in New Issue
Block a user