Skip to content

Commit 403ebf9

Browse files
#430: Replace shouldRunTests check to Testcontainers.runIfAvailable
1 parent fc08cb9 commit 403ebf9

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2019-2025 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.datetime.test
7+
8+
import kotlinx.cinterop.ExperimentalForeignApi
9+
import kotlinx.cinterop.toKString
10+
import platform.posix.getenv
11+
12+
object Testcontainers {
13+
14+
@OptIn(ExperimentalForeignApi::class)
15+
val available: Boolean
16+
get() = getenv("INSIDE_TESTCONTAINERS")?.toKString()?.toBoolean() == true
17+
18+
inline fun runIfAvailable(block: () -> Unit) {
19+
if (available) block() else println("Skipping test that requires testcontainers...")
20+
}
21+
}

core/linux/test/TimeZoneLinuxNativeTest.kt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,13 @@
55

66
package kotlinx.datetime.test
77

8-
import kotlinx.cinterop.ExperimentalForeignApi
9-
import kotlinx.cinterop.toKString
108
import kotlinx.datetime.*
119
import kotlin.test.*
12-
import platform.posix.getenv
1310

1411
class TimeZoneLinuxNativeTest {
1512

16-
private var shouldRunTests = false
17-
18-
@OptIn(ExperimentalForeignApi::class)
19-
@BeforeTest
20-
fun setup() {
21-
shouldRunTests = getenv("INSIDE_TESTCONTAINERS")?.toKString() != null
22-
}
23-
2413
@Test
25-
fun defaultTimeZoneTest() {
26-
if (!shouldRunTests) return
27-
14+
fun defaultTimeZoneTest() = Testcontainers.runIfAvailable {
2815
val tz = TimeZone.currentSystemDefault()
2916
println("TIMEZONE: $tz")
3017
assertEquals(TimeZone.of("Europe/Oslo"), tz)

0 commit comments

Comments
 (0)