From 9295ce70860aa01d130586a999f3a8514346f80a Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 28 Aug 2012 17:11:40 +0400 Subject: [PATCH] LoadCompiledKotlinCustomTest -> LoadKotlinCustomTest. The test itself is enhanced so it loads descriptors from source and from binaries. Test data changed according to latest frontend changes. --- ...isibility.txt => enumVisibilityBinary.txt} | 12 +-- .../enum/enumVisibilitySource.txt | 50 +++++++++++ .../{simpleEnum.txt => simpleEnumBinary.txt} | 4 +- .../enum/simpleEnumSource.txt | 18 ++++ .../LoadCompiledKotlinCustomTest.java | 58 ------------- .../jvm/compiler/LoadKotlinCustomTest.java | 86 +++++++++++++++++++ 6 files changed, 162 insertions(+), 66 deletions(-) rename compiler/testData/loadKotlinCustom/enum/{enumVisibility.txt => enumVisibilityBinary.txt} (68%) create mode 100644 compiler/testData/loadKotlinCustom/enum/enumVisibilitySource.txt rename compiler/testData/loadKotlinCustom/enum/{simpleEnum.txt => simpleEnumBinary.txt} (69%) create mode 100644 compiler/testData/loadKotlinCustom/enum/simpleEnumSource.txt delete mode 100644 compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinCustomTest.java create mode 100644 compiler/tests/org/jetbrains/jet/jvm/compiler/LoadKotlinCustomTest.java diff --git a/compiler/testData/loadKotlinCustom/enum/enumVisibility.txt b/compiler/testData/loadKotlinCustom/enum/enumVisibilityBinary.txt similarity index 68% rename from compiler/testData/loadKotlinCustom/enum/enumVisibility.txt rename to compiler/testData/loadKotlinCustom/enum/enumVisibilityBinary.txt index 289fee8d9e0..0191d7d4d95 100644 --- a/compiler/testData/loadKotlinCustom/enum/enumVisibility.txt +++ b/compiler/testData/loadKotlinCustom/enum/enumVisibilityBinary.txt @@ -1,33 +1,33 @@ namespace test internal final enum class test.In : jet.Enum { - public final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.In + protected final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.In public final override /*1*/ fun name(): jet.String public final override /*1*/ fun ordinal(): jet.Int internal final class object test.In. { - public final /*constructor*/ fun (): test.In. + private final /*constructor*/ fun (): test.In. public final val A: test.In public final fun valueOf(/*0*/ value: jet.String): test.In public final fun values(): jet.Array } } private final enum class test.Pr : jet.Enum { - public final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.Pr + protected final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.Pr public final override /*1*/ fun name(): jet.String public final override /*1*/ fun ordinal(): jet.Int private final class object test.Pr. { - public final /*constructor*/ fun (): test.Pr. + private final /*constructor*/ fun (): test.Pr. public final val A: test.Pr public final fun valueOf(/*0*/ value: jet.String): test.Pr public final fun values(): jet.Array } } public final enum class test.Pu : jet.Enum { - public final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.Pu + protected final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.Pu public final override /*1*/ fun name(): jet.String public final override /*1*/ fun ordinal(): jet.Int public final class object test.Pu. { - public final /*constructor*/ fun (): test.Pu. + private final /*constructor*/ fun (): test.Pu. public final val A: test.Pu public final fun valueOf(/*0*/ value: jet.String): test.Pu public final fun values(): jet.Array diff --git a/compiler/testData/loadKotlinCustom/enum/enumVisibilitySource.txt b/compiler/testData/loadKotlinCustom/enum/enumVisibilitySource.txt new file mode 100644 index 00000000000..1c6da249deb --- /dev/null +++ b/compiler/testData/loadKotlinCustom/enum/enumVisibilitySource.txt @@ -0,0 +1,50 @@ +namespace test + +internal final enum class test.In : jet.Enum { + protected final /*constructor*/ fun (): test.In + public final override /*1*/ fun name(): jet.String + public final override /*1*/ fun ordinal(): jet.Int + internal final class object test.In. { + private final /*constructor*/ fun (): test.In. + internal final val A: test.In..A + internal final enum entry test.In..A : test.In { + private final /*constructor*/ fun (): test.In..A + public final override /*1*/ fun name(): jet.String + public final override /*1*/ fun ordinal(): jet.Int + } + public final fun valueOf(/*0*/ value: jet.String): test.In + public final fun values(): jet.Array + } +} +private final enum class test.Pr : jet.Enum { + protected final /*constructor*/ fun (): test.Pr + public final override /*1*/ fun name(): jet.String + public final override /*1*/ fun ordinal(): jet.Int + private final class object test.Pr. { + private final /*constructor*/ fun (): test.Pr. + internal final val A: test.Pr..A + internal final enum entry test.Pr..A : test.Pr { + private final /*constructor*/ fun (): test.Pr..A + public final override /*1*/ fun name(): jet.String + public final override /*1*/ fun ordinal(): jet.Int + } + public final fun valueOf(/*0*/ value: jet.String): test.Pr + public final fun values(): jet.Array + } +} +public final enum class test.Pu : jet.Enum { + protected final /*constructor*/ fun (): test.Pu + public final override /*1*/ fun name(): jet.String + public final override /*1*/ fun ordinal(): jet.Int + public final class object test.Pu. { + private final /*constructor*/ fun (): test.Pu. + internal final val A: test.Pu..A + internal final enum entry test.Pu..A : test.Pu { + private final /*constructor*/ fun (): test.Pu..A + public final override /*1*/ fun name(): jet.String + public final override /*1*/ fun ordinal(): jet.Int + } + public final fun valueOf(/*0*/ value: jet.String): test.Pu + public final fun values(): jet.Array + } +} diff --git a/compiler/testData/loadKotlinCustom/enum/simpleEnum.txt b/compiler/testData/loadKotlinCustom/enum/simpleEnumBinary.txt similarity index 69% rename from compiler/testData/loadKotlinCustom/enum/simpleEnum.txt rename to compiler/testData/loadKotlinCustom/enum/simpleEnumBinary.txt index 86715d61faa..e17dc8ae625 100644 --- a/compiler/testData/loadKotlinCustom/enum/simpleEnum.txt +++ b/compiler/testData/loadKotlinCustom/enum/simpleEnumBinary.txt @@ -1,11 +1,11 @@ namespace test internal final enum class test.MyEnum : jet.Enum { - public final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.MyEnum + protected final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.MyEnum public final override /*1*/ fun name(): jet.String public final override /*1*/ fun ordinal(): jet.Int internal final class object test.MyEnum. { - public final /*constructor*/ fun (): test.MyEnum. + private final /*constructor*/ fun (): test.MyEnum. public final val ENTRY: test.MyEnum public final fun valueOf(/*0*/ value: jet.String): test.MyEnum public final fun values(): jet.Array diff --git a/compiler/testData/loadKotlinCustom/enum/simpleEnumSource.txt b/compiler/testData/loadKotlinCustom/enum/simpleEnumSource.txt new file mode 100644 index 00000000000..424bb8e5ad2 --- /dev/null +++ b/compiler/testData/loadKotlinCustom/enum/simpleEnumSource.txt @@ -0,0 +1,18 @@ +namespace test + +internal final enum class test.MyEnum : jet.Enum { + protected final /*constructor*/ fun (): test.MyEnum + public final override /*1*/ fun name(): jet.String + public final override /*1*/ fun ordinal(): jet.Int + internal final class object test.MyEnum. { + private final /*constructor*/ fun (): test.MyEnum. + internal final val ENTRY: test.MyEnum..ENTRY + internal final enum entry test.MyEnum..ENTRY : test.MyEnum { + private final /*constructor*/ fun (): test.MyEnum..ENTRY + public final override /*1*/ fun name(): jet.String + public final override /*1*/ fun ordinal(): jet.Int + } + public final fun valueOf(/*0*/ value: jet.String): test.MyEnum + public final fun values(): jet.Array + } +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinCustomTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinCustomTest.java deleted file mode 100644 index 059e5ded803..00000000000 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinCustomTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010-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.jet.jvm.compiler; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; -import org.jetbrains.jet.test.TestCaseWithTmpdir; - -import java.io.File; - -import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.compileKotlinAndLoadTestNamespaceDescriptorFromBinary; -import static org.jetbrains.jet.test.util.NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT; -import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaces; - -/** - * @author Pavel Talanov - */ -/* - This test should be implemented via LoadCompiledKotlinTest. - Atm it's not possible due to enums being loaded differently from binaries (in contrast to from sources). - */ -public final class LoadCompiledKotlinCustomTest extends TestCaseWithTmpdir { - @NotNull - private static final String PATH = "compiler/testData/loadKotlinCustom"; - - private void doTest(@NotNull String expectedFileName, @NotNull String kotlinFileName) throws Exception { - NamespaceDescriptor namespaceFromClass = - compileKotlinAndLoadTestNamespaceDescriptorFromBinary(new File(kotlinFileName), tmpdir, myTestRootDisposable); - - compareNamespaces(namespaceFromClass, namespaceFromClass, DONT_INCLUDE_METHODS_OF_OBJECT, new File(expectedFileName)); - } - - public void testSimpleEnum() throws Exception { - String dir = PATH + "/enum"; - doTest(dir + "/simpleEnum.txt", - dir + "/simpleEnum.kt"); - } - - public void testEnumVisibility() throws Exception { - String dir = PATH + "/enum"; - doTest(dir + "/enumVisibility.txt", - dir + "/enumVisibility.kt"); - } -} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadKotlinCustomTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadKotlinCustomTest.java new file mode 100644 index 00000000000..6d614e7da7d --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadKotlinCustomTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2010-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.jet.jvm.compiler; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; +import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.test.TestCaseWithTmpdir; +import org.jetbrains.jet.test.util.NamespaceComparator; + +import java.io.File; + +import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.*; +import static org.jetbrains.jet.test.util.NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT; +import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaces; + +/** + * @author Pavel Talanov + */ +/* + * This test should be implemented via LoadCompiledKotlinTest. + * Atm it's not possible due to enums being loaded differently from binaries (in contrast to from sources). + */ +public final class LoadKotlinCustomTest extends TestCaseWithTmpdir { + @NotNull + private static final String PATH = "compiler/testData/loadKotlinCustom"; + @NotNull + private static final String ENUM_DIR = PATH + "/enum"; + + private void loadDescriptorsFromCompiledAndCompareWithTxt(@NotNull File expectedFile, @NotNull File kotlinFile) + throws Exception { + NamespaceDescriptor namespaceFromClass = + compileKotlinAndLoadTestNamespaceDescriptorFromBinary(kotlinFile, tmpdir, myTestRootDisposable); + + compareNamespaces(namespaceFromClass, namespaceFromClass, DONT_INCLUDE_METHODS_OF_OBJECT, expectedFile); + } + + private void loadDescriptorsFromSourceAndCompareWithTxt(@NotNull File expectedFile, @NotNull File kotlinFile) + throws Exception { + AnalyzeExhaust exhaust = compileKotlinToDirAndGetAnalyzeExhaust(kotlinFile, tmpdir, getTestRootDisposable()); + NamespaceDescriptor namespaceFromSource = exhaust.getBindingContext().get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, + TEST_PACKAGE_FQNAME); + assert namespaceFromSource != null; + compareNamespaces(namespaceFromSource, namespaceFromSource, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, + expectedFile); + } + + private void doTest( + @NotNull String expectedSourceDescriptors, + @NotNull String expectedBinaryDescriptors, + @NotNull String kotlinFileName + ) throws Exception { + loadDescriptorsFromSourceAndCompareWithTxt(new File(expectedSourceDescriptors), new File(kotlinFileName)); + loadDescriptorsFromCompiledAndCompareWithTxt(new File(expectedBinaryDescriptors), new File(kotlinFileName)); + } + + private void doTest(@NotNull String dir) throws Exception { + String name = getTestName(true); + doTest(dir + "/" + name + "Source.txt", + dir + "/" + name + "Binary.txt", + dir + "/" + name + ".kt"); + } + + public void testSimpleEnum() throws Exception { + doTest(ENUM_DIR); + } + + public void testEnumVisibility() throws Exception { + doTest(PATH + "/enum"); + } +}