Use box tests to check if the light analysis mode (without analyzing bodies when possible) produces the same result as the complete analysis. See also the next commit in which light analysis mode is applied. Note that no tests were changed.

This commit is contained in:
Yan Zhulanow
2016-11-03 01:21:23 +03:00
committed by Yan Zhulanow
parent 8bdb54929b
commit 328286ab14
2287 changed files with 51250 additions and 2 deletions
@@ -16,8 +16,12 @@
package org.jetbrains.kotlin.codegen
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar
import org.jetbrains.org.objectweb.asm.*
import org.jetbrains.org.objectweb.asm.Opcodes.*
import java.io.File
@@ -26,13 +30,49 @@ abstract class AbstractBytecodeListingTest : CodegenTestCase() {
protected open val classBuilderFactory: ClassBuilderFactory
get() = ClassBuilderFactories.TEST
open fun getTextFile(ktFile: File): File = File(ktFile.parentFile, ktFile.nameWithoutExtension + ".txt")
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>, javaFilesDir: File?) {
val javaSources = javaFilesDir?.let { arrayOf(it) } ?: emptyArray()
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, *javaSources)
var addRuntime = false
var addReflect = false
for (file in files) {
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_RUNTIME")) {
addRuntime = true
}
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_REFLECT")) {
addReflect = true
}
}
val configurationKind = if (addReflect)
ConfigurationKind.ALL
else if (addRuntime)
ConfigurationKind.NO_KOTLIN_REFLECT
else
ConfigurationKind.JDK_ONLY
val jdkKind = getJdkKind(files)
if (myEnvironment != null) {
throw IllegalStateException("must not set up myEnvironment twice")
}
val configuration = createConfiguration(
configurationKind,
jdkKind,
listOf<File>(getAnnotationsJar()),
javaSources.filterNotNull(),
emptyList())
myEnvironment = KotlinCoreEnvironment.createForTests(
testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES
)
loadMultiFiles(files)
val txtFile = File(wholeFile.parentFile, wholeFile.nameWithoutExtension + ".txt")
val txtFile = getTextFile(wholeFile)
val generatedFiles = CodegenTestUtil.generateFiles(myEnvironment, myFiles, classBuilderFactory)
.getClassFiles()
.sortedBy { it.relativePath }
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2016 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.
*/
package org.jetbrains.kotlin.codegen
import java.io.File
abstract class AbstractLightAnalysisModeCodegenTest : AbstractBytecodeListingTest() {
override val classBuilderFactory: ClassBuilderFactory
get() = ClassBuilderFactories.TEST_LIGHT_CLASSES
override fun getTextFile(ktFile: File): File {
val boxTestsDir = File("compiler/testData/codegen/box")
val outDir = File("compiler/testData/codegen/light-analysis", ktFile.toRelativeString(boxTestsDir)).parent
return File(outDir, ktFile.nameWithoutExtension + ".txt")
}
}