Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
3ee56657
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3ee56657
编写于
2月 09, 2021
作者:
D
Dmitriy Novozhilov
提交者:
TeamCityServer
2月 10, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Parse compiler configuration for android tests using new test infrastructure
上级
a0007bf2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
106 addition
and
25 deletion
+106
-25
compiler/android-tests/build.gradle.kts
compiler/android-tests/build.gradle.kts
+6
-0
compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/AndroidTestGenerator.kt
...rg/jetbrains/kotlin/android/tests/AndroidTestGenerator.kt
+10
-12
compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt
...ns/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt
+90
-13
未找到文件。
compiler/android-tests/build.gradle.kts
浏览文件 @
3ee56657
...
...
@@ -19,6 +19,10 @@ dependencies {
testCompile
(
project
(
":kotlin-reflect"
))
testCompile
(
projectTests
(
":compiler:tests-common"
))
testCompile
(
commonDep
(
"junit:junit"
))
testApi
(
projectTests
(
":compiler:test-infrastructure"
))
testApi
(
projectTests
(
":compiler:test-infrastructure-utils"
))
testApi
(
projectTests
(
":compiler:tests-compiler-utils"
))
testApi
(
projectTests
(
":compiler:tests-common-new"
))
testCompile
(
projectTests
(
":jps-plugin"
))
testCompile
(
commonDep
(
"junit:junit"
))
...
...
@@ -37,6 +41,8 @@ dependencies {
testCompile
(
intellijPluginDep
(
"java"
))
{
includeJars
(
"jps-builders"
)
}
testCompile
(
jpsStandalone
())
{
includeJars
(
"jps-model"
)
}
testCompile
(
jpsBuildTest
())
testCompile
(
"org.junit.platform:junit-platform-launcher:${commonVer("
org
.
junit
.
platform
", "")}"
)
}
sourceSets
{
...
...
compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/AndroidTestGenerator.kt
浏览文件 @
3ee56657
...
...
@@ -20,7 +20,9 @@ import com.intellij.openapi.util.Ref
import
org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
import
org.jetbrains.kotlin.name.FqName
import
org.jetbrains.kotlin.name.Name
import
org.jetbrains.kotlin.test.KotlinBaseTest
import
org.jetbrains.kotlin.test.model.TestModule
import
org.jetbrains.kotlin.test.services.TestServices
import
org.jetbrains.kotlin.test.services.sourceFileProvider
import
java.io.File
import
java.util.regex.Pattern
...
...
@@ -34,28 +36,24 @@ private data class OldPackageAndNew(val oldFqName: FqName, val newFqName: FqName
internal
fun
patchFilesAndAddTest
(
testFile
:
File
,
testFiles
:
List
<
KotlinBaseTest
.
TestFile
>,
module
:
TestModule
,
services
:
TestServices
,
filesHolder
:
CodegenTestsOnAndroidGenerator
.
FilesWriter
):
FqName
?
{
if
(
testFiles
.
any
{
it
.
name
.
endsWith
(
".java"
)
})
{
//TODO support java files
return
null
}
val
ktFiles
=
testFiles
.
filter
{
it
.
name
.
endsWith
(
".kt"
)
}
if
(
ktFiles
.
isEmpty
())
return
null
):
FqName
{
val
newPackagePrefix
=
testFile
.
path
.
replace
(
"\\\\|-|\\.|/"
.
toRegex
(),
"_"
)
val
oldPackage
=
Ref
<
FqName
>()
val
isJvmName
=
Ref
<
Boolean
>(
false
)
val
testFiles
=
module
.
files
val
isSingle
=
testFiles
.
size
==
1
val
resultFiles
=
testFiles
.
map
{
val
fileName
=
if
(
isSingle
)
it
.
name
else
testFile
.
name
.
substringBeforeLast
(
".kt"
)
+
"/"
+
it
.
name
val
content
=
services
.
sourceFileProvider
.
getContentOfSourceFile
(
it
)
TestClassInfo
(
fileName
,
changePackage
(
newPackagePrefix
,
it
.
content
,
oldPackage
,
isJvmName
),
changePackage
(
newPackagePrefix
,
content
,
oldPackage
,
isJvmName
),
oldPackage
.
get
(),
isJvmName
.
get
(),
getGeneratedClassName
(
File
(
fileName
),
it
.
content
,
newPackagePrefix
,
oldPackage
.
get
())
getGeneratedClassName
(
File
(
fileName
),
content
,
newPackagePrefix
,
oldPackage
.
get
())
)
}
val
packages
=
...
...
compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt
浏览文件 @
3ee56657
...
...
@@ -16,12 +16,25 @@ import org.jetbrains.kotlin.codegen.CodegenTestCase
import
org.jetbrains.kotlin.codegen.CodegenTestFiles
import
org.jetbrains.kotlin.codegen.GenerationUtils
import
org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import
org.jetbrains.kotlin.config.CommonConfigurationKeys
import
org.jetbrains.kotlin.config.CompilerConfiguration
import
org.jetbrains.kotlin.config.JvmTarget
import
org.jetbrains.kotlin.config.*
import
org.jetbrains.kotlin.idea.KotlinFileType
import
org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import
org.jetbrains.kotlin.psi.KtFile
import
org.jetbrains.kotlin.test.*
import
org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import
org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives
import
org.jetbrains.kotlin.test.directives.model.singleOrZeroValue
import
org.jetbrains.kotlin.test.model.DependencyKind
import
org.jetbrains.kotlin.test.model.FrontendKinds
import
org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest
import
org.jetbrains.kotlin.test.services.*
import
org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator
import
org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator
import
org.jetbrains.kotlin.test.services.impl.BackendKindExtractorImpl
import
org.jetbrains.kotlin.test.services.impl.TemporaryDirectoryManagerImpl
import
org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsSourceFilesProvider
import
org.jetbrains.kotlin.test.services.sourceProviders.CodegenHelpersSourceFilesProvider
import
org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider
import
org.jetbrains.kotlin.test.util.KtTestUtil
import
org.junit.Assert
import
java.io.File
...
...
@@ -237,6 +250,7 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
}
}
@OptIn
(
TestInfrastructureInternals
::
class
)
@Throws
(
IOException
::
class
)
private
fun
processFiles
(
files
:
Array
<
File
>,
...
...
@@ -290,29 +304,92 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
if
(
fullFileText
.
contains
(
"// SKIP_JDK6"
))
continue
if
(
hasBoxMethod
(
fullFileText
))
{
val
testFiles
=
createTestFiles
(
file
,
fullFileText
)
val
kind
=
KotlinBaseTest
.
extractConfigurationKind
(
testFiles
)
val
jdkKind
=
KotlinBaseTest
.
getTestJdkKind
(
testFiles
)
val
testConfiguration
=
createTestConfiguration
(
file
)
val
services
=
testConfiguration
.
testServices
val
moduleStructure
=
try
{
testConfiguration
.
moduleStructureExtractor
.
splitTestDataByModules
(
file
.
path
,
testConfiguration
.
directives
,
).
also
{
services
.
register
(
TestModuleStructure
::
class
,
it
)
}
}
catch
(
e
:
ExceptionFromModuleStructureTransformer
)
{
continue
}
val
module
=
moduleStructure
.
modules
.
singleOrNull
()
?:
continue
if
(
module
.
files
.
any
{
it
.
isJavaFile
||
it
.
isKtsFile
})
continue
if
(
module
.
files
.
isEmpty
())
continue
services
.
registerDependencyProvider
(
DependencyProviderImpl
(
services
,
moduleStructure
.
modules
))
val
keyConfiguration
=
CompilerConfiguration
()
KotlinBaseTest
.
updateConfigurationByDirectivesInTestFiles
(
testFiles
,
keyConfiguration
)
module
.
directives
.
singleOrZeroValue
(
JvmEnvironmentConfigurationDirectives
.
JVM_TARGET
)
?.
let
{
keyConfiguration
.
put
(
JVMConfigurationKeys
.
JVM_TARGET
,
it
)
}
val
configuratorForFlags
=
JvmEnvironmentConfigurator
(
services
)
with
(
configuratorForFlags
)
{
val
extractor
=
DirectiveToConfigurationKeyExtractor
()
extractor
.
provideConfigurationKeys
()
extractor
.
configure
(
keyConfiguration
,
module
.
directives
)
}
val
kind
=
configuratorForFlags
.
extractConfigurationKind
(
module
.
directives
)
val
jdkKind
=
configuratorForFlags
.
extractJdkKind
(
module
.
directives
)
keyConfiguration
.
languageVersionSettings
=
module
.
languageVersionSettings
val
key
=
ConfigurationKey
(
kind
,
jdkKind
,
keyConfiguration
.
toString
())
val
compiler
=
if
(
kind
.
withReflection
)
REFLECT
else
COMMON
val
compilerConfigurationProvider
=
services
.
compilerConfigurationProvider
as
CompilerConfigurationProviderImpl
val
filesHolder
=
holders
.
getOrPut
(
key
)
{
FilesWriter
(
compiler
,
KotlinTestUtils
.
newConfiguration
(
kind
,
jdkKind
,
KtTestUtil
.
getAnnotationsJar
()
).
apply
{
FilesWriter
(
compiler
,
compilerConfigurationProvider
.
createCompilerConfiguration
(
module
)).
also
{
println
(
"Creating new configuration by $key"
)
KotlinBaseTest
.
updateConfigurationByDirectivesInTestFiles
(
testFiles
,
this
)
})
}
}
patchFilesAndAddTest
(
file
,
testFil
es
,
filesHolder
)
patchFilesAndAddTest
(
file
,
module
,
servic
es
,
filesHolder
)
}
}
}
}
private
fun
createTestConfiguration
(
testDataFile
:
File
):
TestConfiguration
{
return
TestConfigurationBuilder
().
apply
{
testConfiguration
()
testInfo
=
KotlinTestInfo
(
"org.jetbrains.kotlin.android.tests.AndroidRunner"
,
"test${testDataFile.nameWithoutExtension.capitalize()}"
,
emptySet
()
)
}.
build
(
testDataFile
.
path
)
}
private
val
testConfiguration
:
TestConfigurationBuilder
.()
->
Unit
=
{
globalDefaults
{
frontend
=
FrontendKinds
.
ClassicFrontend
targetBackend
=
TargetBackend
.
ANDROID
targetPlatform
=
JvmPlatforms
.
defaultJvmPlatform
dependencyKind
=
DependencyKind
.
Binary
}
useConfigurators
(
::
CommonEnvironmentConfigurator
,
::
JvmEnvironmentConfigurator
)
useAdditionalSourceProviders
(
::
AdditionalDiagnosticsSourceFilesProvider
,
::
CoroutineHelpersSourceFilesProvider
,
::
CodegenHelpersSourceFilesProvider
,
)
assertions
=
JUnit5Assertions
useAdditionalService
<
TemporaryDirectoryManager
>(
::
TemporaryDirectoryManagerImpl
)
useAdditionalService
<
BackendKindExtractor
>(
::
BackendKindExtractorImpl
)
useSourcePreprocessor
(*
AbstractKotlinCompilerTest
.
defaultPreprocessors
.
toTypedArray
())
useDirectives
(*
AbstractKotlinCompilerTest
.
defaultDirectiveContainers
.
toTypedArray
())
}
private
fun
createTestFiles
(
file
:
File
,
expectedText
:
String
):
List
<
KotlinBaseTest
.
TestFile
>
=
CodegenTestCase
.
createTestFilesFromFile
(
file
,
expectedText
,
false
,
TargetBackend
.
JVM
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录