From c1b9efa8bf826788e9883c280f7b14c19afc09cc Mon Sep 17 00:00:00 2001 From: pTalanov Date: Fri, 2 Mar 2012 13:00:42 +0400 Subject: [PATCH] Remove patch. Refactor tests. --- js/Web_demo_config_and_facade.patch | 242 ------------------ .../jetbrains/k2js/test/BasicClassTest.java | 35 --- ...xampleTestSuite.java => ExamplesTest.java} | 3 +- .../test/{ForTest.java => ForeachTest.java} | 2 +- .../org/jetbrains/k2js/test/FunctionTest.java | 2 +- .../jetbrains/k2js/test/JavaClassesTest.java | 2 +- .../jetbrains/k2js/test/KotlinLibTest.java | 56 +--- .../org/jetbrains/k2js/test/MiscTest.java | 5 +- .../misc}/cases/classWithoutNamespace.kt | 0 .../testFiles/expression/misc/cases/jquery.kt | 8 - 10 files changed, 23 insertions(+), 332 deletions(-) delete mode 100644 js/Web_demo_config_and_facade.patch delete mode 100644 js/js.tests/test/org/jetbrains/k2js/test/BasicClassTest.java rename js/js.tests/test/org/jetbrains/k2js/test/{ExampleTestSuite.java => ExamplesTest.java} (91%) rename js/js.tests/test/org/jetbrains/k2js/test/{ForTest.java => ForeachTest.java} (94%) rename js/js.translator/testFiles/{class => expression/misc}/cases/classWithoutNamespace.kt (100%) delete mode 100644 js/js.translator/testFiles/expression/misc/cases/jquery.kt diff --git a/js/Web_demo_config_and_facade.patch b/js/Web_demo_config_and_facade.patch deleted file mode 100644 index b2caae113f5..00000000000 --- a/js/Web_demo_config_and_facade.patch +++ /dev/null @@ -1,242 +0,0 @@ -Index: js/js.translator/src/org/jetbrains/k2js/facade/WebDemoTranslatorFacade.java -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== ---- js/js.translator/src/org/jetbrains/k2js/facade/WebDemoTranslatorFacade.java (revision ) -+++ js/js.translator/src/org/jetbrains/k2js/facade/WebDemoTranslatorFacade.java (revision ) -@@ -0,0 +1,89 @@ -+/* -+* Copyright 2000-2012 JetBrains s.r.o. -+* -+* Licensed under the Apache License, Version 2.0 (the "License"); -+* you may not use this file except in compliance with the License. -+* You may obtain a copy of the License at -+* -+* http://www.apache.org/licenses/LICENSE-2.0 -+* -+* Unless required by applicable law or agreed to in writing, software -+* distributed under the License is distributed on an "AS IS" BASIS, -+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+* See the License for the specific language governing permissions and -+* limitations under the License. -+*/ -+ -+package org.jetbrains.k2js.facade; -+ -+import com.intellij.openapi.project.Project; -+import org.jetbrains.annotations.NotNull; -+import org.jetbrains.annotations.Nullable; -+import org.jetbrains.jet.lang.psi.JetFile; -+import org.jetbrains.jet.lang.resolve.BindingContext; -+import org.jetbrains.k2js.analyze.AnalyzerFacade; -+import org.jetbrains.k2js.config.WebDemoConfig; -+import org.jetbrains.k2js.utils.JetFileUtils; -+ -+import java.util.Arrays; -+ -+/** -+ * @author Pavel Talanov -+ */ -+@SuppressWarnings("UnusedDeclaration") -+public final class WebDemoTranslatorFacade { -+ -+ @SuppressWarnings("FieldCanBeLocal") -+ private static String EXCEPTION = "exception="; -+ -+ private WebDemoTranslatorFacade() { -+ } -+ -+ @SuppressWarnings("UnusedDeclaration") -+ @Nullable -+ public static BindingContext analyzeProgramCode(@NotNull Project project, @NotNull String programText) { -+ try { -+ JetFile file = JetFileUtils.createPsiFile("test", programText, project); -+ return AnalyzerFacade.analyzeFiles(Arrays.asList(file), new WebDemoConfig(project)); -+ } catch (Throwable e) { -+ reportException(e); -+ return null; -+ } -+ } -+ -+ -+ @SuppressWarnings("UnusedDeclaration") -+ @NotNull -+ public static String translateStringWithCallToMain(@NotNull Project project, -+ @NotNull String programText, @NotNull String argumentsString) { -+ try { -+ return doTranslate(project, programText, argumentsString); -+ -+ } catch (AssertionError e) { -+ reportException(e); -+ return EXCEPTION + "Translation error."; -+ } catch (UnsupportedOperationException e) { -+ reportException(e); -+ return EXCEPTION + "Unsupported feature."; -+ } catch (Throwable e) { -+ reportException(e); -+ return EXCEPTION + "Unexpected exception."; -+ } -+ } -+ -+ @NotNull -+ private static String doTranslate(@NotNull Project project, @NotNull String programText, -+ @NotNull String argumentsString) { -+ K2JSTranslator translator = new K2JSTranslator(new WebDemoConfig(project)); -+ JetFile file = JetFileUtils.createPsiFile("test", programText, project); -+ String programCode = translator.generateProgramCode(file) + "\n"; -+ String flushOutput = "Kotlin.System.flush();\n"; -+ String callToMain = K2JSTranslator.generateCallToMain(file, argumentsString); -+ String programOutput = "Kotlin.System.output();\n"; -+ return programCode + flushOutput + callToMain + programOutput; -+ } -+ -+ private static void reportException(@NotNull Throwable e) { -+ //TODO: -+ } -+} -Index: js/js.libraries/src/org/jetbrains/k2js/config/Loader.java -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== ---- js/js.libraries/src/org/jetbrains/k2js/config/Loader.java (revision ) -+++ js/js.libraries/src/org/jetbrains/k2js/config/Loader.java (revision ) -@@ -0,0 +1,25 @@ -+/* -+ * Copyright 2000-2012 JetBrains s.r.o. -+ * -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+package org.jetbrains.k2js.config; -+ -+/** -+ * @author Pavel Talanov -+ */ -+//TODO: delegate loading to this class -+//NOTE: this class is for loading resources -+public final class Loader { -+} -Index: js/js.translator/src/org/jetbrains/k2js/config/WebDemoConfig.java -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== ---- js/js.translator/src/org/jetbrains/k2js/config/WebDemoConfig.java (revision ) -+++ js/js.translator/src/org/jetbrains/k2js/config/WebDemoConfig.java (revision ) -@@ -0,0 +1,70 @@ -+/* -+ * Copyright 2000-2012 JetBrains s.r.o. -+ * -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+ -+package org.jetbrains.k2js.config; -+ -+import com.intellij.openapi.project.Project; -+import com.intellij.openapi.util.io.FileUtil; -+import org.jetbrains.annotations.NotNull; -+import org.jetbrains.annotations.Nullable; -+import org.jetbrains.jet.lang.psi.JetFile; -+import org.jetbrains.k2js.utils.JetFileUtils; -+ -+import java.io.IOException; -+import java.io.InputStream; -+import java.util.ArrayList; -+import java.util.List; -+ -+/** -+ * @author Pavel Talanov -+ */ -+//TODO: dup with TestConfig -+public final class WebDemoConfig extends Config { -+ -+ @Nullable -+ private /*var*/ List jsLibFiles = null; -+ -+ public WebDemoConfig(@NotNull Project project) { -+ super(project); -+ } -+ -+ @NotNull -+ private static List initLibFiles(@NotNull Project project) { -+ List libFiles = new ArrayList(); -+ for (String libFileName : LIB_FILE_NAMES) { -+ JetFile file = null; -+ //TODO: close stream? -+ @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") -+ InputStream stream = Loader.class.getResourceAsStream(libFileName); -+ try { -+ String text = FileUtil.loadTextAndClose(stream); -+ file = JetFileUtils.createPsiFile(libFileName, text, project); -+ } catch (IOException e) { -+ e.printStackTrace(); -+ } -+ libFiles.add(file); -+ } -+ return libFiles; -+ } -+ -+ @NotNull -+ public List getLibFiles() { -+ if (jsLibFiles == null) { -+ jsLibFiles = initLibFiles(getProject()); -+ } -+ return jsLibFiles; -+ } -+} -Index: .idea/modules.xml -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP -<+>\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n -=================================================================== ---- .idea/modules.xml (date 1330610502000) -+++ .idea/modules.xml (revision ) -@@ -17,6 +17,7 @@ - - - -+ - - - -Index: js/js.translator/js.translator.iml -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP -<+>\n\n \n \n \n \n \n \n \n \n \n \n \n\n\n -=================================================================== ---- js/js.translator/js.translator.iml (date 1330610502000) -+++ js/js.translator/js.translator.iml (revision ) -@@ -10,6 +10,7 @@ - - - -+ - - - diff --git a/js/js.tests/test/org/jetbrains/k2js/test/BasicClassTest.java b/js/js.tests/test/org/jetbrains/k2js/test/BasicClassTest.java deleted file mode 100644 index 29df4e4922c..00000000000 --- a/js/js.tests/test/org/jetbrains/k2js/test/BasicClassTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.k2js.test; - -/** - * @author Pavel Talanov - */ -//TODO: remove class -public class BasicClassTest extends TranslationTest { - - final private static String MAIN = "class/"; - - @Override - protected String mainDirectory() { - return MAIN; - } - - public void testClassWithoutNamespace() throws Exception { - testFunctionOutput("classWithoutNamespace.kt", "Anonymous", "box", true); - } -} diff --git a/js/js.tests/test/org/jetbrains/k2js/test/ExampleTestSuite.java b/js/js.tests/test/org/jetbrains/k2js/test/ExamplesTest.java similarity index 91% rename from js/js.tests/test/org/jetbrains/k2js/test/ExampleTestSuite.java rename to js/js.tests/test/org/jetbrains/k2js/test/ExamplesTest.java index 329f749e1da..b2aea775f6c 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/ExampleTestSuite.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/ExamplesTest.java @@ -20,7 +20,8 @@ import com.intellij.testFramework.UsefulTestCase; import junit.framework.Test; import org.jetbrains.annotations.NotNull; -public final class ExampleTestSuite extends UsefulTestCase { +@SuppressWarnings("JUnitTestCaseWithNoTests") +public final class ExamplesTest extends UsefulTestCase { public static Test suite() { return Suite.suiteForDirectory("examples/", new Suite.SingleFileTester() { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/ForTest.java b/js/js.tests/test/org/jetbrains/k2js/test/ForeachTest.java similarity index 94% rename from js/js.tests/test/org/jetbrains/k2js/test/ForTest.java rename to js/js.tests/test/org/jetbrains/k2js/test/ForeachTest.java index 4ea77af1c5d..88d80b89b78 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/ForTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/ForeachTest.java @@ -19,7 +19,7 @@ package org.jetbrains.k2js.test; /** * @author Pavel Talanov */ -public final class ForTest extends AbstractExpressionTest { +public final class ForeachTest extends AbstractExpressionTest { final private static String MAIN = "for/"; diff --git a/js/js.tests/test/org/jetbrains/k2js/test/FunctionTest.java b/js/js.tests/test/org/jetbrains/k2js/test/FunctionTest.java index f819c841a4d..abd2968eebb 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/FunctionTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/FunctionTest.java @@ -95,7 +95,7 @@ public class FunctionTest extends AbstractExpressionTest { } - public void testkt921() throws Exception { + public void testKT921() throws Exception { try { checkOutput("KT-921.kt", ""); } catch (Throwable e) { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/JavaClassesTest.java b/js/js.tests/test/org/jetbrains/k2js/test/JavaClassesTest.java index 7f66ee62d5c..e5e844d7ed5 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/JavaClassesTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/JavaClassesTest.java @@ -22,7 +22,7 @@ package org.jetbrains.k2js.test; @SuppressWarnings("FieldCanBeLocal") public abstract class JavaClassesTest extends TranslationTest { - private final String SUITE = "java/"; + private static final String SUITE = "java/"; @Override protected String suiteDirectoryName() { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/KotlinLibTest.java b/js/js.tests/test/org/jetbrains/k2js/test/KotlinLibTest.java index 2fb1afd4e19..095285a777c 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/KotlinLibTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/KotlinLibTest.java @@ -16,12 +16,11 @@ package org.jetbrains.k2js.test; +import org.jetbrains.annotations.NotNull; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; /** * @author Pavel Talanov @@ -35,12 +34,6 @@ public final class KotlinLibTest extends TranslationTest { return MAIN; } - private void runPropertyTypeCheck(String objectName, Map> propertyToType) - throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath()), new RhinoPropertyTypesChecker(objectName, propertyToType)); - } - - public void testKotlinJsLibRunsWithRhino() throws Exception { runRhinoTest(Arrays.asList(kotlinLibraryPath()), new RhinoResultChecker() { @Override @@ -50,68 +43,47 @@ public final class KotlinLibTest extends TranslationTest { }); } - //TODO: refactor - public void testCreatedTraitIsJSObject() throws Exception { - final Map> propertyToType - = new HashMap>(); - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("trait.js")), - new RhinoPropertyTypesChecker("foo", propertyToType)); - } - - - public void testCreatedNamespaceIsJSObject() throws Exception { - final Map> propertyToType - = new HashMap>(); - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespace.js")), - new RhinoPropertyTypesChecker("foo", propertyToType)); - } - - // - // TODO:Refactor calls to function result checker with test public void testNamespaceHasDeclaredFunction() throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespace.js")), - new RhinoFunctionResultChecker("test", true)); + runJavascriptTest("namespace.js"); } public void testNamespaceHasDeclaredClasses() throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespaceWithClasses.js")), - new RhinoFunctionResultChecker("test", true)); + runJavascriptTest("namespaceWithClasses.js"); } public void testIsSameType() throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isSameType.js")), - new RhinoFunctionResultChecker("test", true)); + runJavascriptTest("isSameType.js"); } public void testIsAncestorType() throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isAncestorType.js")), - new RhinoFunctionResultChecker("test", true)); + runJavascriptTest("isAncestorType.js"); } public void testIsComplexTest() throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isComplexTest.js")), - new RhinoFunctionResultChecker("test", true)); + runJavascriptTest("isComplexTest.js"); } public void testCommaExpression() throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("commaExpression.js")), - new RhinoFunctionResultChecker("test", true)); + runJavascriptTest("commaExpression.js"); } - public void testArray() throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("array.js")), - new RhinoFunctionResultChecker("test", true)); + runJavascriptTest("array.js"); } public void testHashMap() throws Exception { - runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("hashMap.js")), + runJavascriptTest("hashMap.js"); + } + + + private void runJavascriptTest(@NotNull String filename) throws Exception { + runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases(filename)), new RhinoFunctionResultChecker("test", true)); } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/MiscTest.java b/js/js.tests/test/org/jetbrains/k2js/test/MiscTest.java index b34076ddce0..84fa84dc51f 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/MiscTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/MiscTest.java @@ -35,7 +35,6 @@ public final class MiscTest extends AbstractExpressionTest { } public void testIntRange() throws Exception { - // checkOutput("intRange.kt", " "); checkFooBoxIsTrue("intRange.kt"); } @@ -43,4 +42,8 @@ public final class MiscTest extends AbstractExpressionTest { public void testSafecallComputesExpressionOnlyOnce() throws Exception { checkFooBoxIsTrue("safecallComputesExpressionOnlyOnce.kt"); } + + public void testClassWithoutNamespace() throws Exception { + testFunctionOutput("classWithoutNamespace.kt", "Anonymous", "box", true); + } } diff --git a/js/js.translator/testFiles/class/cases/classWithoutNamespace.kt b/js/js.translator/testFiles/expression/misc/cases/classWithoutNamespace.kt similarity index 100% rename from js/js.translator/testFiles/class/cases/classWithoutNamespace.kt rename to js/js.translator/testFiles/expression/misc/cases/classWithoutNamespace.kt diff --git a/js/js.translator/testFiles/expression/misc/cases/jquery.kt b/js/js.translator/testFiles/expression/misc/cases/jquery.kt deleted file mode 100644 index 4b4c94c8273..00000000000 --- a/js/js.translator/testFiles/expression/misc/cases/jquery.kt +++ /dev/null @@ -1,8 +0,0 @@ -package foo - -import jquery.*; - -fun box() : String { - val aa = jq("a").attr("a"); - return "OK" -} \ No newline at end of file