add test to verify output files; correctly handle lambdas
This commit is contained in:
@@ -133,6 +133,7 @@ import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithJsStdLib
|
||||
import org.jetbrains.jet.renderer.AbstractDescriptorRendererTest
|
||||
import org.jetbrains.jet.types.AbstractJetTypeBindingTest
|
||||
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentCompletionHandlerTest
|
||||
import org.jetbrains.jet.plugin.coverage.AbstractKotlinCoverageOutputFilesTest
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -638,6 +639,10 @@ fun main(args: Array<String>) {
|
||||
testClass(javaClass<AbstractSelectExpressionForDebuggerTest>()) {
|
||||
model("debugger/selectExpression")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractKotlinCoverageOutputFilesTest>()) {
|
||||
model("coverage/outputFiles")
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("idea/tests", "compiler/testData") {
|
||||
|
||||
@@ -33,6 +33,8 @@ import com.intellij.openapi.roots.ProjectRootManager
|
||||
import org.jetbrains.jet.lang.psi.JetTreeVisitorVoid
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
|
||||
import com.intellij.psi.PsiElement
|
||||
|
||||
public class KotlinCoverageExtension(): JavaCoverageEngineExtension() {
|
||||
override fun isApplicableTo(conf: RunConfigurationBase?): Boolean = conf is JetRunConfiguration
|
||||
@@ -73,7 +75,17 @@ public class KotlinCoverageExtension(): JavaCoverageEngineExtension() {
|
||||
val classNames = HashSet<String>()
|
||||
srcFile.acceptChildren(object: JetTreeVisitorVoid() {
|
||||
override fun visitDeclaration(dcl: JetDeclaration) {
|
||||
val className = JetPositionManager.getClassNameForElement(dcl.getFirstChild(), typeMapper, srcFile, false)
|
||||
super.visitDeclaration(dcl)
|
||||
collectClassName(dcl.getFirstChild())
|
||||
}
|
||||
|
||||
override fun visitFunctionLiteralExpression(expression: JetFunctionLiteralExpression) {
|
||||
super.visitFunctionLiteralExpression(expression)
|
||||
collectClassName(expression.getFunctionLiteral().getFirstChild())
|
||||
}
|
||||
|
||||
private fun collectClassName(element: PsiElement) {
|
||||
val className = JetPositionManager.getClassNameForElement(element, typeMapper, srcFile, false)
|
||||
if (className != null) {
|
||||
classNames.add(className)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
org/demo/coverage/Foo
|
||||
org/demo/coverage/Foo$bar$1
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.demo.coverage
|
||||
|
||||
public class Foo {
|
||||
public fun forEach(fn: (Any?) -> Unit): Unit {
|
||||
}
|
||||
|
||||
public fun bar() {
|
||||
forEach {
|
||||
println("foo")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.plugin.coverage
|
||||
|
||||
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import kotlin.test.assertNotNull
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
|
||||
import kotlin.test.assertEquals
|
||||
import java.io.File
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
|
||||
public abstract class AbstractKotlinCoverageOutputFilesTest(): JetLightCodeInsightFixtureTestCase() {
|
||||
private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/coverage/outputFiles"
|
||||
|
||||
override fun getTestDataPath(): String? = TEST_DATA_PATH
|
||||
|
||||
public fun doTest(path: String) {
|
||||
var kotlinFile = myFixture.configureByFile(path) as JetFile
|
||||
val actualClasses = KotlinCoverageExtension.collectOutputClassNames(kotlinFile)
|
||||
val expectedClasses = FileUtil.loadLines(path.replace(".kt", ".expected.txt"))
|
||||
UsefulTestCase.assertSameElements(actualClasses, expectedClasses)
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.plugin.coverage;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
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("idea/testData/coverage/outputFiles")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KotlinCoverageOutputFilesTestGenerated extends AbstractKotlinCoverageOutputFilesTest {
|
||||
public void testAllFilesPresentInOutputFiles() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/coverage/outputFiles"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("lambda.kt")
|
||||
public void testLambda() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/coverage/outputFiles/lambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user