[TEST] Introduce test-infrastructure-utils module and extract common test utilities here
This commit is contained in:
@@ -48,6 +48,7 @@ dependencies {
|
||||
testCompile(project(":kotlin-test:kotlin-test-jvm"))
|
||||
testCompile(projectTests(":compiler:tests-common-jvm6"))
|
||||
testCompile(project(":kotlin-scripting-compiler-impl"))
|
||||
testCompile(projectTests(":compiler:test-infrastructure-utils"))
|
||||
testCompile(commonDep("junit:junit"))
|
||||
testCompile(androidDxJar()) { isTransitive = false }
|
||||
testCompile(commonDep("com.android.tools:r8"))
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 com.intellij.testFramework;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks the annotated parameter as referencing a file in the testdata directory.
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target({ElementType.PARAMETER})
|
||||
public @interface TestDataFile {
|
||||
}
|
||||
@@ -1,33 +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 com.intellij.testFramework;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Specifies the path to testdata for the current test case class.
|
||||
* May use the variable $CONTENT_ROOT to specify the module content root or
|
||||
* $PROJECT_ROOT to use the project base directory.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface TestDataPath {
|
||||
String value();
|
||||
}
|
||||
+2
-2
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTestWithStdLib
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.getHomeDirectory
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil.getHomeDirectory
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractDiagnosticsTestWithStdLibUsingJavac : AbstractDiagnosticsTestWithStdLib() {
|
||||
@@ -45,4 +45,4 @@ abstract class AbstractDiagnosticsTestWithStdLibUsingJavac : AbstractDiagnostics
|
||||
|
||||
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,14 +18,14 @@ package org.jetbrains.kotlin.checkers
|
||||
|
||||
import org.jetbrains.kotlin.codegen.CodegenTestUtil
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractForeignAnnotationsNoAnnotationInClasspathTest : AbstractForeignAnnotationsTest() {
|
||||
// This should be executed after setUp runs, since setUp changes the root folder
|
||||
// for temporary files.
|
||||
private val compiledJavaPath by lazy {
|
||||
KotlinTestUtils.tmpDir("java-compiled-files")
|
||||
KtTestUtil.tmpDir("java-compiled-files")
|
||||
}
|
||||
|
||||
override fun getExtraClasspath(): List<File> {
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactoryImpl
|
||||
import org.jetbrains.kotlin.test.Directives
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils.isDirectiveDefined
|
||||
import org.jetbrains.kotlin.test.KotlinBaseTest
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
@@ -118,12 +118,24 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
|
||||
if (includeExtras) {
|
||||
if (declareFlexibleType) {
|
||||
ktFiles.add(KotlinTestUtils.createFile("EXPLICIT_FLEXIBLE_TYPES.kt", EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS, project))
|
||||
ktFiles.add(
|
||||
KtTestUtil.createFile(
|
||||
"EXPLICIT_FLEXIBLE_TYPES.kt",
|
||||
EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS,
|
||||
project
|
||||
)
|
||||
)
|
||||
}
|
||||
if (declareCheckType) {
|
||||
val checkTypeDeclarations = File("$HELPERS_PATH/types/checkType.kt").readText()
|
||||
|
||||
ktFiles.add(KotlinTestUtils.createFile("CHECK_TYPE.kt", checkTypeDeclarations, project))
|
||||
ktFiles.add(
|
||||
KtTestUtil.createFile(
|
||||
"CHECK_TYPE.kt",
|
||||
checkTypeDeclarations,
|
||||
project
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.tests.di.createContainerForTests
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
@@ -106,14 +107,14 @@ class CheckerTestUtilTest : KotlinTestWithEnvironment() {
|
||||
DiagnosticData(7, 6, "TOO_MANY_ARGUMENTS", 164, 166)
|
||||
)
|
||||
|
||||
private fun getTestDataPath() = KotlinTestUtils.getTestDataPathBase() + "/diagnostics/checkerTestUtil"
|
||||
private fun getTestDataPath() = KtTestUtil.getTestDataPathBase() + "/diagnostics/checkerTestUtil"
|
||||
|
||||
override fun createEnvironment() = createEnvironmentWithMockJdk(ConfigurationKind.ALL)
|
||||
|
||||
private fun doTest(test: Test) = test.test(
|
||||
TestCheckerUtil.createCheckAndReturnPsiFile(
|
||||
"test.kt",
|
||||
KotlinTestUtils.doLoadFile(getTestDataPath(), "test.kt"),
|
||||
KtTestUtil.doLoadFile(getTestDataPath(), "test.kt"),
|
||||
project
|
||||
),
|
||||
environment
|
||||
|
||||
+10
-6
@@ -13,8 +13,12 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
||||
import org.jetbrains.kotlin.script.loadScriptingPlugin
|
||||
import org.jetbrains.kotlin.test.*
|
||||
import org.jetbrains.kotlin.test.Directives
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinBaseTest
|
||||
import org.jetbrains.kotlin.test.TestFiles
|
||||
import org.jetbrains.kotlin.test.TestFiles.TestFileFactory
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
@@ -27,9 +31,9 @@ abstract class KotlinMultiFileTestWithJava<M : KotlinBaseTest.TestModule, F : Ko
|
||||
public override fun setUp() {
|
||||
super.setUp()
|
||||
// TODO: do not create temporary directory for tests without Java sources
|
||||
javaFilesDir = KotlinTestUtils.tmpDir("java-files")
|
||||
javaFilesDir = KtTestUtil.tmpDir("java-files")
|
||||
if (isKotlinSourceRootNeeded()) {
|
||||
kotlinSourceRoot = KotlinTestUtils.tmpDir("kotlin-src")
|
||||
kotlinSourceRoot = KtTestUtil.tmpDir("kotlin-src")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +83,7 @@ abstract class KotlinMultiFileTestWithJava<M : KotlinBaseTest.TestModule, F : Ko
|
||||
|
||||
private fun getClasspath(file: File): List<File> {
|
||||
val result: MutableList<File> = ArrayList()
|
||||
result.add(KotlinTestUtils.getAnnotationsJar())
|
||||
result.add(KtTestUtil.getAnnotationsJar())
|
||||
result.addAll(getExtraClasspath())
|
||||
val fileText = file.readText(Charsets.UTF_8)
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "ANDROID_ANNOTATIONS")) {
|
||||
@@ -104,7 +108,7 @@ abstract class KotlinMultiFileTestWithJava<M : KotlinBaseTest.TestModule, F : Ko
|
||||
@Throws(Exception::class)
|
||||
public override fun doTest(filePath: String) {
|
||||
val file = createTestFileFromPath(filePath)
|
||||
val expectedText = KotlinTestUtils.doLoadFile(file)
|
||||
val expectedText = KtTestUtil.doLoadFile(file)
|
||||
//TODO: move to proper tests
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(expectedText, "// SKIP_JAVAC")) return
|
||||
super.doTest(file.path)
|
||||
@@ -144,7 +148,7 @@ abstract class KotlinMultiFileTestWithJava<M : KotlinBaseTest.TestModule, F : Ko
|
||||
|
||||
private fun writeSourceFile(fileName: String, content: String, targetDir: File) {
|
||||
val tmpFile = File(targetDir, fileName)
|
||||
KotlinTestUtils.mkdirs(tmpFile.parentFile)
|
||||
KtTestUtil.mkdirs(tmpFile.parentFile)
|
||||
tmpFile.writeText(content, Charsets.UTF_8)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -25,13 +25,13 @@ import com.intellij.testFramework.LightVirtualFile;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
|
||||
|
||||
public class TestCheckerUtil {
|
||||
@NotNull
|
||||
public static KtFile createCheckAndReturnPsiFile(@NotNull String fileName, @NotNull String text, @NotNull Project project) {
|
||||
KtFile myFile = KotlinTestUtils.createFile(fileName, text, project);
|
||||
KtFile myFile = KtTestUtil.createFile(fileName, text, project);
|
||||
ensureParsed(myFile);
|
||||
TestCase.assertEquals("light virtual file text mismatch", text, ((LightVirtualFile) myFile.getVirtualFile()).getContent().toString());
|
||||
TestCase.assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(myFile.getVirtualFile()));
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.getHomeDirectory
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil.getHomeDirectory
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractDiagnosticsUsingJavacTest : AbstractDiagnosticsTest() {
|
||||
@@ -43,4 +43,4 @@ abstract class AbstractDiagnosticsUsingJavacTest : AbstractDiagnosticsTest() {
|
||||
|
||||
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.checkers.javac
|
||||
import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractJavacDiagnosticsTest : AbstractDiagnosticsTest() {
|
||||
@@ -52,7 +52,8 @@ abstract class AbstractJavacDiagnosticsTest : AbstractDiagnosticsTest() {
|
||||
return super.createTestFiles(file, expectedText, modules)
|
||||
}
|
||||
|
||||
return super.createTestFiles(specialFile, KotlinTestUtils.doLoadFile(specialFile), modules)
|
||||
return super.createTestFiles(specialFile,
|
||||
KtTestUtil.doLoadFile(specialFile), modules)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.test.CompilerTestUtil;
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.kotlin.utils.JsMetadataVersion;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
@@ -263,7 +264,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
new File(AbstractForeignAnnotationsTestKt.getFOREIGN_ANNOTATIONS_SOURCES_PATH()).getPath()
|
||||
).replace(
|
||||
"$JDK_15$",
|
||||
KotlinTestUtils.getJdk15Home().getPath()
|
||||
KtTestUtil.getJdk15Home().getPath()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.codeMetaInfo
|
||||
|
||||
import org.jetbrains.kotlin.codeMetaInfo.model.ParsedCodeMetaInfo
|
||||
|
||||
object CodeMetaInfoParser {
|
||||
val openingRegex = """(<!([^"]*?((".*?")(, ".*?")*?)?[^"]*?)!>)""".toRegex()
|
||||
val closingRegex = """(<!>)""".toRegex()
|
||||
|
||||
val openingOrClosingRegex = """(${closingRegex.pattern}|${openingRegex.pattern})""".toRegex()
|
||||
|
||||
/*
|
||||
* ([\S&&[^,(){}]]+) -- tag, allowing all non-space characters except bracers and curly bracers
|
||||
* ([{](.*?)[}])? -- list of platforms
|
||||
* (\("(.*?)"\))? -- arguments of meta info
|
||||
* (, )? -- possible separator between different infos
|
||||
*/
|
||||
private val tagRegex = """([\S&&[^,(){}]]+)([{](.*?)[}])?(\("(.*?)"\))?(, )?""".toRegex()
|
||||
|
||||
fun getCodeMetaInfoFromText(renderedText: String): List<ParsedCodeMetaInfo> {
|
||||
var text = renderedText
|
||||
val openingMatchResults = ArrayDeque<MatchResult>()
|
||||
val stackOfOpeningMatchResults = ArrayDeque<MatchResult>()
|
||||
val closingMatchResults = mutableMapOf<MatchResult, MatchResult>()
|
||||
val result = mutableListOf<ParsedCodeMetaInfo>()
|
||||
|
||||
while (true) {
|
||||
var openingStartOffset = Int.MAX_VALUE
|
||||
var closingStartOffset = Int.MAX_VALUE
|
||||
val opening = openingRegex.find(text)
|
||||
val closing = closingRegex.find(text)
|
||||
if (opening == null && closing == null) break
|
||||
|
||||
if (opening != null)
|
||||
openingStartOffset = opening.range.first
|
||||
if (closing != null)
|
||||
closingStartOffset = closing.range.first
|
||||
|
||||
text = if (openingStartOffset < closingStartOffset) {
|
||||
requireNotNull(opening)
|
||||
openingMatchResults.addLast(opening)
|
||||
stackOfOpeningMatchResults.addLast(opening)
|
||||
text.removeRange(openingStartOffset, opening.range.last + 1)
|
||||
} else {
|
||||
requireNotNull(closing)
|
||||
closingMatchResults[stackOfOpeningMatchResults.removeLast()] = closing
|
||||
text.removeRange(closingStartOffset, closing.range.last + 1)
|
||||
}
|
||||
}
|
||||
if (openingMatchResults.size != closingMatchResults.size) {
|
||||
error("Opening and closing tags counts are not equals")
|
||||
}
|
||||
while (!openingMatchResults.isEmpty()) {
|
||||
val openingMatchResult = openingMatchResults.removeLast()
|
||||
val closingMatchResult = closingMatchResults.getValue(openingMatchResult)
|
||||
val allMetaInfos = openingMatchResult.groups[2]!!.value
|
||||
tagRegex.findAll(allMetaInfos).map { it.groups }.forEach {
|
||||
val tag = it[1]!!.value
|
||||
val platforms = it[3]?.value?.split(";") ?: emptyList()
|
||||
val description = it[5]?.value
|
||||
|
||||
result.add(
|
||||
ParsedCodeMetaInfo(
|
||||
openingMatchResult.range.first,
|
||||
closingMatchResult.range.first,
|
||||
platforms.toMutableList(),
|
||||
tag,
|
||||
description
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.codeMetaInfo
|
||||
|
||||
import com.intellij.util.containers.Stack
|
||||
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
|
||||
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
|
||||
import java.io.File
|
||||
import java.lang.StringBuilder
|
||||
|
||||
object CodeMetaInfoRenderer {
|
||||
fun renderTagsToText(
|
||||
codeMetaInfos: List<CodeMetaInfo>,
|
||||
originalText: String
|
||||
): StringBuilder {
|
||||
return StringBuilder().apply {
|
||||
renderTagsToText(this, codeMetaInfos, originalText)
|
||||
}
|
||||
}
|
||||
|
||||
fun renderTagsToText(
|
||||
builder: StringBuilder,
|
||||
codeMetaInfos: List<CodeMetaInfo>,
|
||||
originalText: String
|
||||
) {
|
||||
if (codeMetaInfos.isEmpty()) {
|
||||
builder.append(originalText)
|
||||
return
|
||||
}
|
||||
val sortedMetaInfos = getSortedCodeMetaInfos(codeMetaInfos).groupBy { it.start }
|
||||
val opened = Stack<CodeMetaInfo>()
|
||||
|
||||
for ((i, c) in originalText.withIndex()) {
|
||||
processMetaInfosStartedAtOffset(i, sortedMetaInfos, opened, builder)
|
||||
builder.append(c)
|
||||
}
|
||||
val lastSymbolIsNewLine = builder.last() == '\n'
|
||||
if (lastSymbolIsNewLine) {
|
||||
builder.deleteCharAt(builder.length - 1)
|
||||
}
|
||||
processMetaInfosStartedAtOffset(originalText.length, sortedMetaInfos, opened, builder)
|
||||
if (lastSymbolIsNewLine) {
|
||||
builder.appendLine()
|
||||
}
|
||||
}
|
||||
|
||||
private fun processMetaInfosStartedAtOffset(
|
||||
offset: Int,
|
||||
sortedMetaInfos: Map<Int, List<CodeMetaInfo>>,
|
||||
opened: Stack<CodeMetaInfo>,
|
||||
builder: StringBuilder
|
||||
) {
|
||||
checkOpenedAndCloseStringIfNeeded(opened, offset, builder)
|
||||
val matchedCodeMetaInfos = sortedMetaInfos[offset] ?: emptyList()
|
||||
if (matchedCodeMetaInfos.isNotEmpty()) {
|
||||
openStartTag(builder)
|
||||
val iterator = matchedCodeMetaInfos.listIterator()
|
||||
var current: CodeMetaInfo? = iterator.next()
|
||||
|
||||
while (current != null) {
|
||||
val next: CodeMetaInfo? = if (iterator.hasNext()) iterator.next() else null
|
||||
opened.push(current)
|
||||
builder.append(current.asString())
|
||||
when {
|
||||
next == null ->
|
||||
closeStartTag(builder)
|
||||
next.end == current.end ->
|
||||
builder.append(", ")
|
||||
else ->
|
||||
closeStartAndOpenNewTag(builder)
|
||||
}
|
||||
current = next
|
||||
}
|
||||
}
|
||||
// Here we need to handle meta infos which has start == end and close them immediately
|
||||
checkOpenedAndCloseStringIfNeeded(opened, offset, builder)
|
||||
}
|
||||
|
||||
private val metaInfoComparator = (compareBy<CodeMetaInfo> { it.start } then compareByDescending { it.end }) then compareBy { it.tag }
|
||||
|
||||
private fun getSortedCodeMetaInfos(metaInfos: Collection<CodeMetaInfo>): List<CodeMetaInfo> {
|
||||
return metaInfos.sortedWith(metaInfoComparator)
|
||||
}
|
||||
|
||||
private fun closeString(result: StringBuilder) = result.append("<!>")
|
||||
private fun openStartTag(result: StringBuilder) = result.append("<!")
|
||||
private fun closeStartTag(result: StringBuilder) = result.append("!>")
|
||||
private fun closeStartAndOpenNewTag(result: StringBuilder) = result.append("!><!")
|
||||
|
||||
private fun checkOpenedAndCloseStringIfNeeded(opened: Stack<CodeMetaInfo>, end: Int, result: StringBuilder) {
|
||||
var prev: CodeMetaInfo? = null
|
||||
while (!opened.isEmpty() && end == opened.peek().end) {
|
||||
if (prev == null || prev.start != opened.peek().start)
|
||||
closeString(result)
|
||||
prev = opened.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun clearFileFromDiagnosticMarkup(file: File) {
|
||||
val text = file.readText()
|
||||
val cleanText = clearTextFromDiagnosticMarkup(text)
|
||||
file.writeText(cleanText)
|
||||
}
|
||||
|
||||
fun clearTextFromDiagnosticMarkup(text: String): String = text.replace(CodeMetaInfoParser.openingOrClosingRegex, "")
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.codeMetaInfo.model
|
||||
|
||||
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
|
||||
|
||||
interface CodeMetaInfo {
|
||||
val start: Int
|
||||
val end: Int
|
||||
val tag: String
|
||||
val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration
|
||||
val attributes: MutableList<String>
|
||||
|
||||
fun asString(): String
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.codeMetaInfo.model
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.DiagnosticCodeMetaInfoRenderConfiguration
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
|
||||
class DiagnosticCodeMetaInfo(
|
||||
override val start: Int,
|
||||
override val end: Int,
|
||||
renderConfiguration: DiagnosticCodeMetaInfoRenderConfiguration,
|
||||
val diagnostic: Diagnostic
|
||||
) : CodeMetaInfo {
|
||||
constructor(
|
||||
range: TextRange,
|
||||
renderConfiguration: DiagnosticCodeMetaInfoRenderConfiguration,
|
||||
diagnostic: Diagnostic
|
||||
) : this(range.startOffset, range.endOffset, renderConfiguration, diagnostic)
|
||||
|
||||
override var renderConfiguration: DiagnosticCodeMetaInfoRenderConfiguration = renderConfiguration
|
||||
private set
|
||||
|
||||
fun replaceRenderConfiguration(renderConfiguration: DiagnosticCodeMetaInfoRenderConfiguration) {
|
||||
this.renderConfiguration = renderConfiguration
|
||||
}
|
||||
|
||||
override val tag: String
|
||||
get() = renderConfiguration.getTag(this)
|
||||
|
||||
override val attributes: MutableList<String> = mutableListOf()
|
||||
|
||||
override fun asString(): String = renderConfiguration.asString(this)
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.codeMetaInfo.model
|
||||
|
||||
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.ParsedCodeMetaInfoRenderConfiguration
|
||||
|
||||
class ParsedCodeMetaInfo(
|
||||
override val start: Int,
|
||||
override val end: Int,
|
||||
override val attributes: MutableList<String>,
|
||||
override val tag: String,
|
||||
val description: String?
|
||||
) : CodeMetaInfo {
|
||||
override val renderConfiguration = ParsedCodeMetaInfoRenderConfiguration
|
||||
|
||||
override fun asString(): String = renderConfiguration.asString(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other == null || other !is CodeMetaInfo) return false
|
||||
return this.tag == other.tag && this.start == other.start && this.end == other.end
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = start
|
||||
result = 31 * result + end
|
||||
result = 31 * result + tag.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
fun copy(): ParsedCodeMetaInfo {
|
||||
return ParsedCodeMetaInfo(start, end, attributes.toMutableList(), tag, description)
|
||||
}
|
||||
}
|
||||
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.codeMetaInfo.renderConfigurations
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
|
||||
|
||||
abstract class AbstractCodeMetaInfoRenderConfiguration(var renderParams: Boolean = true) {
|
||||
private val clickOrPressRegex = "Click or press (.*)to navigate".toRegex() // We have different hotkeys on different platforms
|
||||
open fun asString(codeMetaInfo: CodeMetaInfo): String = codeMetaInfo.tag + getPlatformsString(codeMetaInfo)
|
||||
|
||||
open fun getAdditionalParams(codeMetaInfo: CodeMetaInfo) = ""
|
||||
|
||||
protected fun sanitizeLineMarkerTooltip(originalText: String?): String {
|
||||
if (originalText == null) return "null"
|
||||
val noHtmlTags = StringUtil.removeHtmlTags(originalText)
|
||||
.replace(" ", "")
|
||||
.replace(clickOrPressRegex, "")
|
||||
.trim()
|
||||
return sanitizeLineBreaks(noHtmlTags)
|
||||
}
|
||||
|
||||
protected fun sanitizeLineBreaks(originalText: String): String {
|
||||
var sanitizedText = originalText
|
||||
sanitizedText = StringUtil.replace(sanitizedText, "\r\n", " ")
|
||||
sanitizedText = StringUtil.replace(sanitizedText, "\n", " ")
|
||||
sanitizedText = StringUtil.replace(sanitizedText, "\r", " ")
|
||||
return sanitizedText
|
||||
}
|
||||
|
||||
protected fun getPlatformsString(codeMetaInfo: CodeMetaInfo): String {
|
||||
if (codeMetaInfo.attributes.isEmpty()) return ""
|
||||
return "{${codeMetaInfo.attributes.joinToString(";")}}"
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.codeMetaInfo.renderConfigurations
|
||||
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.kotlin.checkers.diagnostics.factories.DebugInfoDiagnosticFactory1
|
||||
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
|
||||
import org.jetbrains.kotlin.codeMetaInfo.model.DiagnosticCodeMetaInfo
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.*
|
||||
|
||||
open class DiagnosticCodeMetaInfoRenderConfiguration(
|
||||
val withNewInference: Boolean = true,
|
||||
val renderSeverity: Boolean = false
|
||||
) : AbstractCodeMetaInfoRenderConfiguration() {
|
||||
private val crossPlatformLineBreak = """\r?\n""".toRegex()
|
||||
|
||||
override fun asString(codeMetaInfo: CodeMetaInfo): String {
|
||||
if (codeMetaInfo !is DiagnosticCodeMetaInfo) return ""
|
||||
return (getTag(codeMetaInfo)
|
||||
+ getPlatformsString(codeMetaInfo)
|
||||
+ getParamsString(codeMetaInfo))
|
||||
.replace(crossPlatformLineBreak, "")
|
||||
}
|
||||
|
||||
private fun getParamsString(codeMetaInfo: DiagnosticCodeMetaInfo): String {
|
||||
if (!renderParams) return ""
|
||||
val params = mutableListOf<String>()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val renderer = when (codeMetaInfo.diagnostic.factory) {
|
||||
is DebugInfoDiagnosticFactory1 -> DiagnosticWithParameters1Renderer(
|
||||
"{0}",
|
||||
Renderers.TO_STRING
|
||||
) as DiagnosticRenderer<Diagnostic>
|
||||
else -> DefaultErrorMessages.getRendererForDiagnostic(codeMetaInfo.diagnostic)
|
||||
}
|
||||
if (renderer is AbstractDiagnosticWithParametersRenderer) {
|
||||
val renderParameters = renderer.renderParameters(codeMetaInfo.diagnostic)
|
||||
params.addAll(ContainerUtil.map(renderParameters) { it.toString() })
|
||||
}
|
||||
if (renderSeverity)
|
||||
params.add("severity='${codeMetaInfo.diagnostic.severity}'")
|
||||
|
||||
params.add(getAdditionalParams(codeMetaInfo))
|
||||
|
||||
return "(\"${params.filter { it.isNotEmpty() }.joinToString("; ")}\")"
|
||||
}
|
||||
|
||||
fun getTag(codeMetaInfo: DiagnosticCodeMetaInfo): String {
|
||||
return codeMetaInfo.diagnostic.factory.name
|
||||
}
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.codeMetaInfo.renderConfigurations
|
||||
|
||||
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
|
||||
import org.jetbrains.kotlin.codeMetaInfo.model.ParsedCodeMetaInfo
|
||||
|
||||
object ParsedCodeMetaInfoRenderConfiguration : AbstractCodeMetaInfoRenderConfiguration() {
|
||||
override fun asString(codeMetaInfo: CodeMetaInfo): String {
|
||||
require(codeMetaInfo is ParsedCodeMetaInfo)
|
||||
return super.asString(codeMetaInfo) + (codeMetaInfo.description?.let { "(\"$it\")" } ?: "")
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -6,13 +6,13 @@
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
|
||||
abstract class AbstractCompileKotlinAgainstKotlinJdk15Test : AbstractCompileKotlinAgainstKotlinTest() {
|
||||
override fun invokeBox(className: String) {
|
||||
runJvmInstance(
|
||||
KotlinTestUtils.getJdk15Home(),
|
||||
KtTestUtil.getJdk15Home(),
|
||||
additionalArgs = listOf("--enable-preview"),
|
||||
classPath = listOfNotNull(
|
||||
aDir, bDir, ForTestCompileRuntime.runtimeJarForTests(),
|
||||
|
||||
+6
-5
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
import java.io.File;
|
||||
@@ -44,8 +45,8 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
||||
tmpdir = KotlinTestUtils.tmpDirForTest(this);
|
||||
aDir = new File(tmpdir, "a");
|
||||
bDir = new File(tmpdir, "b");
|
||||
KotlinTestUtils.mkdirs(aDir);
|
||||
KotlinTestUtils.mkdirs(bDir);
|
||||
KtTestUtil.mkdirs(aDir);
|
||||
KtTestUtil.mkdirs(bDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +116,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
||||
Disposable compileDisposable = createDisposable("compileA");
|
||||
CompilerConfiguration configuration = createConfiguration(
|
||||
ConfigurationKind.ALL, getTestJdkKind(files), getBackendA(),
|
||||
Collections.singletonList(KotlinTestUtils.getAnnotationsJar()),
|
||||
Collections.singletonList(KtTestUtil.getAnnotationsJar()),
|
||||
Collections.emptyList(), Collections.singletonList(testFile)
|
||||
);
|
||||
|
||||
@@ -138,7 +139,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
||||
String commonHeader = StringsKt.substringBefore(files.get(0).content, "FILE:", "");
|
||||
CompilerConfiguration configuration = createConfiguration(
|
||||
ConfigurationKind.ALL, getTestJdkKind(files), getBackendB(),
|
||||
Arrays.asList(KotlinTestUtils.getAnnotationsJar(), aDir),
|
||||
Arrays.asList(KtTestUtil.getAnnotationsJar(), aDir),
|
||||
Collections.emptyList(), Arrays.asList(testFile, new TestFile("header", commonHeader))
|
||||
);
|
||||
|
||||
@@ -167,7 +168,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
||||
) {
|
||||
|
||||
List<KtFile> ktFiles =
|
||||
files.stream().map(file -> KotlinTestUtils.createFile(file.name, file.content, environment.getProject()))
|
||||
files.stream().map(file -> KtTestUtil.createFile(file.name, file.content, environment.getProject()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
ModuleVisibilityManager.SERVICE.getInstance(environment.getProject()).addModule(
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -18,7 +19,7 @@ abstract class AbstractCustomJDKBlackBoxCodegenTest : AbstractBlackBoxCodegenTes
|
||||
override fun doTest(filePath: String) {
|
||||
val file = File(filePath)
|
||||
val expectedText =
|
||||
KotlinTestUtils.doLoadFile(file) +
|
||||
KtTestUtil.doLoadFile(file) +
|
||||
"\n" +
|
||||
"""
|
||||
fun main() {
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader;
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
@@ -49,7 +50,7 @@ abstract public class AbstractGenerateNotNullAssertionsTest extends CodegenTestC
|
||||
}
|
||||
|
||||
private void loadSource(@NotNull String fileName) {
|
||||
loadFileByFullPath(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName);
|
||||
loadFileByFullPath(KtTestUtil.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName);
|
||||
}
|
||||
|
||||
protected void doTestNoAssertionsForKotlinFromBinary(String binaryDependencyFilename, String testFilename) {
|
||||
|
||||
+2
-2
@@ -5,13 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractJdk15BlackBoxCodegenTest : AbstractCustomJDKBlackBoxCodegenTest() {
|
||||
override fun getTestJdkKind(): TestJdkKind = TestJdkKind.FULL_JDK_15
|
||||
override fun getJdkHome(): File = KotlinTestUtils.getJdk15Home()
|
||||
override fun getJdkHome(): File = KtTestUtil.getJdk15Home()
|
||||
override fun getPrefix(): String = "java15/box"
|
||||
|
||||
override fun getAdditionalJvmArgs(): List<String> = listOf("--enable-preview")
|
||||
|
||||
+3
-3
@@ -5,12 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractJdk9BlackBoxCodegenTest : AbstractCustomJDKBlackBoxCodegenTest() {
|
||||
override fun getTestJdkKind(): TestJdkKind = TestJdkKind.FULL_JDK_9
|
||||
override fun getJdkHome(): File = KotlinTestUtils.getJdk9Home()
|
||||
override fun getJdkHome(): File = KtTestUtil.getJdk9Home()
|
||||
override fun getPrefix(): String = "java9/box"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||
import java.io.File
|
||||
|
||||
|
||||
+3
-2
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.test.*;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
@@ -51,13 +52,13 @@ public abstract class AbstractTopLevelMembersInvocationTest extends AbstractByte
|
||||
getTestRootDisposable(),
|
||||
KotlinTestUtils.newConfiguration(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK,
|
||||
CollectionsKt.plus(classPath, KotlinTestUtils.getAnnotationsJar()), Collections.emptyList()
|
||||
CollectionsKt.plus(classPath, KtTestUtil.getAnnotationsJar()), Collections.emptyList()
|
||||
),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
|
||||
loadFiles(ArrayUtil.toStringArray(sourceFiles));
|
||||
|
||||
List<OccurrenceInfo> expected = readExpectedOccurrences(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + sourceFiles.get(0));
|
||||
List<OccurrenceInfo> expected = readExpectedOccurrences(KtTestUtil.getTestDataPathBase() + "/codegen/" + sourceFiles.get(0));
|
||||
String actual = generateToText();
|
||||
Companion.checkGeneratedTextAgainstExpectedOccurrences(actual, expected, TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.scripting.definitions.ScriptDependenciesProvider;
|
||||
import org.jetbrains.kotlin.scripting.resolve.ScriptCompilationConfigurationWrapper;
|
||||
import org.jetbrains.kotlin.test.*;
|
||||
import org.jetbrains.kotlin.test.clientserver.TestProxy;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader;
|
||||
import org.jetbrains.org.objectweb.asm.tree.ClassNode;
|
||||
@@ -63,8 +64,8 @@ import java.util.stream.Collectors;
|
||||
import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
|
||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.*;
|
||||
import static org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar;
|
||||
|
||||
public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.TestFile> {
|
||||
private static final String DEFAULT_TEST_FILE_NAME = "a_test";
|
||||
@@ -134,7 +135,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
|
||||
@NotNull
|
||||
protected String loadFile(@NotNull @TestDataFile String name) {
|
||||
return loadFileByFullPath(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + name);
|
||||
return loadFileByFullPath(KtTestUtil.getTestDataPathBase() + "/codegen/" + name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -172,7 +173,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
if (file.name.endsWith(".kt") || file.name.endsWith(".kts")) {
|
||||
// `rangesToDiagnosticNames` parameter is not-null only for diagnostic tests, it's using for lazy diagnostics
|
||||
String content = CheckerTestUtil.INSTANCE.parseDiagnosedRanges(file.content, new ArrayList<>(0), null);
|
||||
ktFiles.add(KotlinTestUtils.createFile(file.name, content, project));
|
||||
ktFiles.add(KtTestUtil.createFile(file.name, content, project));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,7 +609,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
protected void doTest(@NotNull String filePath) throws Exception {
|
||||
File file = new File(filePath);
|
||||
|
||||
String expectedText = KotlinTestUtils.doLoadFile(file);
|
||||
String expectedText = KtTestUtil.doLoadFile(file);
|
||||
List<TestFile> testFiles = createTestFilesFromFile(file, expectedText);
|
||||
|
||||
doMultiFileTest(file, testFiles);
|
||||
@@ -659,7 +660,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
@NotNull
|
||||
private static File createTempDirectory(String prefix) {
|
||||
try {
|
||||
return KotlinTestUtils.tmpDir(prefix);
|
||||
return KtTestUtil.tmpDir(prefix);
|
||||
} catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
@@ -674,7 +675,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
|
||||
for (TestFile testFile : javaFiles) {
|
||||
File file = new File(dir, testFile.name);
|
||||
KotlinTestUtils.mkdirs(file.getParentFile());
|
||||
KtTestUtil.mkdirs(file.getParentFile());
|
||||
FilesKt.writeText(file, testFile.content, Charsets.UTF_8);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -81,15 +81,15 @@ public class CodegenTestFiles {
|
||||
}
|
||||
|
||||
public static CodegenTestFiles create(Project project, String[] names) {
|
||||
return create(project, names, KotlinTestUtils.getTestDataPathBase());
|
||||
return create(project, names, KtTestUtil.getTestDataPathBase());
|
||||
}
|
||||
|
||||
public static CodegenTestFiles create(Project project, String[] names, String testDataPath) {
|
||||
List<KtFile> files = new ArrayList<>(names.length);
|
||||
for (String name : names) {
|
||||
try {
|
||||
String content = KotlinTestUtils.doLoadFile(testDataPath + "/codegen/", name);
|
||||
KtFile file = KotlinTestUtils.createFile(name, content, project);
|
||||
String content = KtTestUtil.doLoadFile(testDataPath + "/codegen/", name);
|
||||
KtFile file = KtTestUtil.createFile(name, content, project);
|
||||
files.add(file);
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -103,7 +103,7 @@ public class CodegenTestFiles {
|
||||
public static CodegenTestFiles create(@NotNull String fileName, @NotNull String contentWithDiagnosticMarkup, @NotNull Project project) {
|
||||
// `rangesToDiagnosticNames` parameter is not-null only for diagnostic tests, it's using for lazy diagnostics
|
||||
String content = CheckerTestUtil.INSTANCE.parseDiagnosedRanges(contentWithDiagnosticMarkup, new ArrayList<>(), null);
|
||||
KtFile file = KotlinTestUtils.createFile(fileName, content, project);
|
||||
KtFile file = KtTestUtil.createFile(fileName, content, project);
|
||||
List<PsiErrorElement> ranges = AnalyzingUtils.getSyntaxErrorRanges(file);
|
||||
assert ranges.isEmpty() : "Syntax errors found in " + file + ": " + ranges;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
|
||||
@@ -85,7 +86,7 @@ public class CodegenTestUtil {
|
||||
@NotNull List<String> additionalOptions
|
||||
) {
|
||||
try {
|
||||
File directory = KotlinTestUtils.tmpDir("java-classes");
|
||||
File directory = KtTestUtil.tmpDir("java-classes");
|
||||
compileJava(fileNames, additionalClasspath, additionalOptions, directory);
|
||||
return directory;
|
||||
}
|
||||
@@ -118,7 +119,7 @@ public class CodegenTestUtil {
|
||||
List<String> classpath = new ArrayList<>();
|
||||
classpath.add(ForTestCompileRuntime.runtimeJarForTests().getPath());
|
||||
classpath.add(ForTestCompileRuntime.reflectJarForTests().getPath());
|
||||
classpath.add(KotlinTestUtils.getAnnotationsJar().getPath());
|
||||
classpath.add(KtTestUtil.getAnnotationsJar().getPath());
|
||||
classpath.addAll(additionalClasspath);
|
||||
|
||||
List<String> options = new ArrayList<>(Arrays.asList(
|
||||
|
||||
+3
-3
@@ -25,10 +25,10 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.clientserver.TestProcessServer
|
||||
import org.jetbrains.kotlin.test.clientserver.TestProxy
|
||||
import org.jetbrains.kotlin.test.clientserver.getGeneratedClass
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import java.io.File
|
||||
import java.lang.IllegalStateException
|
||||
import java.net.URLClassLoader
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
@@ -158,7 +158,7 @@ abstract class AbstractDebugTest : CodegenTestCase() {
|
||||
GenerationUtils.compileFiles(myFiles.psiFiles, myEnvironment, classBuilderFactory)
|
||||
classFileFactory = generationState.factory
|
||||
|
||||
val tempDirForTest = KotlinTestUtils.tmpDir("debuggerTest")
|
||||
val tempDirForTest = KtTestUtil.tmpDir("debuggerTest")
|
||||
val classesDir = File(tempDirForTest, "classes")
|
||||
try {
|
||||
classFileFactory.writeAllTo(classesDir)
|
||||
@@ -298,4 +298,4 @@ abstract class AbstractDebugTest : CodegenTestCase() {
|
||||
abstract fun storeStep(loggedItems: ArrayList<Any>, event: Event)
|
||||
|
||||
abstract fun checkResult(wholeFile: File, loggedItems: List<Any>)
|
||||
}
|
||||
}
|
||||
|
||||
-149
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.codegen.forTestCompile;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ForTestCompileRuntime {
|
||||
private static volatile SoftReference<ClassLoader> reflectJarClassLoader = new SoftReference<>(null);
|
||||
private static volatile SoftReference<ClassLoader> runtimeJarClassLoader = new SoftReference<>(null);
|
||||
|
||||
@NotNull
|
||||
public static File runtimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File runtimeJarForTestsWithJdk8() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib-jdk8.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File minimalRuntimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlin-stdlib-minimal-for-test.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File kotlinTestJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-test.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File kotlinTestJUnitJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-test-junit.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File kotlinTestJsJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-test-js.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File reflectJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-reflect.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File scriptRuntimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-script-runtime.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File runtimeSourcesJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib-sources.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File stdlibMavenSourcesJarForTests() {
|
||||
return assertExists(new File("dist/maven/kotlin-stdlib-sources.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File stdlibCommonForTests() {
|
||||
return assertExists(new File("dist/common/kotlin-stdlib-common.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File stdlibCommonSourcesForTests() {
|
||||
return assertExists(new File("dist/common/kotlin-stdlib-common-sources.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File stdlibJsForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib-js.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File jetbrainsAnnotationsForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/annotations-13.0.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File jvmAnnotationsForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-annotations-jvm.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File androidAnnotationsForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-annotations-android.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File coroutinesCompatForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-coroutines-experimental-compat.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File assertExists(@NotNull File file) {
|
||||
if (!file.exists()) {
|
||||
throw new IllegalStateException(file + " does not exist. Run 'gradlew dist'");
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static synchronized ClassLoader runtimeAndReflectJarClassLoader() {
|
||||
ClassLoader loader = reflectJarClassLoader.get();
|
||||
if (loader == null) {
|
||||
loader = createClassLoader(runtimeJarForTests(), reflectJarForTests(), scriptRuntimeJarForTests(), kotlinTestJarForTests());
|
||||
reflectJarClassLoader = new SoftReference<>(loader);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static synchronized ClassLoader runtimeJarClassLoader() {
|
||||
ClassLoader loader = runtimeJarClassLoader.get();
|
||||
if (loader == null) {
|
||||
loader = createClassLoader(runtimeJarForTests(), scriptRuntimeJarForTests(), kotlinTestJarForTests());
|
||||
runtimeJarClassLoader = new SoftReference<>(loader);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ClassLoader createClassLoader(@NotNull File... files) {
|
||||
try {
|
||||
List<URL> urls = new ArrayList<>(2);
|
||||
for (File file : files) {
|
||||
urls.add(file.toURI().toURL());
|
||||
}
|
||||
return new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -12,14 +12,14 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirLightDiagnostic
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
import kotlin.math.abs
|
||||
|
||||
abstract class AbstractFirDiagnosticsWithLightTreeTest : AbstractFirDiagnosticsTest() {
|
||||
override fun doTest(filePath: String) {
|
||||
val file = createTestFileFromPath(filePath)
|
||||
val expectedText = KotlinTestUtils.doLoadFile(file)
|
||||
val expectedText = KtTestUtil.doLoadFile(file)
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(expectedText, "// IGNORE_LIGHT_TREE")) return
|
||||
|
||||
super.doTest(filePath)
|
||||
|
||||
@@ -10,7 +10,7 @@ import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest.Companion.DIAGNOSTIC_IN_TESTDATA_PATTERN
|
||||
import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest.Companion.SPEC_LINKED_TESTDATA_PATTERN
|
||||
import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest.Companion.SPEC_NOT_LINED_TESTDATA_PATTERN
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.test.util.trimTrailingWhitespacesAndAddNewlineAtEOF
|
||||
import java.io.File
|
||||
|
||||
@@ -53,11 +53,11 @@ fun compareAndMergeFirFileAndOldFrontendFile(
|
||||
}
|
||||
|
||||
private fun loadTestData(file: File, vararg patternsToBeRemoved: Regex): String {
|
||||
var text = KotlinTestUtils.doLoadFile(file)
|
||||
var text = KtTestUtil.doLoadFile(file)
|
||||
patternsToBeRemoved.forEach { text = text.replace(it, "") }
|
||||
return StringUtil.convertLineSeparators(text.trim()).trimTrailingWhitespacesAndAddNewlineAtEOF()
|
||||
}
|
||||
|
||||
fun loadTestDataWithDiagnostics(file: File) = loadTestData(file, SPEC_LINKED_TESTDATA_PATTERN, SPEC_NOT_LINED_TESTDATA_PATTERN)
|
||||
|
||||
fun loadTestDataWithoutDiagnostics(file: File) = loadTestData(file, DIAGNOSTIC_IN_TESTDATA_PATTERN, SPEC_LINKED_TESTDATA_PATTERN)
|
||||
fun loadTestDataWithoutDiagnostics(file: File) = loadTestData(file, DIAGNOSTIC_IN_TESTDATA_PATTERN, SPEC_LINKED_TESTDATA_PATTERN)
|
||||
|
||||
+3
-3
@@ -22,7 +22,6 @@ import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -35,6 +34,7 @@ import org.jetbrains.kotlin.config.KotlinCompilerVersion;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
|
||||
import org.jetbrains.kotlin.test.WithMutedInDatabaseRunTest;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.KotlinPaths;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
|
||||
@@ -88,7 +88,7 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
|
||||
content = normalizePath(content, testDataDir, "[TestData]");
|
||||
content = normalizePath(content, tmpdir, "[Temp]");
|
||||
content = normalizePath(content, getCompilerLib(), "[CompilerLib]");
|
||||
content = normalizePath(content, new File(KotlinTestUtils.getHomeDirectory()), "[KotlinProjectHome]");
|
||||
content = normalizePath(content, new File(KtTestUtil.getHomeDirectory()), "[KotlinProjectHome]");
|
||||
content = content.replaceAll(Pattern.quote(KotlinCompilerVersion.VERSION), "[KotlinVersion]");
|
||||
content = content.replaceAll("\\(JRE .+\\)", "(JRE [JREVersion])");
|
||||
content = StringUtil.convertLineSeparators(content);
|
||||
@@ -177,4 +177,4 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
|
||||
@Override
|
||||
public void processTerminated(ProcessEvent event) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
||||
+10
-6
@@ -27,21 +27,24 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.javac.JavacWrapper
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.renderer.*
|
||||
import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
|
||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.newConfiguration
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile
|
||||
import org.junit.Assert
|
||||
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.lang.annotation.Retention
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.*
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile
|
||||
|
||||
abstract class AbstractCompileJavaAgainstKotlinTest : TestCaseWithTmpdir() {
|
||||
|
||||
@Throws(IOException::class)
|
||||
@@ -80,7 +83,8 @@ abstract class AbstractCompileJavaAgainstKotlinTest : TestCaseWithTmpdir() {
|
||||
|
||||
if (!compiledSuccessfully) return
|
||||
|
||||
val configuration = newConfiguration(ConfigurationKind.ALL, TestJdkKind.FULL_JDK, getAnnotationsJar(), out)
|
||||
val configuration = newConfiguration(ConfigurationKind.ALL, TestJdkKind.FULL_JDK,
|
||||
KtTestUtil.getAnnotationsJar(), out)
|
||||
configuration.put(JVMConfigurationKeys.USE_PSI_CLASS_FILES_READING, true)
|
||||
val environment = KotlinCoreEnvironment.createForTests(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
setupLanguageVersionSettingsForCompilerTests(ktFile.readText(), environment)
|
||||
|
||||
+12
-5
@@ -33,9 +33,11 @@ import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
|
||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.*
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.newConfiguration
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
@@ -67,13 +69,14 @@ abstract class AbstractCompileKotlinAgainstJavaTest : TestCaseWithTmpdir() {
|
||||
|
||||
val environment = KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, getAnnotationsJar(), out),
|
||||
newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK,
|
||||
KtTestUtil.getAnnotationsJar(), out),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
)
|
||||
|
||||
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
|
||||
environment.configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, out)
|
||||
environment.registerJavac(emptyList(), bootClasspath = listOf(findMockJdkRtJar()))
|
||||
environment.registerJavac(emptyList(), bootClasspath = listOf(KtTestUtil.findMockJdkRtJar()))
|
||||
|
||||
val analysisResult = JvmResolveUtil.analyze(environment)
|
||||
val packageView = analysisResult.moduleDescriptor.getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME)
|
||||
@@ -95,13 +98,17 @@ abstract class AbstractCompileKotlinAgainstJavaTest : TestCaseWithTmpdir() {
|
||||
environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true)
|
||||
environment.configuration.put(JVMConfigurationKeys.COMPILE_JAVA, true)
|
||||
val ktFiles = kotlinFiles.map { kotlinFile: File ->
|
||||
createFile(kotlinFile.name, FileUtil.loadFile(kotlinFile, true), environment.project)
|
||||
KtTestUtil.createFile(
|
||||
kotlinFile.name,
|
||||
FileUtil.loadFile(kotlinFile, true),
|
||||
environment.project
|
||||
)
|
||||
}
|
||||
environment.registerJavac(
|
||||
javaFiles = javaFiles,
|
||||
kotlinFiles = ktFiles,
|
||||
arguments = if (aptMode) arrayOf() else arrayOf("-proc:none"),
|
||||
bootClasspath = listOf(findMockJdkRtJar())
|
||||
bootClasspath = listOf(KtTestUtil.findMockJdkRtJar())
|
||||
)
|
||||
ModuleVisibilityManager.SERVICE.getInstance(environment.project).addModule(
|
||||
ModuleBuilder("module for test", tmpdir.absolutePath, "test")
|
||||
|
||||
+3
-3
@@ -5,14 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractLoadJava15Test : AbstractLoadJavaTest() {
|
||||
override fun getJdkKind(): TestJdkKind = TestJdkKind.FULL_JDK_15
|
||||
override fun getJdkHomeForJavac(): File = KotlinTestUtils.getJdk15Home()
|
||||
override fun getJdkHomeForJavac(): File = KtTestUtil.getJdk15Home()
|
||||
override fun getAdditionalJavacArgs(): List<String> = ADDITIONAL_JAVAC_ARGS_FOR_15
|
||||
}
|
||||
|
||||
val ADDITIONAL_JAVAC_ARGS_FOR_15 = listOf("--release", "15", "--enable-preview")
|
||||
val ADDITIONAL_JAVAC_ARGS_FOR_15 = listOf("--release", "15", "--enable-preview")
|
||||
|
||||
+2
-2
@@ -5,12 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractLoadJava15WithPsiClassReadingTest : AbstractLoadJavaWithPsiClassReadingTest() {
|
||||
override fun getJdkKind(): TestJdkKind = TestJdkKind.FULL_JDK_15
|
||||
override fun getJdkHomeForJavac(): File = KotlinTestUtils.getJdk15Home()
|
||||
override fun getJdkHomeForJavac(): File = KtTestUtil.getJdk15Home()
|
||||
override fun getAdditionalJavacArgs(): List<String> = ADDITIONAL_JAVAC_ARGS_FOR_15
|
||||
}
|
||||
|
||||
+5
-3
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor;
|
||||
import org.jetbrains.kotlin.test.*;
|
||||
import org.jetbrains.kotlin.test.util.DescriptorValidator;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
@@ -39,7 +40,8 @@ import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil.*;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.*;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.compileKotlinWithJava;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.newConfiguration;
|
||||
import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesAllowed;
|
||||
import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden;
|
||||
import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.*;
|
||||
@@ -89,7 +91,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
@NotNull
|
||||
private List<File> getClasspath(File... files) {
|
||||
List<File> classpath = new ArrayList<>(getExtraClasspath());
|
||||
classpath.add(getAnnotationsJar());
|
||||
classpath.add(KtTestUtil.getAnnotationsJar());
|
||||
classpath.addAll(Arrays.asList(files));
|
||||
return classpath;
|
||||
}
|
||||
@@ -240,7 +242,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
);
|
||||
registerJavacIfNeeded(environment);
|
||||
configureEnvironment(environment);
|
||||
KtFile ktFile = KotlinTestUtils.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject());
|
||||
KtFile ktFile = KtTestUtil.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject());
|
||||
|
||||
ModuleDescriptor module = GenerationUtils.compileFiles(Collections.singletonList(ktFile), environment).getModule();
|
||||
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
||||
|
||||
+4
-3
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
import java.io.File;
|
||||
@@ -111,7 +112,7 @@ public class LoadDescriptorUtil {
|
||||
) {
|
||||
List<File> javaBinaryRoots = new ArrayList<>();
|
||||
// TODO: use the same additional binary roots as those were used for compilation
|
||||
javaBinaryRoots.add(KotlinTestUtils.getAnnotationsJar());
|
||||
javaBinaryRoots.add(KtTestUtil.getAnnotationsJar());
|
||||
javaBinaryRoots.add(ForTestCompileRuntime.jvmAnnotationsForTests());
|
||||
javaBinaryRoots.addAll(additionalClasspath);
|
||||
|
||||
@@ -156,7 +157,7 @@ public class LoadDescriptorUtil {
|
||||
List<File> classpath = new ArrayList<>();
|
||||
|
||||
classpath.add(ForTestCompileRuntime.runtimeJarForTests());
|
||||
classpath.add(KotlinTestUtils.getAnnotationsJar());
|
||||
classpath.add(KtTestUtil.getAnnotationsJar());
|
||||
|
||||
for (File test : javaFiles) {
|
||||
String content = FilesKt.readText(test, Charsets.UTF_8);
|
||||
@@ -189,7 +190,7 @@ public class LoadDescriptorUtil {
|
||||
private static List<KtFile> createKtFiles(@NotNull List<File> kotlinFiles, @NotNull KotlinCoreEnvironment environment) {
|
||||
return CollectionsKt.map(kotlinFiles, kotlinFile -> {
|
||||
try {
|
||||
return KotlinTestUtils.createFile(kotlinFile.getName(), FileUtil.loadFile(kotlinFile, true), environment.getProject());
|
||||
return KtTestUtil.createFile(kotlinFile.getName(), FileUtil.loadFile(kotlinFile, true), environment.getProject());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.test.*;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@@ -43,7 +44,7 @@ public abstract class ExtensibleResolveTestCase extends KotlinTestWithEnvironmen
|
||||
|
||||
protected void doTest(@NonNls String filePath) throws Exception {
|
||||
File file = new File(filePath);
|
||||
String text = KotlinTestUtils.doLoadFile(file);
|
||||
String text = KtTestUtil.doLoadFile(file);
|
||||
List<KtFile> files = TestFiles.createTestFiles("file.kt", text, new TestFiles.TestFileFactoryNoModules<KtFile>() {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.PackageDescriptorUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -340,7 +341,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
|
||||
|
||||
@NotNull
|
||||
protected KtFile getFile(@NotNull String content) {
|
||||
KtFile ktFile = KotlinTestUtils.createFile("dummy.kt", content, getProject());
|
||||
KtFile ktFile = KtTestUtil.createFile("dummy.kt", content, getProject());
|
||||
analysisResult = KotlinTestUtils.analyzeFile(ktFile, getEnvironment());
|
||||
|
||||
return ktFile;
|
||||
@@ -361,7 +362,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
|
||||
|
||||
protected static String getContent(@NotNull String annotationText) throws IOException {
|
||||
File file = new File(PATH);
|
||||
return KotlinTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText);
|
||||
return KtTestUtil.doLoadFile(file).replaceAll("ANNOTATION", annotationText);
|
||||
}
|
||||
|
||||
public static String renderAnnotations(Annotations annotations) {
|
||||
|
||||
+2
-1
@@ -43,13 +43,14 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractResolvedCallsTest : KotlinTestWithEnvironment() {
|
||||
override fun createEnvironment(): KotlinCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.ALL)
|
||||
|
||||
fun doTest(filePath: String) {
|
||||
val originalText = KotlinTestUtils.doLoadFile(File(filePath))!!
|
||||
val originalText = KtTestUtil.doLoadFile(File(filePath))!!
|
||||
val (text, carets) = extractCarets(originalText)
|
||||
|
||||
setupLanguageVersionSettingsForCompilerTests(originalText, environment)
|
||||
|
||||
+7
-2
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.tests.di.createContainerForTests
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -61,12 +62,16 @@ abstract class AbstractConstraintSystemTest : KotlinTestWithEnvironment() {
|
||||
}
|
||||
|
||||
private val testDataPath: String
|
||||
get() = KotlinTestUtils.getTestDataPathBase() + "/constraintSystem/"
|
||||
get() = KtTestUtil.getTestDataPathBase() + "/constraintSystem/"
|
||||
|
||||
private fun analyzeDeclarations(): ConstraintSystemTestData {
|
||||
val fileName = "declarations.kt"
|
||||
|
||||
val psiFile = KotlinTestUtils.createFile(fileName, KotlinTestUtils.doLoadFile(testDataPath, fileName), project)
|
||||
val psiFile = KtTestUtil.createFile(
|
||||
fileName,
|
||||
KtTestUtil.doLoadFile(testDataPath, fileName),
|
||||
project
|
||||
)
|
||||
val bindingContext = JvmResolveUtil.analyzeAndCheckForErrors(psiFile, environment).bindingContext
|
||||
return ConstraintSystemTestData(bindingContext, project, typeResolver)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.test
|
||||
import org.jetbrains.kotlin.cli.common.CLITool
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
@@ -53,7 +54,7 @@ object CompilerTestUtil {
|
||||
extraOptions: List<String> = emptyList(),
|
||||
extraClasspath: List<File> = emptyList()
|
||||
): File {
|
||||
val destination = File(KotlinTestUtils.tmpDir("testLibrary"), "$libraryName.jar")
|
||||
val destination = File(KtTestUtil.tmpDir("testLibrary"), "$libraryName.jar")
|
||||
val args = mutableListOf<String>().apply {
|
||||
add(src.path)
|
||||
add("-d")
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.config.JvmTarget.Companion.fromString
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
import java.lang.reflect.Field
|
||||
import java.util.*
|
||||
@@ -32,7 +33,7 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
|
||||
@Throws(java.lang.Exception::class)
|
||||
protected open fun doTest(filePath: String) {
|
||||
val file = File(filePath)
|
||||
val expectedText = KotlinTestUtils.doLoadFile(file)
|
||||
val expectedText = KtTestUtil.doLoadFile(file)
|
||||
doMultiFileTest(file, createTestFilesFromFile(file, expectedText))
|
||||
}
|
||||
|
||||
|
||||
@@ -12,19 +12,13 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.ShutDownTracker;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.util.text.StringUtilRt;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import junit.framework.TestCase;
|
||||
import kotlin.Unit;
|
||||
@@ -32,7 +26,6 @@ import kotlin.collections.CollectionsKt;
|
||||
import kotlin.collections.SetsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
@@ -43,8 +36,8 @@ import org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettingsKt;
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.kotlin.cli.common.config.ContentRootsKt;
|
||||
import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
@@ -52,7 +45,6 @@ import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt;
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.kotlin.config.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
||||
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -61,12 +53,12 @@ import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.test.util.JetTestUtilsKt;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.junit.Assert;
|
||||
|
||||
import javax.tools.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
@@ -96,8 +88,6 @@ public class KotlinTestUtils {
|
||||
private static final boolean AUTOMATICALLY_UNMUTE_PASSED_TESTS = false;
|
||||
private static final boolean AUTOMATICALLY_MUTE_FAILED_TESTS = false;
|
||||
|
||||
private static final List<File> filesToDelete = new ArrayList<>();
|
||||
|
||||
private static final Pattern DIRECTIVE_PATTERN = Pattern.compile("^//\\s*[!]?([A-Z_]+)(:[ \\t]*(.*))?$", Pattern.MULTILINE);
|
||||
|
||||
private KotlinTestUtils() {
|
||||
@@ -125,7 +115,7 @@ public class KotlinTestUtils {
|
||||
@NotNull TestJdkKind jdkKind
|
||||
) {
|
||||
return KotlinCoreEnvironment.createForTests(
|
||||
disposable, newConfiguration(configurationKind, jdkKind, getAnnotationsJar()), EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
disposable, newConfiguration(configurationKind, jdkKind, KtTestUtil.getAnnotationsJar()), EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
);
|
||||
}
|
||||
|
||||
@@ -134,156 +124,9 @@ public class KotlinTestUtils {
|
||||
return createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(disposable, ConfigurationKind.ALL, TestJdkKind.FULL_JDK);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getTestDataPathBase() {
|
||||
return getHomeDirectory() + "/compiler/testData";
|
||||
}
|
||||
|
||||
private static String homeDir = computeHomeDirectory();
|
||||
|
||||
@NotNull
|
||||
public static String getHomeDirectory() {
|
||||
return homeDir;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String computeHomeDirectory() {
|
||||
String userDir = System.getProperty("user.dir");
|
||||
File dir = new File(userDir == null ? "." : userDir);
|
||||
return FileUtil.toCanonicalPath(dir.getAbsolutePath());
|
||||
}
|
||||
|
||||
public static File findMockJdkRtJar() {
|
||||
return new File(getHomeDirectory(), "compiler/testData/mockJDK/jre/lib/rt.jar");
|
||||
}
|
||||
|
||||
// Differs from common mock JDK only by one additional 'nonExistingMethod' in Collection and constructor from Double in Throwable
|
||||
// It's needed to test the way we load additional built-ins members that neither in black nor white lists
|
||||
public static File findMockJdkRtModified() {
|
||||
return new File(getHomeDirectory(), "compiler/testData/mockJDKModified/rt.jar");
|
||||
}
|
||||
|
||||
public static File findAndroidApiJar() {
|
||||
String androidJarProp = System.getProperty("android.jar");
|
||||
File androidJarFile = androidJarProp == null ? null : new File(androidJarProp);
|
||||
if (androidJarFile == null || !androidJarFile.isFile()) {
|
||||
throw new RuntimeException(
|
||||
"Unable to get a valid path from 'android.jar' property (" +
|
||||
androidJarProp +
|
||||
"), please point it to the 'android.jar' file location");
|
||||
}
|
||||
return androidJarFile;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File findAndroidSdk() {
|
||||
String androidSdkProp = System.getProperty("android.sdk");
|
||||
File androidSdkDir = androidSdkProp == null ? null : new File(androidSdkProp);
|
||||
if (androidSdkDir == null || !androidSdkDir.isDirectory()) {
|
||||
throw new RuntimeException(
|
||||
"Unable to get a valid path from 'android.sdk' property (" +
|
||||
androidSdkProp +
|
||||
"), please point it to the android SDK location");
|
||||
}
|
||||
return androidSdkDir;
|
||||
}
|
||||
|
||||
public static String getAndroidSdkSystemIndependentPath() {
|
||||
return PathUtil.toSystemIndependentName(findAndroidSdk().getAbsolutePath());
|
||||
}
|
||||
|
||||
public static File getAnnotationsJar() {
|
||||
return new File(getHomeDirectory(), "compiler/testData/mockJDK/jre/lib/annotations.jar");
|
||||
}
|
||||
|
||||
public static void mkdirs(@NotNull File file) {
|
||||
if (file.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
if (!file.mkdirs()) {
|
||||
if (file.exists()) {
|
||||
throw new IllegalStateException("Failed to create " + file + ": file exists and not a directory");
|
||||
}
|
||||
throw new IllegalStateException("Failed to create " + file);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File tmpDirForTest(@NotNull String testClassName, @NotNull String testName) throws IOException {
|
||||
return normalizeFile(FileUtil.createTempDirectory(testClassName, testName, false));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File tmpDirForTest(TestCase test) throws IOException {
|
||||
return tmpDirForTest(test.getClass().getSimpleName(), test.getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File tmpDir(String name) throws IOException {
|
||||
return normalizeFile(FileUtil.createTempDirectory(name, "", false));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File tmpDirForReusableFolder(String name) throws IOException {
|
||||
return normalizeFile(FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, "", true));
|
||||
}
|
||||
|
||||
private static File normalizeFile(File file) throws IOException {
|
||||
// Get canonical file to be sure that it's the same as inside the compiler,
|
||||
// for example, on Windows, if a canonical path contains any space from FileUtil.createTempDirectory we will get
|
||||
// a File with short names (8.3) in its path and it will break some normalization passes in tests.
|
||||
return file.getCanonicalFile();
|
||||
}
|
||||
|
||||
private static void deleteOnShutdown(File file) {
|
||||
if (filesToDelete.isEmpty()) {
|
||||
ShutDownTracker.getInstance().registerShutdownTask(() -> {
|
||||
for (File victim : filesToDelete) {
|
||||
FileUtil.delete(victim);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
filesToDelete.add(file);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KtFile createFile(@NotNull @NonNls String name, @NotNull String text, @NotNull Project project) {
|
||||
String shortName = name.substring(name.lastIndexOf('/') + 1);
|
||||
shortName = shortName.substring(shortName.lastIndexOf('\\') + 1);
|
||||
LightVirtualFile virtualFile = new LightVirtualFile(shortName, KotlinLanguage.INSTANCE, StringUtilRt.convertLineSeparators(text));
|
||||
|
||||
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
||||
PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
|
||||
//noinspection ConstantConditions
|
||||
return (KtFile) factory.trySetupPsiForFile(virtualFile, KotlinLanguage.INSTANCE, true, false);
|
||||
}
|
||||
|
||||
public static String doLoadFile(String myFullDataPath, String name) throws IOException {
|
||||
String fullName = myFullDataPath + File.separatorChar + name;
|
||||
return doLoadFile(new File(fullName));
|
||||
}
|
||||
|
||||
public static String doLoadFile(@NotNull File file) throws IOException {
|
||||
try {
|
||||
return FileUtil.loadFile(file, CharsetToolkit.UTF8, true);
|
||||
}
|
||||
catch (FileNotFoundException fileNotFoundException) {
|
||||
/*
|
||||
* Unfortunately, the FileNotFoundException will only show the relative path in it's exception message.
|
||||
* This clarifies the exception by showing the full path.
|
||||
*/
|
||||
String messageWithFullPath = file.getAbsolutePath() + " (No such file or directory)";
|
||||
throw new IOException(
|
||||
"Ensure you have your 'Working Directory' configured correctly as the root " +
|
||||
"Kotlin project directory in your test configuration\n\t" +
|
||||
messageWithFullPath,
|
||||
fileNotFoundException);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFilePath(File file) {
|
||||
return FileUtil.toSystemIndependentName(file.getPath());
|
||||
return KtTestUtil.tmpDirForTest(test.getClass().getSimpleName(), test.getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -346,15 +189,15 @@ public class KotlinTestUtils {
|
||||
CompilerConfiguration configuration = newConfiguration();
|
||||
JvmContentRootsKt.addJavaSourceRoots(configuration, javaSource);
|
||||
if (jdkKind == TestJdkKind.MOCK_JDK) {
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, findMockJdkRtJar());
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, KtTestUtil.findMockJdkRtJar());
|
||||
configuration.put(JVMConfigurationKeys.NO_JDK, true);
|
||||
}
|
||||
else if (jdkKind == TestJdkKind.MODIFIED_MOCK_JDK) {
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, findMockJdkRtModified());
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, KtTestUtil.findMockJdkRtModified());
|
||||
configuration.put(JVMConfigurationKeys.NO_JDK, true);
|
||||
}
|
||||
else if (jdkKind == TestJdkKind.ANDROID_API) {
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, findAndroidApiJar());
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, KtTestUtil.findAndroidApiJar());
|
||||
configuration.put(JVMConfigurationKeys.NO_JDK, true);
|
||||
}
|
||||
else if (jdkKind == TestJdkKind.FULL_JDK_6) {
|
||||
@@ -363,10 +206,10 @@ public class KotlinTestUtils {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(jdk6));
|
||||
}
|
||||
else if (jdkKind == TestJdkKind.FULL_JDK_9) {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, getJdk9Home());
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, KtTestUtil.getJdk9Home());
|
||||
}
|
||||
else if (jdkKind == TestJdkKind.FULL_JDK_15) {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, getJdk15Home());
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, KtTestUtil.getJdk15Home());
|
||||
}
|
||||
else if (SystemInfo.IS_AT_LEAST_JAVA9) {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(System.getProperty("java.home")));
|
||||
@@ -390,41 +233,6 @@ public class KotlinTestUtils {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File getJdk9Home() {
|
||||
String jdk9 = System.getenv("JDK_9");
|
||||
if (jdk9 == null) {
|
||||
jdk9 = System.getenv("JDK_19");
|
||||
if (jdk9 == null) {
|
||||
throw new AssertionError("Environment variable JDK_9 is not set!");
|
||||
}
|
||||
}
|
||||
return new File(jdk9);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getJdk11Home() {
|
||||
String jdk11 = System.getenv("JDK_11");
|
||||
if (jdk11 == null) {
|
||||
return null;
|
||||
}
|
||||
return new File(jdk11);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File getJdk15Home() {
|
||||
String jdk15 = System.getenv("JDK_15");
|
||||
|
||||
if (jdk15 == null) {
|
||||
jdk15 = System.getenv("JDK_15_0");
|
||||
}
|
||||
|
||||
if (jdk15 == null) {
|
||||
throw new AssertionError("Environment variable JDK_15 is not set!");
|
||||
}
|
||||
return new File(jdk15);
|
||||
}
|
||||
|
||||
public static void resolveAllKotlinFiles(KotlinCoreEnvironment environment) throws IOException {
|
||||
List<KotlinSourceRoot> roots = ContentRootsKt.getKotlinSourceRoots(environment.getConfiguration());
|
||||
if (roots.isEmpty()) return;
|
||||
@@ -685,7 +493,7 @@ public class KotlinTestUtils {
|
||||
}
|
||||
|
||||
public static boolean compileJavaFilesExternallyWithJava9(@NotNull Collection<File> files, @NotNull List<String> options) {
|
||||
return compileJavaFilesExternally(files, options, getJdk9Home());
|
||||
return compileJavaFilesExternally(files, options, KtTestUtil.getJdk9Home());
|
||||
}
|
||||
|
||||
public static boolean compileJavaFilesExternally(@NotNull Collection<File> files, @NotNull List<String> options, @NotNull File jdkHome) {
|
||||
@@ -825,7 +633,7 @@ public class KotlinTestUtils {
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (!isIgnored && AUTOMATICALLY_MUTE_FAILED_TESTS) {
|
||||
String text = doLoadFile(testDataFile);
|
||||
String text = KtTestUtil.doLoadFile(testDataFile);
|
||||
String directive = ignoreDirective + targetBackend.name() + "\n";
|
||||
|
||||
String newText;
|
||||
@@ -864,7 +672,7 @@ public class KotlinTestUtils {
|
||||
|
||||
if (isIgnored) {
|
||||
if (AUTOMATICALLY_UNMUTE_PASSED_TESTS) {
|
||||
String text = doLoadFile(testDataFile);
|
||||
String text = KtTestUtil.doLoadFile(testDataFile);
|
||||
String directive = ignoreDirective + targetBackend.name();
|
||||
String newText = Pattern.compile("^" + directive + "\n", Pattern.MULTILINE).matcher(text).replaceAll("");
|
||||
if (!newText.equals(text)) {
|
||||
@@ -1069,7 +877,7 @@ public class KotlinTestUtils {
|
||||
private static void assertTestClassPresentByMetadata(@NotNull Class<?> outerClass, @NotNull File testDataDir) {
|
||||
for (Class<?> nestedClass : outerClass.getDeclaredClasses()) {
|
||||
TestMetadata testMetadata = nestedClass.getAnnotation(TestMetadata.class);
|
||||
if (testMetadata != null && testMetadata.value().equals(getFilePath(testDataDir))) {
|
||||
if (testMetadata != null && testMetadata.value().equals(KtTestUtil.getFilePath(testDataDir))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.preloading.ClassPreloadingUtils
|
||||
import org.jetbrains.kotlin.preloading.Preloader
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.assertEquals
|
||||
@@ -52,7 +53,7 @@ object MockLibraryUtil {
|
||||
useJava9: Boolean = false
|
||||
): File {
|
||||
return compileLibraryToJar(
|
||||
sourcesPath, KotlinTestUtils.tmpDirForReusableFolder("testLibrary-" + jarName), jarName, addSources, allowKotlinSources, extraOptions, extraClasspath
|
||||
sourcesPath, KtTestUtil.tmpDirForReusableFolder("testLibrary-" + jarName), jarName, addSources, allowKotlinSources, extraOptions, extraClasspath
|
||||
, useJava9)}
|
||||
|
||||
@JvmStatic
|
||||
@@ -96,7 +97,7 @@ object MockLibraryUtil {
|
||||
if (javaFiles.isNotEmpty()) {
|
||||
val classpath = mutableListOf<String>()
|
||||
classpath += ForTestCompileRuntime.runtimeJarForTests().path
|
||||
classpath += KotlinTestUtils.getAnnotationsJar().path
|
||||
classpath += KtTestUtil.getAnnotationsJar().path
|
||||
classpath += extraClasspath
|
||||
|
||||
// Probably no kotlin files were present, so dir might not have been created after kotlin compiler
|
||||
@@ -127,7 +128,7 @@ object MockLibraryUtil {
|
||||
|
||||
@JvmStatic
|
||||
fun compileJsLibraryToJar(sourcesPath: String, jarName: String, addSources: Boolean, extraOptions: List<String> = emptyList()): File {
|
||||
val contentDir = KotlinTestUtils.tmpDirForReusableFolder("testLibrary-" + jarName)
|
||||
val contentDir = KtTestUtil.tmpDirForReusableFolder("testLibrary-" + jarName)
|
||||
|
||||
val outDir = File(contentDir, "out")
|
||||
val outputFile = File(outDir, jarName + ".js")
|
||||
|
||||
Reference in New Issue
Block a user