Refactoring: always use compiler settings with de-configuration in tests
This commit is contained in:
committed by
Nikolay Krasko
parent
018215f47d
commit
3a5f42cc5e
+12
-2
@@ -228,7 +228,6 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
||||
|
||||
}
|
||||
|
||||
|
||||
object CompilerTestDirectives {
|
||||
const val LANGUAGE_VERSION_DIRECTIVE = "LANGUAGE_VERSION:"
|
||||
const val JVM_TARGET_DIRECTIVE = "JVM_TARGET:"
|
||||
@@ -237,6 +236,17 @@ object CompilerTestDirectives {
|
||||
val ALL_COMPILER_TEST_DIRECTIVES = listOf(LANGUAGE_VERSION_DIRECTIVE, JVM_TARGET_DIRECTIVE, COMPILER_ARGUMENTS_DIRECTIVE)
|
||||
}
|
||||
|
||||
fun <T> withCustomCompilerOptions(fileText: String, project: Project, module: Module, body: () -> T): T {
|
||||
val configured = configureCompilerOptions(fileText, project, module)
|
||||
try {
|
||||
return body()
|
||||
} finally {
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun configureCompilerOptions(fileText: String, project: Project, module: Module): Boolean {
|
||||
val version = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// $LANGUAGE_VERSION_DIRECTIVE ")
|
||||
val jvmTarget = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// $JVM_TARGET_DIRECTIVE ")
|
||||
@@ -286,7 +296,7 @@ fun <T> configureRegistryAndRun(fileText: String, body: () -> T) {
|
||||
}
|
||||
}
|
||||
|
||||
fun rollbackCompilerOptions(project: Project, module: Module) {
|
||||
private fun rollbackCompilerOptions(project: Project, module: Module) {
|
||||
configureLanguageAndApiVersion(project, module, LanguageVersion.LATEST_STABLE.versionString)
|
||||
|
||||
val facetSettings = KotlinFacet.get(module)!!.configuration.settings
|
||||
|
||||
Reference in New Issue
Block a user