JS stdlib: test that js library doesn't contain internal declarations.
This commit is contained in:
@@ -18,10 +18,6 @@ import org.junit.Test
|
|||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
|
||||||
import com.intellij.openapi.util.Disposer
|
import com.intellij.openapi.util.Disposer
|
||||||
import org.jetbrains.jet.config.CompilerConfiguration
|
import org.jetbrains.jet.config.CompilerConfiguration
|
||||||
import org.jetbrains.jet.config.CommonConfigurationKeys
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.TopDownAnalyzerFacadeForJVM
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility
|
||||||
@@ -33,19 +29,31 @@ import java.util.ArrayList
|
|||||||
import org.jetbrains.jet.lang.psi.JetFile
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
import org.jetbrains.jet.renderer.DescriptorRenderer
|
import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||||
import kotlin.test.fail
|
import kotlin.test.fail
|
||||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
|
|
||||||
import org.jetbrains.jet.utils.PathUtil
|
import org.jetbrains.jet.utils.PathUtil
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||||
import org.junit.Assert
|
|
||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
|
import org.jetbrains.jet.config.CommonConfigurationKeys
|
||||||
|
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.TopDownAnalyzerFacadeForJVM
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingTraceContext
|
||||||
|
import org.jetbrains.k2js.config.LibrarySourcesConfig
|
||||||
|
import org.jetbrains.k2js.config.EcmaVersion
|
||||||
|
import org.jetbrains.k2js.analyze.TopDownAnalyzerFacadeForJS
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
|
|
||||||
// this list is not designed to contain all packages, it is need for sanity check in case test code breaks
|
private val ANALYZE_PACKAGE_ROOTS_FOR_JVM = listOf("kotlin")
|
||||||
private val PACKAGES_SHOULD_BE_VALIDATED = listOf("kotlin", "kotlin.concurrent", "kotlin.jvm") map { FqName(it) }
|
private val ANALYZE_PACKAGE_ROOTS_FOR_JS = listOf("kotlin", "jquery", "html5")
|
||||||
|
|
||||||
|
// these lists are not designed to contain all packages, they need for sanity check in case test code breaks
|
||||||
|
private val ADDITIONALLY_REQUIRED_PACKAGES_FOR_JVM = listOf("kotlin.jvm", "kotlin.concurrent")
|
||||||
|
private val ADDITIONALLY_REQUIRED_PACKAGES_FOR_JS = listOf("kotlin.js", "kotlin.reflect")
|
||||||
|
|
||||||
|
private val KOTLIN_ROOT_PATH = "../../../"
|
||||||
|
|
||||||
class NoInternalVisibilityInStdLibTest {
|
class NoInternalVisibilityInStdLibTest {
|
||||||
private class OutputSink {
|
private class OutputSink(private val requiredPackages: List<FqName>) {
|
||||||
private val internalDescriptors = ArrayList<DeclarationDescriptor>()
|
private val internalDescriptors = ArrayList<DeclarationDescriptor>()
|
||||||
private val validatedPackages = HashSet<FqName>()
|
private val validatedPackages = HashSet<FqName>()
|
||||||
|
|
||||||
@@ -61,10 +69,10 @@ class NoInternalVisibilityInStdLibTest {
|
|||||||
println("Validated packages: ")
|
println("Validated packages: ")
|
||||||
validatedPackages.forEach { println(" $it") }
|
validatedPackages.forEach { println(" $it") }
|
||||||
|
|
||||||
Assert.assertTrue(
|
if (!validatedPackages.containsAll(requiredPackages)) {
|
||||||
"Some of the expected stdlib packages were not validated, check code of the test",
|
fail("Some of the expected stdlib packages were not validated: " +
|
||||||
validatedPackages.containsAll(PACKAGES_SHOULD_BE_VALIDATED)
|
requiredPackages.subtract(validatedPackages))
|
||||||
)
|
}
|
||||||
|
|
||||||
if (internalDescriptors.isEmpty()) return
|
if (internalDescriptors.isEmpty()) return
|
||||||
|
|
||||||
@@ -96,16 +104,19 @@ class NoInternalVisibilityInStdLibTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Test fun testNoInternalVisibility() {
|
Test fun testJvmStdlib() {
|
||||||
val disposable = Disposer.newDisposable()
|
doTest(ANALYZE_PACKAGE_ROOTS_FOR_JVM, ADDITIONALLY_REQUIRED_PACKAGES_FOR_JVM) {
|
||||||
val module = try {
|
|
||||||
val configuration = CompilerConfiguration()
|
val configuration = CompilerConfiguration()
|
||||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, "../src/kotlin")
|
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, "../src/kotlin")
|
||||||
|
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, "../src/generated")
|
||||||
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.getJdkClassesRoots())
|
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.getJdkClassesRoots())
|
||||||
val environment = JetCoreEnvironment.createForProduction(disposable, configuration)
|
|
||||||
|
val environment = JetCoreEnvironment.createForProduction(it, configuration)
|
||||||
|
|
||||||
val module = TopDownAnalyzerFacadeForJVM.createJavaModule("<module for validating std lib>")
|
val module = TopDownAnalyzerFacadeForJVM.createJavaModule("<module for validating std lib>")
|
||||||
module.addDependencyOnModule(module)
|
module.addDependencyOnModule(module)
|
||||||
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule())
|
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule())
|
||||||
|
|
||||||
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||||
environment.getProject(),
|
environment.getProject(),
|
||||||
environment.getSourceFiles(),
|
environment.getSourceFiles(),
|
||||||
@@ -116,12 +127,41 @@ class NoInternalVisibilityInStdLibTest {
|
|||||||
null
|
null
|
||||||
).getModuleDescriptor()
|
).getModuleDescriptor()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Test fun testJsStdlibJar() {
|
||||||
|
doTest(ANALYZE_PACKAGE_ROOTS_FOR_JS, ADDITIONALLY_REQUIRED_PACKAGES_FOR_JS) {
|
||||||
|
val configuration = CompilerConfiguration()
|
||||||
|
val environment = JetCoreEnvironment.createForProduction(it, configuration)
|
||||||
|
val project = environment.getProject()
|
||||||
|
val pathToJsStdlibJar = KOTLIN_ROOT_PATH + PathUtil.getKotlinPathsForDistDirectory().getJsLibJarPath().path
|
||||||
|
val config = LibrarySourcesConfig(project, "testModule", listOf("@", pathToJsStdlibJar), EcmaVersion.defaultVersion(), false)
|
||||||
|
|
||||||
|
TopDownAnalyzerFacadeForJS.analyzeFiles(listOf(), { true }, config).getModuleDescriptor()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doTest(
|
||||||
|
testPackages: List<String>,
|
||||||
|
additionallyRequiredPackages: List<String>,
|
||||||
|
createTestModule: (disposable: Disposable) -> ModuleDescriptor
|
||||||
|
) {
|
||||||
|
val disposable = Disposer.newDisposable()
|
||||||
|
val module = try {
|
||||||
|
createTestModule(disposable)
|
||||||
|
}
|
||||||
finally {
|
finally {
|
||||||
Disposer.dispose(disposable)
|
Disposer.dispose(disposable)
|
||||||
}
|
}
|
||||||
val kotlinPackage = module.getPackage(FqName("kotlin"))!!
|
|
||||||
val sink = OutputSink()
|
val requiredPackages = testPackages + additionallyRequiredPackages
|
||||||
validateDescriptor(module, kotlinPackage, sink)
|
val sink = OutputSink(requiredPackages map { FqName(it) })
|
||||||
|
|
||||||
|
for (testPackage in testPackages) {
|
||||||
|
val packageView = module.getPackage(FqName(testPackage))!!
|
||||||
|
validateDescriptor(module, packageView, sink)
|
||||||
|
}
|
||||||
|
|
||||||
sink.reportErrors()
|
sink.reportErrors()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,4 +185,4 @@ class NoInternalVisibilityInStdLibTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user