Avoid storing state in consistency tests
This commit is contained in:
+2
-6
@@ -25,12 +25,8 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
public class ClsStubConsistencyTest : StubConsistencyBaseTest() {
|
public class ClsStubConsistencyTest : StubConsistencyBaseTest() {
|
||||||
|
override fun getVirtualFileFinder(): VirtualFileFinder = JvmVirtualFileFinder.SERVICE.getInstance(getProject())
|
||||||
override val packages: List<FqName> = listOf(FqName("kotlin"))
|
override fun getPackages(): List<FqName> = listOf(FqName("kotlin"))
|
||||||
|
|
||||||
override val virtualFileFinder: VirtualFileFinder by Delegates.lazy() {
|
|
||||||
JvmVirtualFileFinder.SERVICE.getInstance(getProject())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun createStubBuilder() = KotlinClsStubBuilder()
|
override fun createStubBuilder() = KotlinClsStubBuilder()
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.decompiler.stubBuilder
|
package org.jetbrains.kotlin.idea.decompiler.stubBuilder
|
||||||
|
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledTextFromJsMetadata
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledTextFromJsMetadata
|
||||||
import org.jetbrains.kotlin.idea.js.KotlinJavaScriptLibraryManager
|
import org.jetbrains.kotlin.idea.js.KotlinJavaScriptLibraryManager
|
||||||
@@ -26,19 +27,17 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
public class KotlinJavaScriptStubConsistencyTest : StubConsistencyBaseTest() {
|
public class KotlinJavaScriptStubConsistencyTest : StubConsistencyBaseTest() {
|
||||||
|
|
||||||
override val packages: List<FqName> = listOf(
|
|
||||||
"java.util", "jquery", "jquery.ui", "kotlin", "kotlin.browser", "kotlin.dom", "kotlin.js"
|
|
||||||
).map { FqName(it) }
|
|
||||||
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
KotlinJavaScriptLibraryManager.getInstance(getProject()).syncUpdateProjectLibrary()
|
KotlinJavaScriptLibraryManager.getInstance(getProject()).syncUpdateProjectLibrary()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val virtualFileFinder: VirtualFileFinder by Delegates.lazy() {
|
override fun getPackages(): List<FqName> = listOf(
|
||||||
|
"java.util", "jquery", "jquery.ui",
|
||||||
|
"kotlin", "kotlin.browser", "kotlin.dom", "kotlin.js").map { FqName(it) }
|
||||||
|
|
||||||
|
override fun getVirtualFileFinder(): VirtualFileFinder =
|
||||||
JsVirtualFileFinder.SERVICE.getInstance(getProject())
|
JsVirtualFileFinder.SERVICE.getInstance(getProject())
|
||||||
}
|
|
||||||
|
|
||||||
override fun createStubBuilder() = KotlinJavaScriptStubBuilder()
|
override fun createStubBuilder() = KotlinJavaScriptStubBuilder()
|
||||||
|
|
||||||
|
|||||||
+4
-5
@@ -29,21 +29,20 @@ import org.junit.Assert
|
|||||||
|
|
||||||
public abstract class StubConsistencyBaseTest : JetLightCodeInsightFixtureTestCase() {
|
public abstract class StubConsistencyBaseTest : JetLightCodeInsightFixtureTestCase() {
|
||||||
|
|
||||||
protected abstract val packages: List<FqName>
|
protected abstract fun getPackages(): List<FqName>
|
||||||
|
protected abstract fun getVirtualFileFinder(): VirtualFileFinder
|
||||||
protected abstract val virtualFileFinder: VirtualFileFinder
|
|
||||||
|
|
||||||
protected abstract fun createStubBuilder(): ClsStubBuilder
|
protected abstract fun createStubBuilder(): ClsStubBuilder
|
||||||
|
|
||||||
protected abstract fun getDecompiledText(packageFile: VirtualFile): String
|
protected abstract fun getDecompiledText(packageFile: VirtualFile): String
|
||||||
|
|
||||||
public fun testConsistency() {
|
public fun testConsistency() {
|
||||||
packages.forEach { doTest(it) }
|
getPackages().forEach { doTest(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTest(packageFqName: FqName) {
|
private fun doTest(packageFqName: FqName) {
|
||||||
val project = getProject()
|
val project = getProject()
|
||||||
val packageFile = virtualFileFinder.findVirtualFileWithHeader(PackageClassUtils.getPackageClassId(packageFqName))!!
|
val packageFile = getVirtualFileFinder().findVirtualFileWithHeader(PackageClassUtils.getPackageClassId(packageFqName))!!
|
||||||
val decompiledText = getDecompiledText(packageFile)
|
val decompiledText = getDecompiledText(packageFile)
|
||||||
val fileWithDecompiledText = JetPsiFactory(project).createFile(decompiledText)
|
val fileWithDecompiledText = JetPsiFactory(project).createFile(decompiledText)
|
||||||
val stubTreeFromDecompiledText = JetFileStubBuilder().buildStubTree(fileWithDecompiledText)
|
val stubTreeFromDecompiledText = JetFileStubBuilder().buildStubTree(fileWithDecompiledText)
|
||||||
|
|||||||
+3
-4
@@ -29,13 +29,12 @@ import kotlin.properties.Delegates
|
|||||||
|
|
||||||
public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
||||||
|
|
||||||
override val packages: List<FqName> = listOf(FqName("kotlin"))
|
override fun getPackages(): List<FqName> = listOf(FqName("kotlin"))
|
||||||
|
|
||||||
override val topLevelMembers: Map<String, String> = mapOf("kotlin" to "linkedListOf")
|
override fun getTopLevelMembers(): Map<String, String> = mapOf("kotlin" to "linkedListOf")
|
||||||
|
|
||||||
override val virtualFileFinder: VirtualFileFinder by Delegates.lazy() {
|
override fun getVirtualFileFinder(): VirtualFileFinder =
|
||||||
JvmVirtualFileFinder.SERVICE.getInstance(getProject())
|
JvmVirtualFileFinder.SERVICE.getInstance(getProject())
|
||||||
}
|
|
||||||
|
|
||||||
override fun getDecompiledText(packageFile: VirtualFile, resolver: ResolverForDecompiler?): String =
|
override fun getDecompiledText(packageFile: VirtualFile, resolver: ResolverForDecompiler?): String =
|
||||||
(resolver?.let { buildDecompiledText(packageFile, it) } ?: buildDecompiledText(packageFile)).text
|
(resolver?.let { buildDecompiledText(packageFile, it) } ?: buildDecompiledText(packageFile)).text
|
||||||
|
|||||||
+4
-6
@@ -30,19 +30,17 @@ import org.jetbrains.kotlin.test.JetTestUtils
|
|||||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||||
import org.jetbrains.kotlin.utils.PathUtil
|
import org.jetbrains.kotlin.utils.PathUtil
|
||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
|
import java.util.*
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
public class KotlinJavaScriptDecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
public class KotlinJavaScriptDecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
||||||
|
override fun getPackages(): List<FqName> = listOf(
|
||||||
override val packages: List<FqName> = listOf(
|
|
||||||
"java.util", "jquery", "jquery.ui", "kotlin", "kotlin.browser", "kotlin.dom", "kotlin.js"
|
"java.util", "jquery", "jquery.ui", "kotlin", "kotlin.browser", "kotlin.dom", "kotlin.js"
|
||||||
).map { FqName(it) }
|
).map { FqName(it) }
|
||||||
|
|
||||||
override val topLevelMembers: Map<String, String> = mapOf("kotlin" to "intArrayOf")
|
override fun getTopLevelMembers(): Map<String, String> = mapOf("kotlin" to "intArrayOf")
|
||||||
|
|
||||||
override val virtualFileFinder: VirtualFileFinder by Delegates.lazy() {
|
override fun getVirtualFileFinder(): VirtualFileFinder = JsVirtualFileFinder.SERVICE.getInstance(getProject())
|
||||||
JsVirtualFileFinder.SERVICE.getInstance(getProject())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
|
|||||||
+6
-6
@@ -34,27 +34,27 @@ import org.junit.Assert
|
|||||||
|
|
||||||
public abstract class TextConsistencyBaseTest : JetLightCodeInsightFixtureTestCase() {
|
public abstract class TextConsistencyBaseTest : JetLightCodeInsightFixtureTestCase() {
|
||||||
|
|
||||||
protected abstract val packages: List<FqName>
|
protected abstract fun getPackages(): List<FqName>
|
||||||
|
|
||||||
protected abstract val topLevelMembers: Map<String, String>
|
protected abstract fun getTopLevelMembers(): Map<String, String>
|
||||||
|
|
||||||
protected abstract val virtualFileFinder: VirtualFileFinder
|
protected abstract fun getVirtualFileFinder(): VirtualFileFinder
|
||||||
|
|
||||||
protected abstract fun getDecompiledText(packageFile: VirtualFile, resolver: ResolverForDecompiler? = null): String
|
protected abstract fun getDecompiledText(packageFile: VirtualFile, resolver: ResolverForDecompiler? = null): String
|
||||||
|
|
||||||
protected abstract fun getModuleDescriptor(): ModuleDescriptor
|
protected abstract fun getModuleDescriptor(): ModuleDescriptor
|
||||||
|
|
||||||
public fun testConsistency() {
|
public fun testConsistency() {
|
||||||
packages.forEach { doTest(it) }
|
getPackages().forEach { doTest(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTest(packageFqName: FqName) {
|
private fun doTest(packageFqName: FqName) {
|
||||||
val packageFile = virtualFileFinder.findVirtualFileWithHeader(PackageClassUtils.getPackageClassId(packageFqName))!!
|
val packageFile = getVirtualFileFinder().findVirtualFileWithHeader(PackageClassUtils.getPackageClassId(packageFqName))!!
|
||||||
val projectBasedText = getDecompiledText(packageFile, ResolverForDecompilerImpl(getModuleDescriptor()))
|
val projectBasedText = getDecompiledText(packageFile, ResolverForDecompilerImpl(getModuleDescriptor()))
|
||||||
val deserializedText = getDecompiledText(packageFile)
|
val deserializedText = getDecompiledText(packageFile)
|
||||||
Assert.assertEquals(projectBasedText, deserializedText)
|
Assert.assertEquals(projectBasedText, deserializedText)
|
||||||
// sanity checks
|
// sanity checks
|
||||||
topLevelMembers[packageFqName.asString()]?.let {
|
getTopLevelMembers()[packageFqName.asString()]?.let {
|
||||||
Assert.assertTrue(projectBasedText.contains(it))
|
Assert.assertTrue(projectBasedText.contains(it))
|
||||||
}
|
}
|
||||||
Assert.assertFalse(projectBasedText.contains("ERROR"))
|
Assert.assertFalse(projectBasedText.contains("ERROR"))
|
||||||
|
|||||||
Reference in New Issue
Block a user