Move Android compiler plugin tests to android-compiler-plugin module

This commit is contained in:
Yan Zhulanow
2014-11-06 15:20:20 +03:00
parent efff642635
commit fa62d3bcec
63 changed files with 70 additions and 79 deletions
@@ -1,91 +0,0 @@
/*
* 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 org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest
import org.jetbrains.jet.ConfigurationKind
import org.jetbrains.jet.TestJdkKind
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
import org.jetbrains.jet.JetTestUtils
import java.util.Collections
import com.intellij.util.ArrayUtil
import com.intellij.openapi.util.io.FileUtil
import java.io.File
import java.util.ArrayList
import com.intellij.util.Processor
import org.jetbrains.jet.codegen.CodegenTestFiles
import java.util.regex.Pattern
import org.jetbrains.jet.config.CompilerConfiguration
import org.jetbrains.kotlin.android.AndroidConfigurationKeys
public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
private fun createAndroidAPIEnvironment(path: String) {
return createEnvironmentForConfiguration(JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.ANDROID_API), path)
}
private fun createFakeAndroidEnvironment(path: String) {
return createEnvironmentForConfiguration(JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK), path)
}
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);
}
public fun doCompileAgainstAndroidSdkTest(path: String) {
createAndroidAPIEnvironment(path)
doMultiFileTest(path)
}
public fun doFakeInvocationTest(path: String) {
if (needsInvocationTest(path)) {
createFakeAndroidEnvironment(path)
doMultiFileTest(path, getFakeFiles(path))
}
}
private fun getFakeFiles(path: String): Collection<String> {
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)).empty
}
private fun doMultiFileTest(path: String, additionalFiles: Collection<String>? = null) {
val files = ArrayList<String>(2)
FileUtil.processFilesRecursively(File(path), object : Processor<File> {
override fun process(file: File?): Boolean {
when (file!!.getName()) {
"1.kt" -> { if (additionalFiles == null) files.add(relativePath(file)) }
"0.kt" -> { if (additionalFiles != null) files.add(relativePath(file)) }
else -> { if (file.getName().endsWith(".kt")) files.add(relativePath(file)) }
}
return true
}
})
Collections.sort(files);
if (additionalFiles != null) {
files.addAll(additionalFiles)
}
myFiles = CodegenTestFiles.create(myEnvironment!!.getProject(), ArrayUtil.toStringArray(files))
blackBox();
}
}
@@ -1,50 +0,0 @@
/*
* 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 org.jetbrains.jet.codegen.AbstractBytecodeTextTest
import org.jetbrains.jet.JetTestUtils
import org.jetbrains.jet.ConfigurationKind
import org.jetbrains.jet.TestJdkKind
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
public abstract class AbstractAndroidBytecodePersistenceTest : AbstractBytecodeTextTest() {
private fun createAndroidAPIEnvironment(path: String) {
return createEnvironmentForConfiguration(JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.ANDROID_API), path)
}
private fun createFakeAndroidEnvironment(path: String) {
return createEnvironmentForConfiguration(JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK), path)
}
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);
}
public override fun doTest(path: String) {
val fileName = path + getTestName(true) + ".kt"
createAndroidAPIEnvironment(path)
loadFileByFullPath(fileName)
val expected = readExpectedOccurrences(fileName)
countAndCompareActualOccurrences(expected)
}
}
@@ -1,59 +0,0 @@
/*
* 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.testFramework.UsefulTestCase
import java.io.File
import java.io.IOException
import java.util.Scanner
import java.io.FileWriter
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
import org.jetbrains.jet.config.CompilerConfiguration
import org.jetbrains.jet.JetTestUtils
import org.jetbrains.jet.ConfigurationKind
import org.jetbrains.jet.TestJdkKind
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
import org.junit.Assert
import kotlin.test.fail
public abstract class AbstractAndroidXml2KConversionTest : UsefulTestCase() {
public fun doTest(path: String) {
val jetCoreEnvironment = getEnvironment(path)
val parser = CliAndroidUIXmlProcessor(jetCoreEnvironment.getProject(), path + "/layout", path + "AndroidManifest.xml")
val actual = parser.parseToString()
JetTestUtils.assertEqualsToFile(File(path + "/layout.kt"), actual!!)
}
public fun doNoManifestTest(path: String) {
try {
doTest(path)
fail("NoAndroidManifestFound not thrown")
}
catch (e: AndroidUIXmlProcessor.NoAndroidManifestFound) {
}
}
private fun getEnvironment(testPath: String): JetCoreEnvironment {
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)
}
}
@@ -1,117 +0,0 @@
/*
* 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.testFramework.TestDataPath;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@InnerTestClasses({AndroidBoxTestGenerated.Android.class, AndroidBoxTestGenerated.Invoke.class})
public class AndroidBoxTestGenerated extends AbstractAndroidBoxTest {
@TestMetadata("compiler/testData/codegen/android")
@TestDataPath("$PROJECT_ROOT")
public static class Android extends AbstractAndroidBoxTest {
public void testAllFilesPresentInAndroid() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/android"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/fqNameInAttr/");
doCompileAgainstAndroidSdkTest(fileName);
}
@TestMetadata("fqNameInTag")
public void testFqNameInTag() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/fqNameInTag/");
doCompileAgainstAndroidSdkTest(fileName);
}
@TestMetadata("manyWidgets")
public void testManyWidgets() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/manyWidgets/");
doCompileAgainstAndroidSdkTest(fileName);
}
@TestMetadata("multiFile")
public void testMultiFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/multiFile/");
doCompileAgainstAndroidSdkTest(fileName);
}
@TestMetadata("singleFile")
public void testSingleFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/singleFile/");
doCompileAgainstAndroidSdkTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/android")
@TestDataPath("$PROJECT_ROOT")
public static class Invoke extends AbstractAndroidBoxTest {
public void testAllFilesPresentInInvoke() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/android"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/fqNameInAttr/");
doFakeInvocationTest(fileName);
}
@TestMetadata("fqNameInTag")
public void testFqNameInTag() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/fqNameInTag/");
doFakeInvocationTest(fileName);
}
@TestMetadata("manyWidgets")
public void testManyWidgets() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/manyWidgets/");
doFakeInvocationTest(fileName);
}
@TestMetadata("multiFile")
public void testMultiFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/multiFile/");
doFakeInvocationTest(fileName);
}
@TestMetadata("singleFile")
public void testSingleFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/android/singleFile/");
doFakeInvocationTest(fileName);
}
}
public static Test suite() {
TestSuite suite = new TestSuite("AndroidBoxTestGenerated");
suite.addTestSuite(Android.class);
suite.addTestSuite(Invoke.class);
return suite;
}
}
@@ -1,62 +0,0 @@
/*
* 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.testFramework.TestDataPath;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/androidPersistence")
@TestDataPath("$PROJECT_ROOT")
public class AndroidBytecodePersistenceTestGenerated extends AbstractAndroidBytecodePersistenceTest {
public void testAllFilesPresentInAndroidPersistence() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/androidPersistence"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/androidPersistence/fqNameInAttr/");
doTest(fileName);
}
@TestMetadata("fqNameInTag")
public void testFqNameInTag() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/androidPersistence/fqNameInTag/");
doTest(fileName);
}
@TestMetadata("multiFile")
public void testMultiFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/androidPersistence/multiFile/");
doTest(fileName);
}
@TestMetadata("simple")
public void testSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/androidPersistence/simple/");
doTest(fileName);
}
}
@@ -1,93 +0,0 @@
/*
* 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.testFramework.TestDataPath;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@InnerTestClasses({AndroidXml2KConversionTestGenerated.Simple.class, AndroidXml2KConversionTestGenerated.Exceptions.class})
public class AndroidXml2KConversionTestGenerated extends AbstractAndroidXml2KConversionTest {
@TestMetadata("compiler/testData/android/converter/simple")
@TestDataPath("$PROJECT_ROOT")
public static class Simple extends AbstractAndroidXml2KConversionTest {
public void testAllFilesPresentInSimple() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/android/converter/simple"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/android/converter/simple/fqNameInAttr/");
doTest(fileName);
}
@TestMetadata("fqNameInTag")
public void testFqNameInTag() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/android/converter/simple/fqNameInTag/");
doTest(fileName);
}
@TestMetadata("multiFile")
public void testMultiFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/android/converter/simple/multiFile/");
doTest(fileName);
}
@TestMetadata("noIds")
public void testNoIds() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/android/converter/simple/noIds/");
doTest(fileName);
}
@TestMetadata("singleFile")
public void testSingleFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/android/converter/simple/singleFile/");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/android/converter/exceptions")
@TestDataPath("$PROJECT_ROOT")
public static class Exceptions extends AbstractAndroidXml2KConversionTest {
public void testAllFilesPresentInExceptions() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/android/converter/exceptions"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("noManifest")
public void testNoManifest() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/android/converter/exceptions/noManifest/");
doNoManifestTest(fileName);
}
}
public static Test suite() {
TestSuite suite = new TestSuite("AndroidXml2KConversionTestGenerated");
suite.addTestSuite(Simple.class);
suite.addTestSuite(Exceptions.class);
return suite;
}
}