Extract tests-common module without any actual tests

The main reasoning for the module is to avoid running any compiler tests while executing run configuration that searches tests across module dependencies.
This commit is contained in:
Nikolay Krasko
2016-04-07 09:45:18 +03:00
parent c45bdef0c2
commit 47c7181f2a
122 changed files with 253 additions and 99 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* 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.
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.asJava;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
import junit.framework.TestCase;
import java.io.File;
import java.util.Collections;
@@ -53,12 +54,12 @@ public class JavaElementFinderTest extends KotlinAsJavaTestBase {
private void assertClass(String qualifiedName) {
PsiClass psiClass = finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject()));
assertNotNull(String.format("Class with fqn='%s' wasn't found.", qualifiedName), psiClass);
assertTrue(String.format("Class with fqn='%s' is not valid.", qualifiedName), psiClass.isValid());
TestCase.assertNotNull(String.format("Class with fqn='%s' wasn't found.", qualifiedName), psiClass);
TestCase.assertTrue(String.format("Class with fqn='%s' is not valid.", qualifiedName), psiClass.isValid());
}
private void assertNoClass(String qualifiedName) {
assertNull(String.format("Class with fqn='%s' isn't expected to be found.", qualifiedName),
finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject())));
TestCase.assertNull(String.format("Class with fqn='%s' isn't expected to be found.", qualifiedName),
finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject())));
}
}
@@ -1,66 +0,0 @@
/*
* 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.asJava
import com.intellij.openapi.util.io.FileUtil
import com.intellij.psi.PsiClass
import com.intellij.psi.impl.compiled.ClsElementImpl
import junit.framework.TestCase
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
import java.util.regex.Pattern
object LightClassTestCommon {
private val SUBJECT_FQ_NAME_PATTERN = Pattern.compile("^//\\s*(.*)$", Pattern.MULTILINE)
@JvmOverloads
fun testLightClass(
testDataFile: File,
findLightClass: (String) -> PsiClass?,
normalizeText: (String) -> String = { it }
) {
val text = FileUtil.loadFile(testDataFile, true)
val matcher = SUBJECT_FQ_NAME_PATTERN.matcher(text)
TestCase.assertTrue("No FqName specified. First line of the form '// f.q.Name' expected", matcher.find())
val fqName = matcher.group(1)
val lightClass = findLightClass(fqName)
val actual = actualText(fqName, lightClass, normalizeText)
KotlinTestUtils.assertEqualsToFile(KotlinTestUtils.replaceExtension(testDataFile, "java"), actual)
}
private fun actualText(fqName: String?, lightClass: PsiClass?, normalizeText: (String) -> String): String {
if (lightClass == null) {
return "<not generated>"
}
TestCase.assertTrue("Not a light class: $lightClass ($fqName)", lightClass is KtLightClass)
val delegate = (lightClass as KtLightClass).clsDelegate
TestCase.assertTrue("Not a CLS element: $delegate", delegate is ClsElementImpl)
val buffer = StringBuilder()
(delegate as ClsElementImpl).appendMirrorText(0, buffer)
val actual = normalizeText(buffer.toString())
return actual
}
// Actual text for light class is generated with ClsElementImpl.appendMirrorText() that can find empty DefaultImpl inner class in stubs
// for all interfaces. This inner class can't be used in Java as it generally is not seen from light classes built from Kotlin sources.
// It is also omitted during classes generation in backend so it also absent in light classes built from compiled code.
fun removeEmptyDefaultImpls(text: String) : String = text.replace("\n final class DefaultImpls {\n }\n", "")
}