Register plugin extensions in tests
This commit is contained in:
+26
-4
@@ -32,6 +32,12 @@ import org.jetbrains.jet.codegen.CodegenTestFiles
|
||||
import java.util.regex.Pattern
|
||||
import org.jetbrains.jet.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.android.AndroidConfigurationKeys
|
||||
import org.jetbrains.jet.JetTestCaseBuilder
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import org.jetbrains.jet.extensions.ExternalDeclarationsProvider
|
||||
import org.jetbrains.kotlin.android.AndroidExpressionCodegen
|
||||
import org.jetbrains.jet.codegen.extensions.ExpressionCodegenExtension
|
||||
import org.jetbrains.jet.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
|
||||
public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
|
||||
|
||||
@@ -44,9 +50,14 @@ public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
|
||||
}
|
||||
|
||||
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, path + "layout/");
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, path + "AndroidManifest.xml");
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration);
|
||||
val resPath = path + "layout/"
|
||||
val manifestPath = path + "AndroidManifest.xml"
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, resPath)
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, manifestPath)
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
val project = myEnvironment.getProject()
|
||||
ExternalDeclarationsProvider.registerExtension(project, AndroidTestDeclarationsProvider(project, resPath, manifestPath))
|
||||
ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegen())
|
||||
}
|
||||
|
||||
public fun doCompileAgainstAndroidSdkTest(path: String) {
|
||||
@@ -69,6 +80,13 @@ public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
|
||||
return !FileUtil.findFilesByMask(Pattern.compile("^0.kt$"), File(path)).empty
|
||||
}
|
||||
|
||||
override fun relativePath(file: File): String {
|
||||
val stringToCut = "plugins/android-compiler-plugin/testData/codegen/"
|
||||
val systemIndependentPath = file.getPath().replace(File.separatorChar, '/')
|
||||
assert(systemIndependentPath.startsWith(stringToCut), "File path is not absolute: $file ")
|
||||
return systemIndependentPath.substring(stringToCut.length())
|
||||
}
|
||||
|
||||
private fun doMultiFileTest(path: String, additionalFiles: Collection<String>? = null) {
|
||||
val files = ArrayList<String>(2)
|
||||
FileUtil.processFilesRecursively(File(path), object : Processor<File> {
|
||||
@@ -85,7 +103,11 @@ public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
|
||||
if (additionalFiles != null) {
|
||||
files.addAll(additionalFiles)
|
||||
}
|
||||
myFiles = CodegenTestFiles.create(myEnvironment!!.getProject(), ArrayUtil.toStringArray(files))
|
||||
myFiles = CodegenTestFiles.create(
|
||||
myEnvironment!!.getProject(),
|
||||
ArrayUtil.toStringArray(files),
|
||||
JetTestCaseBuilder.getHomeDirectory() + "/plugins/android-compiler-plugin/testData"
|
||||
)
|
||||
blackBox();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -24,6 +24,10 @@ import org.jetbrains.jet.config.CompilerConfiguration
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
|
||||
import org.jetbrains.kotlin.android.AndroidConfigurationKeys
|
||||
import org.jetbrains.jet.extensions.ExternalDeclarationsProvider
|
||||
import org.jetbrains.jet.codegen.extensions.ExpressionCodegenExtension
|
||||
import org.jetbrains.kotlin.android.AndroidExpressionCodegen
|
||||
import org.jetbrains.jet.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
|
||||
public abstract class AbstractAndroidBytecodePersistenceTest : AbstractBytecodeTextTest() {
|
||||
|
||||
@@ -36,10 +40,16 @@ public abstract class AbstractAndroidBytecodePersistenceTest : AbstractBytecodeT
|
||||
}
|
||||
|
||||
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, path + "res/layout/");
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, path + "../AndroidManifest.xml");
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration);
|
||||
val resPath = path + "res/layout/"
|
||||
val manifestPath = path + "../AndroidManifest.xml"
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, resPath)
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, manifestPath)
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
val project = myEnvironment.getProject()
|
||||
ExternalDeclarationsProvider.registerExtension(project, AndroidTestDeclarationsProvider(project, resPath, manifestPath))
|
||||
ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegen())
|
||||
}
|
||||
|
||||
public override fun doTest(path: String) {
|
||||
val fileName = path + getTestName(true) + ".kt"
|
||||
createAndroidAPIEnvironment(path)
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import org.jetbrains.jet.TestJdkKind
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
|
||||
import org.junit.Assert
|
||||
import kotlin.test.fail
|
||||
import org.jetbrains.jet.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
|
||||
public abstract class AbstractAndroidXml2KConversionTest : UsefulTestCase() {
|
||||
|
||||
@@ -54,6 +55,6 @@ public abstract class AbstractAndroidXml2KConversionTest : UsefulTestCase() {
|
||||
val configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK)
|
||||
// configuration.put<String>(JVMConfigurationKeys.ANDROID_RES_PATH, testPath + "/layout")
|
||||
// configuration.put<String>(JVMConfigurationKeys.ANDROID_MANIFEST, testPath + "/AndroidManifest.xml")
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration)
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.resolve.android
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jet.extensions.ExternalDeclarationsProvider
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.utils.emptyOrSingletonList
|
||||
|
||||
private class AndroidTestDeclarationsProvider(
|
||||
val project: Project,
|
||||
val resPath: String,
|
||||
val manifestPath: String
|
||||
) : ExternalDeclarationsProvider {
|
||||
override fun getExternalDeclarations(): Collection<JetFile> {
|
||||
val parser = CliAndroidUIXmlProcessor(project, resPath, manifestPath)
|
||||
return emptyOrSingletonList(parser.parseToPsi(project))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user