[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
This commit is contained in:
Anton Lakotka
2022-12-09 14:51:23 +01:00
committed by Space Team
parent f09fb5ed09
commit a37b548b9f
@@ -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<String> = 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<String> = 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")
)
}
}