Reformat and cleanup most JVM codegen test classes

This commit is contained in:
Alexander Udalov
2019-03-29 14:56:35 +01:00
parent 23a214710b
commit 7fdb9c990e
43 changed files with 491 additions and 580 deletions
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 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.
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.android.parcel
@@ -37,11 +26,11 @@ import java.util.concurrent.TimeUnit
abstract class AbstractParcelBoxTest : CodegenTestCase() {
protected companion object {
val BASE_DIR = "plugins/android-extensions/android-extensions-compiler/testData/parcel/box"
const val BASE_DIR = "plugins/android-extensions/android-extensions-compiler/testData/parcel/box"
val LIBRARY_KT = File(File(BASE_DIR).parentFile, "boxLib.kt")
private val JUNIT_GENERATED_TEST_CLASS_BYTES by lazy { constructSyntheticTestClass() }
private val JUNIT_GENERATED_TEST_CLASS_FQNAME = "test.JunitTest"
private const val JUNIT_GENERATED_TEST_CLASS_FQNAME = "test.JunitTest"
private fun constructSyntheticTestClass(): ByteArray {
return with(ClassWriter(COMPUTE_MAXS or COMPUTE_FRAMES)) {
@@ -104,12 +93,12 @@ abstract class AbstractParcelBoxTest : CodegenTestCase() {
}
override fun doTest(filePath: String) {
super.doTest(File(BASE_DIR, filePath + ".kt").absolutePath)
super.doTest(File(BASE_DIR, "$filePath.kt").absolutePath)
}
private val androidPluginPath: String by lazy {
System.getProperty("ideaSdk.androidPlugin.path")?.takeIf { File(it).isDirectory }
?: throw RuntimeException("Unable to get a valid path from 'ideaSdk.androidPlugin.path' property, please point it to the Idea android plugin location")
?: throw RuntimeException("Unable to get a valid path from 'ideaSdk.androidPlugin.path' property, please point it to the Idea android plugin location")
}
private fun getClasspathForTest(): List<File> {
@@ -117,10 +106,10 @@ abstract class AbstractParcelBoxTest : CodegenTestCase() {
val layoutLibJars = listOf(File(androidPluginPath, "layoutlib.jar"), File(androidPluginPath, "layoutlib-api.jar"))
val robolectricClasspath = System.getProperty("robolectric.classpath")
?: throw RuntimeException("Unable to get a valid classpath from 'robolectric.classpath' property, please set it accordingly")
?: throw RuntimeException("Unable to get a valid classpath from 'robolectric.classpath' property, please set it accordingly")
val robolectricJars = robolectricClasspath.split(File.pathSeparator)
.map { File(it) }
.sortedBy { it.nameWithoutExtension }
.map { File(it) }
.sortedBy { it.nameWithoutExtension }
val junitCoreResourceName = JUnitCore::class.java.name.replace('.', '/') + ".class"
val junitJar = File(JUnitCore::class.java.classLoader.getResource(junitCoreResourceName).file.substringBeforeLast('!'))
@@ -151,12 +140,12 @@ abstract class AbstractParcelBoxTest : CodegenTestCase() {
classFileFactory.getClassFiles().forEach { writeClass(it.relativePath, it.asByteArray()) }
val process = ProcessBuilder(
javaExe.absolutePath,
"-ea",
"-classpath",
(libraryClasspath + dirForTestClasses).joinToString(File.pathSeparator),
JUnitCore::class.java.name,
JUNIT_GENERATED_TEST_CLASS_FQNAME
javaExe.absolutePath,
"-ea",
"-classpath",
(libraryClasspath + dirForTestClasses).joinToString(File.pathSeparator),
JUnitCore::class.java.name,
JUNIT_GENERATED_TEST_CLASS_FQNAME
).inheritIO().start()
process.waitFor(3, TimeUnit.MINUTES)
@@ -175,4 +164,4 @@ abstract class AbstractParcelBoxTest : CodegenTestCase() {
addAndroidExtensionsRuntimeLibrary(environment)
environment.updateClasspath(listOf(JvmClasspathRoot(File(androidPluginPath, "layoutlib.jar"))))
}
}
}
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 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.
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.android.parcel
@@ -28,7 +17,9 @@ abstract class AbstractParcelBytecodeListingTest : AbstractAsmLikeInstructionLis
AndroidComponentRegistrar.registerParcelExtensions(environment.project)
addAndroidExtensionsRuntimeLibrary(environment)
val androidPluginPath = System.getProperty("ideaSdk.androidPlugin.path")?.takeIf { File(it).isDirectory }
?: throw RuntimeException("Unable to get a valid path from 'ideaSdk.androidPlugin.path' property, please point it to the Idea android plugin location")
?: throw RuntimeException(
"Unable to get a valid path from 'ideaSdk.androidPlugin.path' property, please point it to the Idea android plugin location"
)
environment.updateClasspath(listOf(JvmClasspathRoot(File(androidPluginPath, "layoutlib.jar"))))
}
}
}
@@ -1,24 +1,12 @@
/*
* Copyright 2010-2017 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.
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.android.synthetic.test
import com.intellij.openapi.util.io.FileUtil
import com.intellij.util.ArrayUtil
import com.intellij.util.Processor
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
import org.jetbrains.kotlin.codegen.AbstractBlackBoxCodegenTest
import org.jetbrains.kotlin.codegen.CodegenTestFiles
@@ -28,7 +16,6 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TestJdkKind
import java.io.File
import java.net.URL
import java.util.*
import java.util.regex.Pattern
abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
@@ -42,7 +29,9 @@ abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
}
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
val layoutPaths = File(path).listFiles { it -> it.name.startsWith("layout") && it.isDirectory }!!.map { "$path${it.name}/" }
val layoutPaths = File(path)
.listFiles { file -> file.name.startsWith("layout") && file.isDirectory }!!
.map { "$path${it.name}/" }
myEnvironment = createTestEnvironment(configuration, layoutPaths)
}
@@ -63,11 +52,12 @@ abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
}
private fun getFakeFiles(path: String): Collection<String> {
return FileUtil.findFilesByMask(Pattern.compile("^Fake.*\\.kt$"), File(path.replace(getTestName(true), ""))).map { relativePath(it) }
return FileUtil.findFilesByMask(Pattern.compile("^Fake.*\\.kt$"), File(path.replace(getTestName(true), "")))
.map { relativePath(it) }
}
private fun needsInvocationTest(path: String): Boolean {
return !FileUtil.findFilesByMask(Pattern.compile("^0.kt$"), File(path)).isEmpty()
return FileUtil.findFilesByMask(Pattern.compile("^0.kt$"), File(path)).isNotEmpty()
}
override fun codegenTestBasePath(): String {
@@ -76,35 +66,33 @@ abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
private fun doMultiFileTest(path: String, additionalFiles: Collection<String>? = null) {
val files = mutableListOf<String>()
FileUtil.processFilesRecursively(File(path), object : Processor<File> {
override fun process(file: File?): Boolean {
when (file!!.name) {
"1.kt" -> {
if (additionalFiles == null) files.add(relativePath(file))
}
"0.kt" -> {
if (additionalFiles != null) files.add(relativePath(file))
}
else -> {
if (file.name.endsWith(".kt")) files.add(relativePath(file))
}
FileUtil.processFilesRecursively(File(path)) { file ->
when (file!!.name) {
"1.kt" -> {
if (additionalFiles == null) files.add(relativePath(file))
}
"0.kt" -> {
if (additionalFiles != null) files.add(relativePath(file))
}
else -> {
if (file.name.endsWith(".kt")) files.add(relativePath(file))
}
return true
}
})
true
}
for (file in File("plugins/android-extensions/android-extensions-runtime/src").walk()) {
if (file.extension == "kt") files += relativePath(file.absoluteFile)
}
Collections.sort(files)
files.sort()
if (additionalFiles != null) {
files.addAll(additionalFiles)
}
myFiles = CodegenTestFiles.create(
myEnvironment!!.project,
ArrayUtil.toStringArray(files),
KotlinTestUtils.getHomeDirectory() + "/plugins/android-extensions/android-extensions-compiler/testData"
myEnvironment!!.project,
ArrayUtil.toStringArray(files),
KotlinTestUtils.getHomeDirectory() + "/plugins/android-extensions/android-extensions-compiler/testData"
)
blackBox(true)
}
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 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.
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.android.synthetic.test
@@ -41,20 +30,20 @@ abstract class AbstractAndroidSyntheticPropertyDescriptorTest : KtUsefulTestCase
val analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(listOf(), env)
val fragmentProvider =
ext.getPackageFragmentProvider(
project, analysisResult.moduleDescriptor, LockBasedStorageManager.NO_LOCKS,
KotlinTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE, null, LookupTracker.DO_NOTHING
) as AndroidSyntheticPackageFragmentProvider
ext.getPackageFragmentProvider(
project, analysisResult.moduleDescriptor, LockBasedStorageManager.NO_LOCKS,
KotlinTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE, null, LookupTracker.DO_NOTHING
) as AndroidSyntheticPackageFragmentProvider
val renderer = DescriptorRenderer.COMPACT_WITH_MODIFIERS
val expected = fragmentProvider.packages.values
.map { it() }
.sortedBy { it.fqName.asString() }
.joinToString(separator = "\n\n\n") {
val descriptors = it.getMemberScope().getContributedDescriptors()
.joinToString(separator = "\n\n\n") { packageFragment ->
val descriptors = packageFragment.getMemberScope().getContributedDescriptors()
.sortedWith(MemberComparator.INSTANCE)
.map { " " + renderer.render(it) }.joinToString("\n")
it.fqName.asString() + (if (descriptors.isNotEmpty()) "\n\n" + descriptors else "")
.joinToString("\n") { " " + renderer.render(it) }
packageFragment.fqName.asString() + (if (descriptors.isNotEmpty()) "\n\n" + descriptors else "")
}
KotlinTestUtils.assertEqualsToFile(File(path, "result.txt"), expected)
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 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.
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.android.synthetic.test
@@ -35,8 +24,6 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import org.jetbrains.kotlin.utils.KotlinPaths
import org.jetbrains.kotlin.utils.KotlinPathsFromHomeDir
import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
@@ -52,7 +39,9 @@ fun KtUsefulTestCase.createTestEnvironment(configuration: CompilerConfiguration,
ExpressionCodegenExtension.registerExtension(project, CliAndroidExtensionsExpressionCodegenExtension(true, CacheImplementation.DEFAULT))
StorageComponentContainerContributor.registerExtension(project, AndroidExtensionPropertiesComponentContainerContributor())
ClassBuilderInterceptorExtension.registerExtension(project, CliAndroidOnDestroyClassBuilderInterceptorExtension(CacheImplementation.DEFAULT))
ClassBuilderInterceptorExtension.registerExtension(
project, CliAndroidOnDestroyClassBuilderInterceptorExtension(CacheImplementation.DEFAULT)
)
PackageFragmentProviderExtension.registerExtension(project, CliAndroidPackageFragmentProviderExtension(true))
addAndroidExtensionsRuntimeLibrary(myEnvironment)
@@ -68,5 +57,7 @@ fun addAndroidExtensionsRuntimeLibrary(environment: KotlinCoreEnvironment) {
}
fun getResPaths(path: String): List<String> {
return File(path).listFiles { it -> it.name.startsWith("res") && it.isDirectory }!!.map { "$path${it.name}/" }
}
return File(path)
.listFiles { file -> file.name.startsWith("res") && file.isDirectory }!!
.map { "$path${it.name}/" }
}