-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: use kotlinx-io to read resource files (#114)
klio (which we used to read files) is not maintained anymore.
- Loading branch information
Showing
5 changed files
with
48 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/src/commonTest/kotlin/fr/acinq/secp256k1/TestHelpers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fr.acinq.secp256k1 | ||
|
||
import kotlinx.io.buffered | ||
import kotlinx.io.files.Path | ||
import kotlinx.io.files.SystemFileSystem | ||
import kotlinx.io.readByteArray | ||
import kotlinx.io.readString | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.JsonElement | ||
|
||
object TestHelpers { | ||
val resourcesPath = Path(readEnvironmentVariable("TEST_RESOURCES_PATH")?: "src/commonTest/resources") | ||
|
||
fun readResourceAsJson(filename: String): JsonElement { | ||
val raw = SystemFileSystem.source(Path(resourcesPath, filename)).buffered().readString() | ||
val format = Json { ignoreUnknownKeys = true } | ||
return format.parseToJsonElement(raw) | ||
} | ||
|
||
|
||
fun readResourceAsByteArray(filename: String): ByteArray { | ||
return SystemFileSystem.source(Path(resourcesPath, filename)).buffered().readByteArray() | ||
} | ||
} | ||
|
||
expect fun readEnvironmentVariable(name: String): String? |
5 changes: 5 additions & 0 deletions
5
tests/src/jvmTest/kotlin/fr/acinq/secp256k1/TestHelpers.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package fr.acinq.secp256k1 | ||
|
||
actual fun readEnvironmentVariable(name: String): String? { | ||
return System.getenv(name) | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/src/nativeTest/kotlin/fr/acinq/secp256k1/TestHelpers.native.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package fr.acinq.secp256k1 | ||
|
||
import platform.posix.* | ||
import kotlinx.cinterop.* | ||
|
||
@OptIn(ExperimentalForeignApi::class) | ||
actual fun readEnvironmentVariable(name: String): String? { | ||
return getenv(name)?.toKString() | ||
} |