From 9e55fd219e70754ed0e8e74090db0cedffa97fea Mon Sep 17 00:00:00 2001 From: "Natalia.Ukhorskaya" Date: Thu, 13 Sep 2012 13:20:22 +0400 Subject: [PATCH] Android tests: add expected result for box() method --- .../AbstractCodegenTestCaseOnAndroid.java | 5 +-- .../CodegenTestsOnAndroidGenerator.java | 33 +++++++++++++------ .../jet/compiler/android/SpecialFiles.java | 19 ++++++++--- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/compiler/android-tests/android-module/src/org/jetbrains/jet/compiler/android/AbstractCodegenTestCaseOnAndroid.java b/compiler/android-tests/android-module/src/org/jetbrains/jet/compiler/android/AbstractCodegenTestCaseOnAndroid.java index 9d6fb547270..107a2666df4 100644 --- a/compiler/android-tests/android-module/src/org/jetbrains/jet/compiler/android/AbstractCodegenTestCaseOnAndroid.java +++ b/compiler/android-tests/android-module/src/org/jetbrains/jet/compiler/android/AbstractCodegenTestCaseOnAndroid.java @@ -18,6 +18,7 @@ package org.jetbrains.jet.compiler.android; import junit.framework.TestCase; +import java.lang.String; import java.lang.reflect.Method; /** @@ -26,13 +27,13 @@ import java.lang.reflect.Method; public class AbstractCodegenTestCaseOnAndroid extends TestCase { - protected void invokeBoxMethod(String filePath) throws Exception { + protected void invokeBoxMethod(String filePath, String expectedResult) throws Exception { try { Class clazz; clazz = Class.forName(filePath.replaceAll("\\\\|-|\\.|/", "_") + ".namespace"); Method method; method = clazz.getMethod("box"); - assertEquals("OK", method.invoke(null)); + assertEquals(expectedResult, method.invoke(null)); } catch (Throwable e) { throw new RuntimeException("File: " + filePath, e); diff --git a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/CodegenTestsOnAndroidGenerator.java b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/CodegenTestsOnAndroidGenerator.java index 4b533e4787d..0b71e2cfc97 100644 --- a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/CodegenTestsOnAndroidGenerator.java +++ b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/CodegenTestsOnAndroidGenerator.java @@ -37,6 +37,7 @@ 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; @@ -48,11 +49,11 @@ import java.util.regex.Pattern; public class CodegenTestsOnAndroidGenerator extends UsefulTestCase { private final PathManager pathManager; - private final String testClassPackage = "org.jetbrains.jet.compiler.android"; - private final String testClassName = "CodegenTestCaseOnAndroid"; - private final String baseTestClassPackage = "org.jetbrains.jet.compiler.android"; - private final String baseTestClassName = "AbstractCodegenTestCaseOnAndroid"; - private final String generatorName = "CodegenTestsOnAndroidGenerator"; + private static final String testClassPackage = "org.jetbrains.jet.compiler.android"; + private static final String testClassName = "CodegenTestCaseOnAndroid"; + private static final String baseTestClassPackage = "org.jetbrains.jet.compiler.android"; + private static final String baseTestClassName = "AbstractCodegenTestCaseOnAndroid"; + private static final String generatorName = "CodegenTestsOnAndroidGenerator"; private JetCoreEnvironment environmentWithMockJdk = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable, ConfigurationKind.JDK_AND_ANNOTATIONS); private JetCoreEnvironment environmentWithFullJdk = JetTestUtils.createEnvironmentWithFullJdk(myTestRootDisposable); @@ -135,6 +136,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase { Set excludedFiles = SpecialFiles.getExcludedFiles(); Set filesCompiledWithoutStdLib = SpecialFiles.getFilesCompiledWithoutStdLib(); Set filesCompiledWithJUnit = SpecialFiles.getFilesCompiledWithJUnit(); + Map filesWithSpecialResult = SpecialFiles.getFilesWithSpecialResult(); for (File file : files) { if (excludedFiles.contains(file.getName())) { continue; @@ -160,7 +162,14 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase { factory = getFactoryFromText(file.getAbsolutePath(), text, environmentWithFullJdk); } - generateTestMethod(p, generatedTestName, StringUtil.escapeStringCharacters(file.getPath())); + 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())); + } File outputDir = new File(pathManager.getOutputForCompiledFiles()); if (!outputDir.exists()) { outputDir.mkdirs(); @@ -173,7 +182,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase { } } - private ClassFileFactory getFactoryFromText(String filePath, String text, JetCoreEnvironment jetEnvironment) { + private static ClassFileFactory getFactoryFromText(String filePath, String text, JetCoreEnvironment jetEnvironment) { JetFile psiFile = JetPsiFactory.createFile(jetEnvironment.getProject(), text); ClassFileFactory factory; try { @@ -185,7 +194,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase { return factory; } - private boolean hasBoxMethod(String text) { + private static boolean hasBoxMethod(String text) { return text.contains("fun box()"); } @@ -199,15 +208,19 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase { } } - private void generateTestMethod(Printer p, String testName, String namespace) { + private static void generateTestMethodWithExpectedResult(Printer p, String testName, String namespace, String expectedResult) { p.println("public void test" + testName + "() throws Exception {"); p.pushIndent(); - p.println("invokeBoxMethod(\"" + namespace + "\");"); + p.println("invokeBoxMethod(\"" + namespace + "\", \"" + expectedResult + "\");"); 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)); diff --git a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java index 4e41fa498b6..4dfbbd1e203 100644 --- a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java +++ b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java @@ -16,12 +16,10 @@ package org.jetbrains.jet.compiler.android; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @author Natalia.Ukhorskaya @@ -31,13 +29,16 @@ public class SpecialFiles { private static final Set excludedFiles = Sets.newHashSet(); private static final Set filesCompiledWithoutStdLib = Sets.newHashSet(); private static final Set filesCompiledWithJUnit = Sets.newHashSet(); + private static final Map filesWithSpecialResult = Maps.newHashMap(); static { fillExcludedFiles(); fillFilesCompiledWithoutStdLib(); fillFilesCompiledWithJUnit(); + fillFilesWithSpecialResult(); } - + + public static Set getFilesCompiledWithJUnit() { return filesCompiledWithJUnit; } @@ -50,6 +51,14 @@ public class SpecialFiles { return filesCompiledWithoutStdLib; } + public static Map getFilesWithSpecialResult() { + return filesWithSpecialResult; + } + + private static void fillFilesWithSpecialResult() { + filesWithSpecialResult.put("kt2398.kt", "OKKO"); + } + private static void fillFilesCompiledWithJUnit() { filesCompiledWithJUnit.add("kt2334.kt"); }