From 3b02498ca8a1b3b82bc2ad4fba0685a7c4cdfbcd Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Thu, 15 Oct 2015 14:03:05 +0300 Subject: [PATCH] Tests for private members and accessors for them --- .../boxInline/private/accessorStability.1.kt | 5 +++ .../boxInline/private/accessorStability.2.kt | 19 +++++++++ .../private/accessorStabilityInClass.1.kt | 5 +++ .../private/accessorStabilityInClass.2.kt | 23 +++++++++++ .../privateInInlineInMultiFileFacade.1.kt | 5 +++ .../privateInInlineInMultiFileFacade.2.kt | 15 +++++++ .../boxInline/private/privateInline.1.kt | 4 ++ .../boxInline/private/privateInline.2.kt | 14 +++++++ .../noPrivateNoAccessorsInMultiFileFacade.kt | 20 ++++++++++ .../noPrivateNoAccessorsInMultiFileFacade2.kt | 25 ++++++++++++ .../topLevelPrivate/privateInInlineNested.kt | 19 +++++++++ .../topLevelPrivate/syntheticAccessor.kt | 11 ++++++ .../syntheticAccessorInMultiFile.kt | 13 +++++++ .../BlackBoxInlineCodegenTestGenerated.java | 33 ++++++++++++++++ ...lackBoxWithStdlibCodegenTestGenerated.java | 39 +++++++++++++++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 33 ++++++++++++++++ 16 files changed, 283 insertions(+) create mode 100644 compiler/testData/codegen/boxInline/private/accessorStability.1.kt create mode 100644 compiler/testData/codegen/boxInline/private/accessorStability.2.kt create mode 100644 compiler/testData/codegen/boxInline/private/accessorStabilityInClass.1.kt create mode 100644 compiler/testData/codegen/boxInline/private/accessorStabilityInClass.2.kt create mode 100644 compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.1.kt create mode 100644 compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.2.kt create mode 100644 compiler/testData/codegen/boxInline/private/privateInline.1.kt create mode 100644 compiler/testData/codegen/boxInline/private/privateInline.2.kt create mode 100644 compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade.kt create mode 100644 compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade2.kt create mode 100644 compiler/testData/codegen/boxWithStdlib/topLevelPrivate/privateInInlineNested.kt create mode 100644 compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessor.kt create mode 100644 compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessorInMultiFile.kt diff --git a/compiler/testData/codegen/boxInline/private/accessorStability.1.kt b/compiler/testData/codegen/boxInline/private/accessorStability.1.kt new file mode 100644 index 00000000000..c1b657518ed --- /dev/null +++ b/compiler/testData/codegen/boxInline/private/accessorStability.1.kt @@ -0,0 +1,5 @@ +import test.* + +fun box(): String { + return call() +} diff --git a/compiler/testData/codegen/boxInline/private/accessorStability.2.kt b/compiler/testData/codegen/boxInline/private/accessorStability.2.kt new file mode 100644 index 00000000000..22f97564ff3 --- /dev/null +++ b/compiler/testData/codegen/boxInline/private/accessorStability.2.kt @@ -0,0 +1,19 @@ +package test + +fun call() = inlineFun2 { stub()} + +internal inline fun inlineFun2(p: () -> Unit): String { + p() + + return inlineFun { + test() + } +} + +private fun stub() = "fail" + +private fun test() = "OK" + +inline internal fun inlineFun(p: () -> String): String { + return p() +} diff --git a/compiler/testData/codegen/boxInline/private/accessorStabilityInClass.1.kt b/compiler/testData/codegen/boxInline/private/accessorStabilityInClass.1.kt new file mode 100644 index 00000000000..a3ae3ba0db9 --- /dev/null +++ b/compiler/testData/codegen/boxInline/private/accessorStabilityInClass.1.kt @@ -0,0 +1,5 @@ +import test.* + +fun box(): String { + return A().call() +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/private/accessorStabilityInClass.2.kt b/compiler/testData/codegen/boxInline/private/accessorStabilityInClass.2.kt new file mode 100644 index 00000000000..5f5c3bb0ef2 --- /dev/null +++ b/compiler/testData/codegen/boxInline/private/accessorStabilityInClass.2.kt @@ -0,0 +1,23 @@ +package test + +class A { + fun call() = inlineFun2 { stub() } + + internal inline fun inlineFun2(p: () -> Unit): String { + p() + + return inlineFun { + test() + } + } + + private fun stub() = "fail" + + private fun test() = "OK" + + + inline internal fun inlineFun(p: () -> String): String { + return p() + } + +} diff --git a/compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.1.kt b/compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.1.kt new file mode 100644 index 00000000000..d2766156005 --- /dev/null +++ b/compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.1.kt @@ -0,0 +1,5 @@ +import test.* + +fun box(): String { + return A().call(); +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.2.kt b/compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.2.kt new file mode 100644 index 00000000000..554c97a26c2 --- /dev/null +++ b/compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.2.kt @@ -0,0 +1,15 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("TestKt") +package test + +private val prop = "O" + +private fun test() = "K" + +inline internal fun inlineFun(): String { + return prop + test() +} + +class A () { + fun call() = inlineFun() +} diff --git a/compiler/testData/codegen/boxInline/private/privateInline.1.kt b/compiler/testData/codegen/boxInline/private/privateInline.1.kt new file mode 100644 index 00000000000..d5e0bd1261b --- /dev/null +++ b/compiler/testData/codegen/boxInline/private/privateInline.1.kt @@ -0,0 +1,4 @@ +import test.* +fun box(): String { + return A().call(); +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/private/privateInline.2.kt b/compiler/testData/codegen/boxInline/private/privateInline.2.kt new file mode 100644 index 00000000000..68dba621454 --- /dev/null +++ b/compiler/testData/codegen/boxInline/private/privateInline.2.kt @@ -0,0 +1,14 @@ +package test + +private val prop = "O" + +private fun test() = "K" + +inline internal fun inlineFun(): String { + return prop + test() +} + +class A () { + fun call() = inlineFun() +} + diff --git a/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade.kt b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade.kt new file mode 100644 index 00000000000..4d54ca84811 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade.kt @@ -0,0 +1,20 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("TestKt") +package test + +import kotlin.test.assertEquals + +private var prop = "O" + +private fun test() = "K" + +fun box(): String { + + val clazz = Class.forName("test.TestKt") + assertEquals(1, clazz.declaredMethods.size(), "Facade should have only box and getProp methods") + assertEquals("box", clazz.declaredMethods.first().name, "Facade should have only box method") + + return { + prop + test() + }() +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade2.kt b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade2.kt new file mode 100644 index 00000000000..07cbaab0ea3 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade2.kt @@ -0,0 +1,25 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("TestKt") +package test + +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +public var prop = "fail" + private set + +private fun test() = "K" + +fun box(): String { + + val clazz = Class.forName("test.TestKt") + assertEquals(2, clazz.declaredMethods.size(), "Facade should have only box method") + val methods = clazz.declaredMethods.map { it.name } + assertTrue(methods.contains("box"), "Facade should have box method") + assertTrue(methods.contains("getProp"), "Facade should have box method") + + return { + prop = "O" + prop + test() + }() +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/privateInInlineNested.kt b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/privateInInlineNested.kt new file mode 100644 index 00000000000..2f43f6e7930 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/privateInInlineNested.kt @@ -0,0 +1,19 @@ +package test + +private val prop = "O" + +private fun test() = "K" + +inline internal fun call(p: () -> String): String = p() + +inline internal fun inlineFun(): String { + return call { + object { + fun run() = prop + test() + }.run() + } +} + +fun box(): String { + return inlineFun(); +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessor.kt b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessor.kt new file mode 100644 index 00000000000..68d402f57bc --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessor.kt @@ -0,0 +1,11 @@ +package test + +private val prop = "O" + +private fun test() = "K" + +fun box(): String { + return { + prop + test() + }() +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessorInMultiFile.kt b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessorInMultiFile.kt new file mode 100644 index 00000000000..ad983df3576 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessorInMultiFile.kt @@ -0,0 +1,13 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("TestKt") +package test + +private val prop = "O" + +private fun test() = "K" + +fun box(): String { + return { + prop + test() + }() +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index fa4f1cf6258..b74f141166a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -983,6 +983,39 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo } } + @TestMetadata("compiler/testData/codegen/boxInline/private") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Private extends AbstractBlackBoxInlineCodegenTest { + @TestMetadata("accessorStability.1.kt") + public void testAccessorStability() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/private/accessorStability.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + + @TestMetadata("accessorStabilityInClass.1.kt") + public void testAccessorStabilityInClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/private/accessorStabilityInClass.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + + public void testAllFilesPresentInPrivate() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/private"), Pattern.compile("^(.+)\\.1.kt$"), true); + } + + @TestMetadata("privateInInlineInMultiFileFacade.1.kt") + public void testPrivateInInlineInMultiFileFacade() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + + @TestMetadata("privateInline.1.kt") + public void testPrivateInline() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/private/privateInline.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/reified") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 48d6b4bd508..028f3daa40c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -4664,6 +4664,45 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode } } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/topLevelPrivate") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TopLevelPrivate extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInTopLevelPrivate() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/topLevelPrivate"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("noPrivateNoAccessorsInMultiFileFacade.kt") + public void testNoPrivateNoAccessorsInMultiFileFacade() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade.kt"); + doTestWithStdlib(fileName); + } + + @TestMetadata("noPrivateNoAccessorsInMultiFileFacade2.kt") + public void testNoPrivateNoAccessorsInMultiFileFacade2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/topLevelPrivate/noPrivateNoAccessorsInMultiFileFacade2.kt"); + doTestWithStdlib(fileName); + } + + @TestMetadata("privateInInlineNested.kt") + public void testPrivateInInlineNested() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/topLevelPrivate/privateInInlineNested.kt"); + doTestWithStdlib(fileName); + } + + @TestMetadata("syntheticAccessor.kt") + public void testSyntheticAccessor() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessor.kt"); + doTestWithStdlib(fileName); + } + + @TestMetadata("syntheticAccessorInMultiFile.kt") + public void testSyntheticAccessorInMultiFile() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/topLevelPrivate/syntheticAccessorInMultiFile.kt"); + doTestWithStdlib(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/typeMapping") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index d629aa6e49d..dd1286efdb7 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -983,6 +983,39 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi } } + @TestMetadata("compiler/testData/codegen/boxInline/private") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Private extends AbstractCompileKotlinAgainstInlineKotlinTest { + @TestMetadata("accessorStability.1.kt") + public void testAccessorStability() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/private/accessorStability.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + + @TestMetadata("accessorStabilityInClass.1.kt") + public void testAccessorStabilityInClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/private/accessorStabilityInClass.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + + public void testAllFilesPresentInPrivate() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/private"), Pattern.compile("^(.+)\\.1.kt$"), true); + } + + @TestMetadata("privateInInlineInMultiFileFacade.1.kt") + public void testPrivateInInlineInMultiFileFacade() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/private/privateInInlineInMultiFileFacade.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + + @TestMetadata("privateInline.1.kt") + public void testPrivateInline() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/private/privateInline.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/reified") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)