Test: convert IR source ranges test to the new infrastructure
Related to KT-59864, KT-60111, KT-59584
This commit is contained in:
committed by
Space Team
parent
dab06c0942
commit
072757cdde
+1
-1
@@ -1,4 +1,4 @@
|
||||
@0:0..33:1 FILE fqName:<root> fileName:/comments.kt
|
||||
@0:0..34:0 FILE fqName:<root> fileName:/comments.kt
|
||||
@1:0..33:1 CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
@1:0..33:1 CONSTRUCTOR visibility:public <> () returnType:<root>.Foo [primary]
|
||||
@1:0..33:1 BLOCK_BODY
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@0:0..23:1 FILE fqName:test fileName:/classFuns.kt
|
||||
@0:0..24:0 FILE fqName:test fileName:/classFuns.kt
|
||||
@3:0..23:1 CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
@3:0..23:1 CONSTRUCTOR visibility:public <> () returnType:test.Test [primary]
|
||||
@3:0..23:1 BLOCK_BODY
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@0:0..77:1 FILE fqName:test fileName:/classProperties.kt
|
||||
@0:0..78:0 FILE fqName:test fileName:/classProperties.kt
|
||||
@2:0..77:1 CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
@2:0..77:1 CONSTRUCTOR visibility:public <> () returnType:test.Test [primary]
|
||||
@2:0..77:1 BLOCK_BODY
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@0:0..22:11 FILE fqName:<root> fileName:/classes.kt
|
||||
@0:0..23:0 FILE fqName:<root> fileName:/classes.kt
|
||||
@0:0..11 CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
@0:0..11 CONSTRUCTOR visibility:public <> () returnType:<root>.Test1 [primary]
|
||||
@0:0..11 BLOCK_BODY
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@0:0..10 FILE fqName:<root> fileName:/fakeOverrides.kt
|
||||
@0:0..1:0 FILE fqName:<root> fileName:/fakeOverrides.kt
|
||||
@0:0..10 CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
@0:0..10 CONSTRUCTOR visibility:public <> () returnType:<root>.Test [primary]
|
||||
@0:0..10 BLOCK_BODY
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@0:0..13:23 FILE fqName:<root> fileName:/primaryConstructors.kt
|
||||
@0:0..14:0 FILE fqName:<root> fileName:/primaryConstructors.kt
|
||||
@0:0..23 CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
@0:0..23 CONSTRUCTOR visibility:public <> (x:kotlin.Int) returnType:<root>.Test1 [primary]
|
||||
@0:12..22 VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@0:0..13:1 FILE fqName:<root> fileName:/secondaryConstructors.kt
|
||||
@0:0..14:0 FILE fqName:<root> fileName:/secondaryConstructors.kt
|
||||
@0:0..13:1 CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
@1:4..27 CONSTRUCTOR visibility:public <> () returnType:<root>.C
|
||||
@1:4..27 BLOCK_BODY
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
@0:0..4:1 FILE fqName:<root> fileName:/synthesizedDataClassMembers.kt
|
||||
@0:0..5:0 FILE fqName:<root> fileName:/synthesizedDataClassMembers.kt
|
||||
@0:0..4:1 CLASS CLASS name:C modality:FINAL visibility:public [data] superTypes:[kotlin.Any]
|
||||
@0:5..4:1 CONSTRUCTOR visibility:public <> (x:kotlin.Int, y:kotlin.String, z:kotlin.Any) returnType:<root>.C [primary]
|
||||
@1:8..18 VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@0:0..19:14 FILE fqName:test fileName:/topLevelFuns.kt
|
||||
@0:0..20:0 FILE fqName:test fileName:/topLevelFuns.kt
|
||||
@3:0..14 FUN name:test0 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
@3:12..14 BLOCK_BODY
|
||||
@9:0..14 FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@0:0..68:32 FILE fqName:test fileName:/topLevelProperties.kt
|
||||
@0:0..69:0 FILE fqName:test fileName:/topLevelProperties.kt
|
||||
@3:0..14 PROPERTY name:test0 visibility:public modality:FINAL [val]
|
||||
@3:0..14 FIELD PROPERTY_BACKING_FIELD name:test0 type:kotlin.Int visibility:private [final,static]
|
||||
@3:12..14 EXPRESSION_BODY
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
@0:0..26:1 FILE fqName:<root> fileName:/kt17108.kt
|
||||
@0:0..27:0 FILE fqName:<root> fileName:/kt17108.kt
|
||||
@4:0..26:1 CLASS INTERFACE name:Boolean modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
|
||||
@8:20..38 FUN name:not visibility:public modality:ABSTRACT <> ($this:<root>.Boolean) returnType:<root>.Boolean [operator]
|
||||
@8:4..38 VALUE_PARAMETER name:<this> type:<root>.Boolean
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
@3:0..53 PROPERTY name:lazyNullString visibility:public modality:FINAL [delegated,val]
|
||||
@3:27..53 FIELD PROPERTY_DELEGATE name:lazyNullString$delegate type:kotlin.Lazy<@[FlexibleNullability] kotlin.String?> visibility:private [final,static]
|
||||
@3:30..53 EXPRESSION_BODY
|
||||
@3:30..53 CALL 'public final fun lazy <T> (initializer: kotlin.Function0<T of kotlin.lazy>): kotlin.Lazy<T of kotlin.lazy> declared in kotlin' type=kotlin.Lazy<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
@3:30..53 CALL 'public final fun lazy <T> (initializer: kotlin.Function0<T of kotlin.LazyKt.lazy>): kotlin.Lazy<T of kotlin.LazyKt.lazy> declared in kotlin.LazyKt' type=kotlin.Lazy<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
@3:35..53 FUN_EXPR type=kotlin.Function0<@[FlexibleNullability] kotlin.String?> origin=LAMBDA
|
||||
@3:35..53 FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:@[FlexibleNullability] kotlin.String?
|
||||
@3:37..51 BLOCK_BODY
|
||||
@@ -12,7 +12,7 @@
|
||||
@3:30..53 BLOCK_BODY
|
||||
@3:30..53 RETURN type=kotlin.Nothing from='public final fun <get-lazyNullString> (): kotlin.String declared in <root>'
|
||||
@3:30..53 TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
|
||||
@3:30..53 CALL 'public final fun getValue <T> (thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): T of kotlin.getValue [inline,operator] declared in kotlin' type=@[FlexibleNullability] kotlin.String? origin=null
|
||||
@3:30..53 CALL 'public final fun getValue <T> (thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): T of kotlin.LazyKt.getValue [inline,operator] declared in kotlin.LazyKt' type=@[FlexibleNullability] kotlin.String? origin=null
|
||||
@3:27..53 GET_FIELD 'FIELD PROPERTY_DELEGATE name:lazyNullString$delegate type:kotlin.Lazy<@[FlexibleNullability] kotlin.String?> visibility:private [final,static]' type=kotlin.Lazy<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
@-1:-1..-1 CONST Null type=kotlin.Nothing? value=null
|
||||
@3:27..53 PROPERTY_REFERENCE 'public final lazyNullString: kotlin.String [delegated,val]' field=null getter='public final fun <get-lazyNullString> (): kotlin.String declared in <root>' setter=null type=kotlin.reflect.KProperty0<kotlin.String> origin=PROPERTY_REFERENCE_FOR_DELEGATE
|
||||
|
||||
+28
-18
@@ -3,14 +3,14 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir;
|
||||
package org.jetbrains.kotlin.test.runners.ir;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -19,108 +19,118 @@ import java.util.regex.Pattern;
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/ir/sourceRanges")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class IrSourceRangesTestCaseGenerated extends AbstractIrSourceRangesTestCase {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public class ClassicJvmIrSourceRangesTestGenerated extends AbstractClassicJvmIrSourceRangesTest {
|
||||
@Test
|
||||
public void testAllFilesPresentInSourceRanges() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/sourceRanges"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/sourceRanges"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotations.kt")
|
||||
public void testAnnotations() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/annotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("augmentedAssignmentWithExpression.kt")
|
||||
public void testAugmentedAssignmentWithExpression() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/augmentedAssignmentWithExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("comments.kt")
|
||||
public void testComments() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/comments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("elvis.kt")
|
||||
public void testElvis() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/elvis.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt17108.kt")
|
||||
public void testKt17108() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/kt17108.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt24258.kt")
|
||||
public void testKt24258() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/kt24258.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("postfixIncrementDecrement.kt")
|
||||
public void testPostfixIncrementDecrement() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/postfixIncrementDecrement.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/ir/sourceRanges/declarations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Declarations extends AbstractIrSourceRangesTestCase {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public class Declarations {
|
||||
@Test
|
||||
public void testAllFilesPresentInDeclarations() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/sourceRanges/declarations"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/sourceRanges/declarations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("classFuns.kt")
|
||||
public void testClassFuns() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/classFuns.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("classProperties.kt")
|
||||
public void testClassProperties() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/classProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("classes.kt")
|
||||
public void testClasses() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/classes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("fakeOverrides.kt")
|
||||
public void testFakeOverrides() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/fakeOverrides.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt29862.kt")
|
||||
public void testKt29862() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/kt29862.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primaryConstructors.kt")
|
||||
public void testPrimaryConstructors() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/primaryConstructors.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("secondaryConstructors.kt")
|
||||
public void testSecondaryConstructors() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/secondaryConstructors.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synthesizedDataClassMembers.kt")
|
||||
public void testSynthesizedDataClassMembers() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/synthesizedDataClassMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelFuns.kt")
|
||||
public void testTopLevelFuns() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/topLevelFuns.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelProperties.kt")
|
||||
public void testTopLevelProperties() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/declarations/topLevelProperties.kt");
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test.backend.handlers
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.SourceRangeInfo
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
|
||||
import org.jetbrains.kotlin.ir.util.RenderIrElementVisitor
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.model.BackendKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||
import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumper
|
||||
import org.jetbrains.kotlin.test.utils.withExtension
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.File
|
||||
|
||||
class IrSourceRangesDumpHandler(
|
||||
testServices: TestServices,
|
||||
artifactKind: BackendKind<IrBackendInput>,
|
||||
) : AbstractIrHandler(testServices, artifactKind) {
|
||||
companion object {
|
||||
const val DUMP_EXTENSION = "txt"
|
||||
}
|
||||
|
||||
override val directiveContainers: List<DirectivesContainer>
|
||||
get() = listOf(CodegenTestDirectives, FirDiagnosticsDirectives)
|
||||
|
||||
private val baseDumper = MultiModuleInfoDumper()
|
||||
private val buildersForSeparateFileDumps: MutableMap<File, StringBuilder> = mutableMapOf()
|
||||
|
||||
override fun processModule(module: TestModule, info: IrBackendInput) {
|
||||
if (CodegenTestDirectives.DUMP_SOURCE_RANGES_IR !in module.directives) return
|
||||
info.processAllIrModuleFragments(module) { irModuleFragment, moduleName ->
|
||||
val builder = baseDumper.builderForModule(moduleName)
|
||||
|
||||
for (irFile in irModuleFragment.files) {
|
||||
builder.append(irFile.dumpWithSourceLocations(irFile.fileEntry))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrElement.dumpWithSourceLocations(fileEntry: IrFileEntry): String =
|
||||
StringBuilder().also {
|
||||
acceptVoid(DumpSourceLocations(it, fileEntry))
|
||||
}.toString()
|
||||
|
||||
private class DumpSourceLocations(
|
||||
out: Appendable,
|
||||
val fileEntry: IrFileEntry
|
||||
) : IrElementVisitorVoid {
|
||||
val printer = Printer(out, " ")
|
||||
val elementRenderer = RenderIrElementVisitor()
|
||||
|
||||
private fun printElement(element: IrElement) {
|
||||
val sourceRangeInfo = fileEntry.getSourceRangeInfo(element.startOffset, element.endOffset)
|
||||
printer.println("@${sourceRangeInfo.render()} ${element.accept(elementRenderer, null)}")
|
||||
}
|
||||
|
||||
override fun visitElement(element: IrElement) {
|
||||
printElement(element)
|
||||
printer.pushIndent()
|
||||
if (element is IrAnnotationContainer && element.annotations.isNotEmpty()) {
|
||||
printer.println("annotations:")
|
||||
printer.pushIndent()
|
||||
for (annotation in element.annotations) {
|
||||
printElement(annotation)
|
||||
printer.pushIndent()
|
||||
annotation.acceptChildrenVoid(this)
|
||||
printer.popIndent()
|
||||
}
|
||||
printer.popIndent()
|
||||
}
|
||||
element.acceptChildrenVoid(this)
|
||||
printer.popIndent()
|
||||
}
|
||||
|
||||
private fun SourceRangeInfo.render() =
|
||||
if (startLineNumber == endLineNumber)
|
||||
"$startLineNumber:$startColumnNumber..$endColumnNumber"
|
||||
else
|
||||
"$startLineNumber:$startColumnNumber..$endLineNumber:$endColumnNumber"
|
||||
}
|
||||
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
val moduleStructure = testServices.moduleStructure
|
||||
val defaultExpectedFile = moduleStructure.originalTestDataFiles.first()
|
||||
.withExtension(moduleStructure.modules.first().getDumpExtension())
|
||||
checkOneExpectedFile(defaultExpectedFile, baseDumper.generateResultingDump())
|
||||
buildersForSeparateFileDumps.entries.forEach { (expectedFile, dump) -> checkOneExpectedFile(expectedFile, dump.toString()) }
|
||||
}
|
||||
|
||||
private fun checkOneExpectedFile(expectedFile: File, actualDump: String) {
|
||||
if (actualDump.isNotEmpty()) {
|
||||
assertions.assertEqualsToFile(expectedFile, actualDump)
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestModule.getDumpExtension(ignoreFirIdentical: Boolean = false): String {
|
||||
return IrTextDumpHandler.computeDumpExtension(this, DUMP_EXTENSION, ignoreFirIdentical)
|
||||
}
|
||||
}
|
||||
+4
@@ -147,6 +147,10 @@ object CodegenTestDirectives : SimpleDirectivesContainer() {
|
||||
description = "Dumps generated backend IR in pretty kotlin dump (enables ${IrPrettyKotlinDumpHandler::class})"
|
||||
)
|
||||
|
||||
val DUMP_SOURCE_RANGES_IR by directive(
|
||||
description = "Dumps generated backend IR together with elements source ranges (enables ${IrSourceRangesDumpHandler::class})"
|
||||
)
|
||||
|
||||
val SKIP_KT_DUMP by directive(
|
||||
description = "Skips check pretty kt IR dump (disables ${IrPrettyKotlinDumpHandler::class})"
|
||||
)
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test.runners.ir
|
||||
|
||||
import org.jetbrains.kotlin.test.Constructor
|
||||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_KT_IR
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_SIGNATURES
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_SOURCE_RANGES_IR
|
||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter
|
||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade
|
||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact
|
||||
import org.jetbrains.kotlin.test.model.*
|
||||
|
||||
abstract class AbstractJvmIrSourceRangesTest<FrontendOutput : ResultingArtifact.FrontendOutput<FrontendOutput>> :
|
||||
AbstractJvmIrTextTest<FrontendOutput>() {
|
||||
|
||||
override fun configure(builder: TestConfigurationBuilder) {
|
||||
super.configure(builder)
|
||||
with(builder) {
|
||||
defaultDirectives {
|
||||
+DUMP_SOURCE_RANGES_IR
|
||||
-DUMP_KT_IR
|
||||
-DUMP_IR
|
||||
-DUMP_SIGNATURES
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class AbstractClassicJvmIrSourceRangesTest : AbstractJvmIrSourceRangesTest<ClassicFrontendOutputArtifact>() {
|
||||
|
||||
override val frontend: FrontendKind<*>
|
||||
get() = FrontendKinds.ClassicFrontend
|
||||
|
||||
override val frontendFacade: Constructor<FrontendFacade<ClassicFrontendOutputArtifact>>
|
||||
get() = ::ClassicFrontendFacade
|
||||
|
||||
override val converter: Constructor<Frontend2BackendConverter<ClassicFrontendOutputArtifact, IrBackendInput>>
|
||||
get() = ::ClassicFrontend2IrConverter
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.ir
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
|
||||
import org.jetbrains.kotlin.ir.util.RenderIrElementVisitor
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractIrSourceRangesTestCase : AbstractIrGeneratorTestCase() {
|
||||
override fun doTest(wholeFile: File, testFiles: List<TestFile>) {
|
||||
val dir = wholeFile.parentFile
|
||||
val testFileToIrFile = generateIrFilesAsSingleModule(testFiles)
|
||||
for ((testFile, irFile) in testFileToIrFile) {
|
||||
val irFileDump = irFile.dumpWithSourceLocations(irFile.fileEntry)
|
||||
val expectedSourceLocations = File(dir, testFile.name.replace(".kt", ".txt"))
|
||||
KotlinTestUtils.assertEqualsToFile(expectedSourceLocations, irFileDump)
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrElement.dumpWithSourceLocations(fileEntry: IrFileEntry): String =
|
||||
StringBuilder().also {
|
||||
acceptVoid(DumpSourceLocations(it, fileEntry))
|
||||
}.toString()
|
||||
|
||||
private class DumpSourceLocations(
|
||||
out: Appendable,
|
||||
val fileEntry: IrFileEntry
|
||||
) : IrElementVisitorVoid {
|
||||
val printer = Printer(out, " ")
|
||||
val elementRenderer = RenderIrElementVisitor()
|
||||
|
||||
private fun printElement(element: IrElement) {
|
||||
val sourceRangeInfo = fileEntry.getSourceRangeInfo(element.startOffset, element.endOffset)
|
||||
printer.println("@${sourceRangeInfo.render()} ${element.accept(elementRenderer, null)}")
|
||||
}
|
||||
|
||||
override fun visitElement(element: IrElement) {
|
||||
printElement(element)
|
||||
printer.pushIndent()
|
||||
if (element is IrAnnotationContainer && element.annotations.isNotEmpty()) {
|
||||
printer.println("annotations:")
|
||||
printer.pushIndent()
|
||||
for (annotation in element.annotations) {
|
||||
printElement(annotation)
|
||||
printer.pushIndent()
|
||||
annotation.acceptChildrenVoid(this)
|
||||
printer.popIndent()
|
||||
}
|
||||
printer.popIndent()
|
||||
}
|
||||
element.acceptChildrenVoid(this)
|
||||
printer.popIndent()
|
||||
}
|
||||
|
||||
private fun SourceRangeInfo.render() =
|
||||
if (startLineNumber == endLineNumber)
|
||||
"$startLineNumber:$startColumnNumber..$endColumnNumber"
|
||||
else
|
||||
"$startLineNumber:$startColumnNumber..$endLineNumber:$endColumnNumber"
|
||||
}
|
||||
}
|
||||
-5
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.generators.util.TestGeneratorUtil
|
||||
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
||||
import org.jetbrains.kotlin.integration.AbstractAntTaskTest
|
||||
import org.jetbrains.kotlin.ir.AbstractIrCfgTestCase
|
||||
import org.jetbrains.kotlin.ir.AbstractIrSourceRangesTestCase
|
||||
import org.jetbrains.kotlin.jvm.compiler.*
|
||||
import org.jetbrains.kotlin.jvm.compiler.ir.AbstractIrCompileJavaAgainstKotlinTest
|
||||
import org.jetbrains.kotlin.jvm.compiler.ir.AbstractIrCompileKotlinAgainstJavaTest
|
||||
@@ -115,10 +114,6 @@ fun generateJUnit3CompilerTests(args: Array<String>, mainClassName: String?) {
|
||||
model("ir/irCfg")
|
||||
}
|
||||
|
||||
testClass<AbstractIrSourceRangesTestCase> {
|
||||
model("ir/sourceRanges")
|
||||
}
|
||||
|
||||
testClass<AbstractTopLevelMembersInvocationTest> {
|
||||
model("codegen/topLevelMemberInvocation", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
+4
@@ -123,6 +123,10 @@ fun generateJUnit5CompilerTests(args: Array<String>, mainClassName: String?) {
|
||||
model("ir/irText")
|
||||
}
|
||||
|
||||
testClass<AbstractClassicJvmIrSourceRangesTest> {
|
||||
model("ir/sourceRanges")
|
||||
}
|
||||
|
||||
testClass<AbstractBytecodeTextTest> {
|
||||
model("codegen/bytecodeText")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user