Skip to content

Commit bf689b3

Browse files
#430: Add missingTimezoneTest
1 parent 12f56d9 commit bf689b3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

core/linux/test/TimeZoneNativeTest.kt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import kotlinx.cinterop.allocArray
1212
import kotlinx.cinterop.convert
1313
import kotlinx.cinterop.memScoped
1414
import kotlinx.cinterop.toKString
15+
import kotlinx.datetime.IllegalTimeZoneException
1516
import kotlinx.datetime.TimeZone
1617
import kotlinx.datetime.internal.root
1718
import kotlin.test.Test
1819
import kotlin.test.assertEquals
1920
import platform.posix.*
21+
import kotlin.test.assertFailsWith
22+
import kotlin.test.assertTrue
2023

2124
class TimeZoneNativeTest {
2225

@@ -35,7 +38,7 @@ class TimeZoneNativeTest {
3538

3639
@Test
3740
fun correctSymlinkTest() {
38-
root = "./linux/test/time-zone-native-test-resources/correct-symlink/"
41+
root = "${RESOURCES}correct-symlink/"
3942

4043
println("PWD: ${pwd()}")
4144

@@ -45,9 +48,27 @@ class TimeZoneNativeTest {
4548

4649
@Test
4750
fun fallsBackToUTC() {
48-
root = "./linux/test/time-zone-native-test-resources/missing-localtime/"
51+
root = "${RESOURCES}missing-localtime/"
4952

5053
val tz = TimeZone.currentSystemDefault()
5154
assertEquals(TimeZone.UTC, tz)
5255
}
56+
57+
@Test
58+
fun missingTimezoneTest() {
59+
root = "${RESOURCES}missing-timezone/"
60+
61+
val exception = assertFailsWith<IllegalTimeZoneException> {
62+
TimeZone.currentSystemDefault()
63+
}
64+
65+
assertTrue(
66+
exception.message?.startsWith("Could not determine the timezone ID") == true,
67+
"Exception message did not match"
68+
)
69+
}
70+
71+
companion object {
72+
const val RESOURCES = "./linux/test/time-zone-native-test-resources/"
73+
}
5374
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/tmp

0 commit comments

Comments
 (0)