Add test for KotlinBytecodeToolWindow

This commit is contained in:
Natalia Ukhorskaya
2015-04-21 15:46:38 +03:00
parent 907f0db7be
commit f936689db3
21 changed files with 254 additions and 1 deletions
@@ -73,6 +73,7 @@ import org.jetbrains.kotlin.idea.highlighter.AbstractHighlightingTest
import org.jetbrains.kotlin.idea.imports.AbstractOptimizeImportsTest
import org.jetbrains.kotlin.idea.intentions.AbstractIntentionTest
import org.jetbrains.kotlin.idea.intentions.declarations.AbstractJoinLinesTest
import org.jetbrains.kotlin.idea.internal.AbstractBytecodeToolWindowTest
import org.jetbrains.kotlin.idea.kdoc.AbstractKDocHighlightingTest
import org.jetbrains.kotlin.idea.kdoc.AbstractKDocTypingTest
import org.jetbrains.kotlin.idea.navigation.AbstractGotoSuperTest
@@ -628,6 +629,10 @@ fun main(args: Array<String>) {
model("coverage/outputFiles")
}
testClass(javaClass<AbstractBytecodeToolWindowTest>()) {
model("internal/toolWindow", recursive = false, extension = null)
}
testClass(javaClass<AbstractReferenceResolveTest>(), "org.jetbrains.kotlin.idea.kdoc.KdocResolveTestGenerated") {
model("kdoc/resolve")
}
@@ -194,8 +194,9 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
setText(DEFAULT_TEXT);
}
// public for tests
@NotNull
private static String getBytecodeForFile(
public static String getBytecodeForFile(
final JetFile jetFile,
boolean enableInline,
boolean enableAssertions,
@@ -0,0 +1,10 @@
package inlineFun1
class A<T> {
fun test() = 1
inline fun myFun1(f: () -> T): T {
test()
return f()
}
}
@@ -0,0 +1,7 @@
package foo
import inlineFun1.*
fun test() {
A<Int>().myFun1 { 1 }
}
@@ -0,0 +1,3 @@
package inlineFun1
inline fun myFun1(f: () -> Int): Int = f()
@@ -0,0 +1,7 @@
package foo
import inlineFun1.*
fun test() {
myFun1 { 1 }
}
@@ -0,0 +1,5 @@
package inlineFun1
import inlineFun2.*
inline fun myFun1(f: () -> Int): Int = myFun2 { f() }
@@ -0,0 +1,3 @@
package inlineFun2
inline fun myFun2(f: () -> Int): Int = f()
@@ -0,0 +1,7 @@
package foo
import inlineFun1.*
fun test() {
myFun1 { 1 }
}
@@ -0,0 +1,3 @@
package inlineFun1
inline fun Int.myFun1(f: () -> Int): Int = f()
@@ -0,0 +1,7 @@
package foo
import inlineFun1.*
fun test() {
1 myFun1 { 1 }
}
@@ -0,0 +1,3 @@
package inlineFun1
inline fun <reified T> myFun1(f: () -> T): T = f()
@@ -0,0 +1,9 @@
package foo
import inlineFun1.*
fun test() {
myFun1 { 1 }
}
// INLINE: false
@@ -0,0 +1,8 @@
package inlineFun1
import inlineFun2.*
import inlineFun3.*
inline fun myFun1(f: () -> Int): Int {
return myFun3 { f() } + myFun2 { f() }
}
@@ -0,0 +1,5 @@
package inlineFun2
import inlineFun3.*
inline fun myFun2(f: () -> Int): Int = myFun3 { f() }
@@ -0,0 +1,3 @@
package inlineFun3
inline fun myFun3(f: () -> Int): Int = f()
@@ -0,0 +1,7 @@
package foo
import inlineFun1.*
fun test() {
myFun1 { 1 }
}
@@ -0,0 +1,26 @@
package inlineFun1
inline fun myFun(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) f: () -> Int): Int {
val o = object {
fun test() = 1
}
o.test()
val lambda = { 1 }
lambda()
val o2 = object {
fun test() = f()
}
o2.test()
val lambda2 = { f() }
lambda2()
val ref = ::reference
ref.invoke()
return f()
}
fun reference() = 1
@@ -0,0 +1,7 @@
package foo
import inlineFun1.*
fun test() {
myFun { 1 }
}
@@ -0,0 +1,48 @@
/*
* Copyright 2010-2015 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.idea.internal
import org.jetbrains.kotlin.idea.JetFileType
import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.JetTestUtils
import java.io.File
public abstract class AbstractBytecodeToolWindowTest: JetLightCodeInsightFixtureTestCase() {
override fun getTestDataPath() = JetTestUtils.getHomeDirectory()
override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
public fun doTest(testPath: String) {
val mainDir = File(testPath)
val mainFileName = mainDir.getName() + ".kt"
mainDir.listFiles { file, name -> name != mainFileName }.forEach { myFixture.configureByFile(testPath + "/" + it.getName()) }
val mainFileText = File("$testPath/$mainFileName").readText()
myFixture.configureByText(JetFileType.INSTANCE, mainFileText)
val file = myFixture.getFile() as JetFile
val enableInline = InTextDirectivesUtils.getPrefixedBoolean(mainFileText, "// INLINE:") ?: true
val bytecodes = KotlinBytecodeToolWindow.getBytecodeForFile(file, enableInline, true, true)
assert(bytecodes.contains("// ================")) {
"The header \"// ================\" is missing.\n This means that there is an exception failed during compilation:\n$bytecodes"
}
}
}
@@ -0,0 +1,79 @@
/*
* Copyright 2010-2015 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.idea.internal;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/internal/toolWindow")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class BytecodeToolWindowTestGenerated extends AbstractBytecodeToolWindowTest {
public void testAllFilesPresentInToolWindow() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/internal/toolWindow"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("inlineFunctionBodyResolve")
public void testInlineFunctionBodyResolve() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/internal/toolWindow/inlineFunctionBodyResolve/");
doTest(fileName);
}
@TestMetadata("inlineFunctionDeep1")
public void testInlineFunctionDeep1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/internal/toolWindow/inlineFunctionDeep1/");
doTest(fileName);
}
@TestMetadata("inlineFunctionDeep2")
public void testInlineFunctionDeep2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/internal/toolWindow/inlineFunctionDeep2/");
doTest(fileName);
}
@TestMetadata("inlineFunctionInfixCall")
public void testInlineFunctionInfixCall() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/internal/toolWindow/inlineFunctionInfixCall/");
doTest(fileName);
}
@TestMetadata("inlineFunctionReifiedParam")
public void testInlineFunctionReifiedParam() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/internal/toolWindow/inlineFunctionReifiedParam/");
doTest(fileName);
}
@TestMetadata("multipleInlineFunctionCalls")
public void testMultipleInlineFunctionCalls() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/internal/toolWindow/multipleInlineFunctionCalls/");
doTest(fileName);
}
@TestMetadata("objectInInlineFun")
public void testObjectInInlineFun() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/internal/toolWindow/objectInInlineFun/");
doTest(fileName);
}
}