From a37b548b9fd7230e88a97d20f87b7db502717a91 Mon Sep 17 00:00:00 2001 From: Anton Lakotka Date: Fri, 9 Dec 2022 14:51:23 +0100 Subject: [PATCH] [Gradle, Test] Reset locale to default when changing it for tests Since `Locale.setDefault` is a global operation it will take effect on other test causing them to produce unexpectable results. ^KT-38712 --- .../kotlin/gradle/ConfigurationsTest.kt | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt index aeaa7db88b6..ad33572e023 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt @@ -382,32 +382,42 @@ class ConfigurationsTest : MultiplatformExtensionTest() { */ @Test fun `gradle entities should have correct names when default locale is turkish`() { - Locale.setDefault(Locale("tr", "TR")) - - val project = buildProjectWithMPP { - kotlin { - jvm() - ios() + fun withLocale(locale: Locale, code: () -> Unit) { + val currentLocal = Locale.getDefault() + try { + Locale.setDefault(locale) + code() + } finally { + Locale.setDefault(currentLocal) } } - project.evaluate() - val gradleEntityNames: List = with (project) { - listOf( - tasks.names, - configurations.names, - components.names, - extensions.asMap.keys, - kotlin.sourceSets.names, - kotlin.targets.names, - ).flatten() + withLocale(Locale("tr", "TR")) { + val project = buildProjectWithMPP { + kotlin { + jvm() + ios() + } + } + project.evaluate() + + val gradleEntityNames: List = with(project) { + listOf( + tasks.names, + configurations.names, + components.names, + extensions.asMap.keys, + kotlin.sourceSets.names, + kotlin.targets.names, + ).flatten() + } + + val entityNamesWithTurkishI = gradleEntityNames.filter { it.contains('İ') || it.contains('ı') } + assertTrue( + entityNamesWithTurkishI.isEmpty(), + "Following entities should not have turkish 'İ' or 'ı' in their names:\n" + + entityNamesWithTurkishI.joinToString("\n") + ) } - - val entityNamesWithTurkishI = gradleEntityNames.filter { it.contains('İ') || it.contains('ı') } - assertTrue( - entityNamesWithTurkishI.isEmpty(), - "Following entities should not have turkish 'İ' or 'ı' in their names:\n" + - entityNamesWithTurkishI.joinToString("\n") - ) } } \ No newline at end of file