From 0b49195a036d269d3f34882f09296efcdcebf412 Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Mon, 21 Sep 2015 23:06:22 +0300 Subject: [PATCH] add tests in KotlinJpsTest for check access to internal elements from another module --- .../kotlin/jps/build/KotlinJpsBuildTest.kt | 27 ++++++++++++++++ .../kotlinProject.iml | 13 ++++++++ .../kotlinProject.ipr | 14 ++++++++ .../src/src.kt | 3 ++ .../test/test.kt | 4 +++ .../kotlinProject.ipr | 32 +++++++++++++++++++ .../module1/module1.iml | 14 ++++++++ .../module1/src/module1.kt | 10 ++++++ .../module2/module2.iml | 14 ++++++++ .../module2/src/additional.kt | 9 ++++++ .../module2/src/module2.kt | 29 +++++++++++++++++ .../InternalFromAnotherModule/errors.txt | 3 ++ .../kotlinProject.ipr | 32 +++++++++++++++++++ .../module1/module1.iml | 13 ++++++++ .../module1/src/module1.kt | 10 ++++++ .../module2/module2.iml | 14 ++++++++ .../module2/src/additional.kt | 9 ++++++ .../module2/src/module2.kt | 26 +++++++++++++++ 18 files changed, 276 insertions(+) create mode 100644 jps-plugin/testData/general/AccessToInternalInProductionFromTests/kotlinProject.iml create mode 100644 jps-plugin/testData/general/AccessToInternalInProductionFromTests/kotlinProject.ipr create mode 100644 jps-plugin/testData/general/AccessToInternalInProductionFromTests/src/src.kt create mode 100644 jps-plugin/testData/general/AccessToInternalInProductionFromTests/test/test.kt create mode 100644 jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/kotlinProject.ipr create mode 100644 jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module1/module1.iml create mode 100644 jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module1/src/module1.kt create mode 100644 jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/module2.iml create mode 100644 jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/src/additional.kt create mode 100644 jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/src/module2.kt create mode 100644 jps-plugin/testData/general/InternalFromAnotherModule/errors.txt create mode 100644 jps-plugin/testData/general/InternalFromAnotherModule/kotlinProject.ipr create mode 100644 jps-plugin/testData/general/InternalFromAnotherModule/module1/module1.iml create mode 100644 jps-plugin/testData/general/InternalFromAnotherModule/module1/src/module1.kt create mode 100644 jps-plugin/testData/general/InternalFromAnotherModule/module2/module2.iml create mode 100644 jps-plugin/testData/general/InternalFromAnotherModule/module2/src/additional.kt create mode 100644 jps-plugin/testData/general/InternalFromAnotherModule/module2/src/module2.kt diff --git a/jps-plugin/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps-plugin/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index 6a6a749a614..48721526603 100644 --- a/jps-plugin/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps-plugin/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -43,6 +43,7 @@ import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.kotlin.codegen.JvmCodegenUtil import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.test.JetTestUtils import org.jetbrains.kotlin.test.MockLibraryUtil import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.org.objectweb.asm.ClassReader @@ -472,6 +473,25 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { checkWhen(touch("module2/src/b.kt"), null, packageClasses("module2", "module2/src/b.kt", "test.TestPackage")) } + public fun testInternalFromAnotherModule() { + initProject() + val result = makeAll() + result.assertFailed() + + val actualErrors = result.getMessages(BuildMessage.Kind.ERROR) + .map { it.messageText }.sorted().joinToString("\n") + val projectRoot = File(AbstractKotlinJpsBuildTestCase.TEST_DATA_PATH + "general/" + getTestName(false)) + val expectedFile = File(projectRoot, "errors.txt") + JetTestUtils.assertEqualsToFile(expectedFile, actualErrors) + } + + // TODO See KT-9299 In a project with circular dependencies between modules, IDE reports error on use of internal class from another module, but the corresponding code still compiles and runs. + public fun testCircularDependenciesInternalFromAnotherModule() { + initProject() + val result = makeAll() + result.assertSuccessful() + } + public fun testCircularDependencyWithReferenceToOldVersionLib() { initProject() @@ -496,6 +516,13 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { result.assertSuccessful() } + public fun testAccessToInternalInProductionFromTests() { + initProject() + + val result = makeAll() + result.assertSuccessful() + } + private fun createKotlinJavaScriptLibraryArchive() { val jarFile = File(workDir, KOTLIN_JS_LIBRARY_JAR) try { diff --git a/jps-plugin/testData/general/AccessToInternalInProductionFromTests/kotlinProject.iml b/jps-plugin/testData/general/AccessToInternalInProductionFromTests/kotlinProject.iml new file mode 100644 index 00000000000..a441b33e10b --- /dev/null +++ b/jps-plugin/testData/general/AccessToInternalInProductionFromTests/kotlinProject.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps-plugin/testData/general/AccessToInternalInProductionFromTests/kotlinProject.ipr b/jps-plugin/testData/general/AccessToInternalInProductionFromTests/kotlinProject.ipr new file mode 100644 index 00000000000..90747786771 --- /dev/null +++ b/jps-plugin/testData/general/AccessToInternalInProductionFromTests/kotlinProject.ipr @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps-plugin/testData/general/AccessToInternalInProductionFromTests/src/src.kt b/jps-plugin/testData/general/AccessToInternalInProductionFromTests/src/src.kt new file mode 100644 index 00000000000..f820de4b762 --- /dev/null +++ b/jps-plugin/testData/general/AccessToInternalInProductionFromTests/src/src.kt @@ -0,0 +1,3 @@ +fun foo() { } + +internal fun internalBar() {} \ No newline at end of file diff --git a/jps-plugin/testData/general/AccessToInternalInProductionFromTests/test/test.kt b/jps-plugin/testData/general/AccessToInternalInProductionFromTests/test/test.kt new file mode 100644 index 00000000000..1249dfa8d90 --- /dev/null +++ b/jps-plugin/testData/general/AccessToInternalInProductionFromTests/test/test.kt @@ -0,0 +1,4 @@ +fun test() { + foo() + internalBar() +} \ No newline at end of file diff --git a/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/kotlinProject.ipr b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/kotlinProject.ipr new file mode 100644 index 00000000000..c1a403dd047 --- /dev/null +++ b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/kotlinProject.ipr @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module1/module1.iml b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module1/module1.iml new file mode 100644 index 00000000000..c9205eae762 --- /dev/null +++ b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module1/module1.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module1/src/module1.kt b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module1/src/module1.kt new file mode 100644 index 00000000000..30fcc94d780 --- /dev/null +++ b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module1/src/module1.kt @@ -0,0 +1,10 @@ +package test + +internal open class InternalClass1 + +abstract class ClassA1(internal val member: Int) + +abstract class ClassB1 { + internal abstract val member: Int +} + diff --git a/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/module2.iml b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/module2.iml new file mode 100644 index 00000000000..ecdc9e147ae --- /dev/null +++ b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/module2.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/src/additional.kt b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/src/additional.kt new file mode 100644 index 00000000000..e7ebf8914c0 --- /dev/null +++ b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/src/additional.kt @@ -0,0 +1,9 @@ +package test + +internal open class InternalClass2 + +abstract class ClassA2(internal val member: Int) + +abstract class ClassB2 { + internal abstract val member: Int +} diff --git a/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/src/module2.kt b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/src/module2.kt new file mode 100644 index 00000000000..1f1647ddad4 --- /dev/null +++ b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/module2/src/module2.kt @@ -0,0 +1,29 @@ +// ERROR: 'internal open val member: kotlin.Int defined in test.ClassBB1' has no access to 'internal abstract val member: kotlin.Int defined in test.ClassB1', so it cannot override it +// ERROR: Cannot access 'InternalClass1': it is 'internal' in 'test' +// ERROR: Cannot access 'member': it is 'invisible_fake' in 'ClassAA1' +package test + +// InternalClass1, ClassA1, ClassB1 are in module1 +class ClassInheritedFromInternal1: InternalClass1() + +class ClassAA1 : ClassA1(10) + +class ClassBB1 : ClassB1() { + internal override val member = 10 +} + +// InternalClass2, ClassA2, ClassB2 are in module2 +class ClassInheritedFromInternal2: InternalClass2() + +class ClassAA2 : ClassA2(10) + +class ClassBB2 : ClassB2() { + internal override val member = 10 +} + +fun f() { + val x1 = ClassAA1().member + val x2 = ClassAA2().member +} + + diff --git a/jps-plugin/testData/general/InternalFromAnotherModule/errors.txt b/jps-plugin/testData/general/InternalFromAnotherModule/errors.txt new file mode 100644 index 00000000000..b1533fc68e8 --- /dev/null +++ b/jps-plugin/testData/general/InternalFromAnotherModule/errors.txt @@ -0,0 +1,3 @@ +'internal open val member: kotlin.Int defined in test.ClassBB1' has no access to 'internal abstract val member: kotlin.Int defined in test.ClassB1', so it cannot override it +Cannot access 'InternalClass1': it is 'internal' in 'test' +Cannot access 'member': it is 'invisible_fake' in 'ClassAA1' \ No newline at end of file diff --git a/jps-plugin/testData/general/InternalFromAnotherModule/kotlinProject.ipr b/jps-plugin/testData/general/InternalFromAnotherModule/kotlinProject.ipr new file mode 100644 index 00000000000..c1a403dd047 --- /dev/null +++ b/jps-plugin/testData/general/InternalFromAnotherModule/kotlinProject.ipr @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jps-plugin/testData/general/InternalFromAnotherModule/module1/module1.iml b/jps-plugin/testData/general/InternalFromAnotherModule/module1/module1.iml new file mode 100644 index 00000000000..3b1ba79ed61 --- /dev/null +++ b/jps-plugin/testData/general/InternalFromAnotherModule/module1/module1.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/jps-plugin/testData/general/InternalFromAnotherModule/module1/src/module1.kt b/jps-plugin/testData/general/InternalFromAnotherModule/module1/src/module1.kt new file mode 100644 index 00000000000..30fcc94d780 --- /dev/null +++ b/jps-plugin/testData/general/InternalFromAnotherModule/module1/src/module1.kt @@ -0,0 +1,10 @@ +package test + +internal open class InternalClass1 + +abstract class ClassA1(internal val member: Int) + +abstract class ClassB1 { + internal abstract val member: Int +} + diff --git a/jps-plugin/testData/general/InternalFromAnotherModule/module2/module2.iml b/jps-plugin/testData/general/InternalFromAnotherModule/module2/module2.iml new file mode 100644 index 00000000000..ecdc9e147ae --- /dev/null +++ b/jps-plugin/testData/general/InternalFromAnotherModule/module2/module2.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/jps-plugin/testData/general/InternalFromAnotherModule/module2/src/additional.kt b/jps-plugin/testData/general/InternalFromAnotherModule/module2/src/additional.kt new file mode 100644 index 00000000000..e7ebf8914c0 --- /dev/null +++ b/jps-plugin/testData/general/InternalFromAnotherModule/module2/src/additional.kt @@ -0,0 +1,9 @@ +package test + +internal open class InternalClass2 + +abstract class ClassA2(internal val member: Int) + +abstract class ClassB2 { + internal abstract val member: Int +} diff --git a/jps-plugin/testData/general/InternalFromAnotherModule/module2/src/module2.kt b/jps-plugin/testData/general/InternalFromAnotherModule/module2/src/module2.kt new file mode 100644 index 00000000000..e4e4077a9f4 --- /dev/null +++ b/jps-plugin/testData/general/InternalFromAnotherModule/module2/src/module2.kt @@ -0,0 +1,26 @@ +package test + +// InternalClass1, ClassA1, ClassB1 are in module1 +class ClassInheritedFromInternal1: InternalClass1() + +class ClassAA1 : ClassA1(10) + +class ClassBB1 : ClassB1() { + internal override val member = 10 +} + +// InternalClass2, ClassA2, ClassB2 are in module2 +class ClassInheritedFromInternal2: InternalClass2() + +class ClassAA2 : ClassA2(10) + +class ClassBB2 : ClassB2() { + internal override val member = 10 +} + +fun f() { + val x1 = ClassAA1().member + val x2 = ClassAA2().member +} + +