Skip to content

Commit 21cad73

Browse files
committed
Test fixes
Signed-off-by: Marcin Kuszczak <1508798+aartiPl@users.noreply.github.com>
1 parent fad84fe commit 21cad73

3 files changed

Lines changed: 30 additions & 27 deletions

File tree

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package io.github.kscripting.kscript.integration
22

3+
import io.github.kscripting.kscript.integration.tools.TestAssertion
4+
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
5+
import org.junit.jupiter.api.Tag
6+
import org.junit.jupiter.api.Test
7+
38
class CliReplTest : TestBase {
4-
fun `CLI REPL tests`() {
9+
@Test
10+
@Tag("posix")
11+
@Tag("windows")
12+
fun `Do not run interactive mode prep without script argument`() {
13+
verify("kscript -i", 1, "", TestAssertion.startsWith("kscript - Enhanced scripting support for Kotlin"))
14+
}
15+
16+
// fun `CLI REPL tests`() {
517
// ## interactive mode without dependencies
618
// #assert "kscript -i 'exitProcess(0)'" "To create a shell with script dependencies run:\nkotlinc -classpath ''"
719
// #assert "echo '' | kscript -i -" "To create a shell with script dependencies run:\nkotlinc -classpath ''"
@@ -10,5 +22,5 @@ class CliReplTest : TestBase {
1022
// ## first version is disabled because support-auto-prefixing kicks in
1123
// #assert "kscript -i '//DEPS log4j:log4j:1.2.14'" "To create a shell with script dependencies run:\nkotlinc -classpath '${HOME}/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar'"
1224
// #assert "kscript -i <(echo '//DEPS log4j:log4j:1.2.14')" "To create a shell with script dependencies run:\nkotlinc -classpath '${HOME}/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar'"
13-
}
25+
// }
1426
}

src/integration/kotlin/io/github/kscripting/kscript/integration/EnvironmentTest.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
package io.github.kscripting.kscript.integration
22

3-
import io.github.kscripting.kscript.integration.tools.TestAssertion.startsWith
43
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
54
import io.github.kscripting.kscript.integration.tools.TestContext.projectDir
65
import org.junit.jupiter.api.Tag
76
import org.junit.jupiter.api.Test
87

98
class EnvironmentTest : TestBase {
10-
@Test
11-
@Tag("posix")
12-
@Tag("windows")
13-
fun `Do not run interactive mode prep without script argument`() {
14-
verify("kscript -i", 1, "", startsWith("kscript - Enhanced scripting support for Kotlin"))
15-
}
16-
179
@Test
1810
@Tag("posix")
1911
@Tag("windows")
2012
fun `Make sure that KOTLIN_HOME can be guessed from kotlinc correctly`() {
21-
verify("echo 'println(99)' | kscript -", 0, "99\n") { env -> env.remove("KOTLIN_HOME") }
13+
verify("kscript \"println(99)\"", 0, "99\n") { env -> env.remove("KOTLIN_HOME") }
2214
}
2315

2416
//TODO: test what happens if kotlin/kotlinc/java/gradle/idea is not in PATH

src/main/kotlin/io/github/kscripting/kscript/model/ConfigBuilder.kt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import kotlin.io.path.reader
77

88
@Suppress("MemberVisibilityCanBePrivate")
99
class ConfigBuilder(
10-
private val osType: OsType,
11-
private val systemProperties: Properties,
12-
private val environment: Map<String, String?>
10+
private val osType: OsType, private val systemProperties: Properties, private val environment: Map<String, String?>
1311
) {
1412
var userHomeDir: OsPath? = null
1513
var tempDir: OsPath? = null
@@ -27,11 +25,16 @@ class ConfigBuilder(
2725
var repositoryPassword: String? = null
2826
var artifactsDir: OsPath? = null
2927

30-
//Env variables paths read by Java are always in native format; All paths should be stored in Config as native,
28+
//Java properties paths are always in native format. All paths should be stored in Config as native,
3129
//and then converted to shell format as needed.
32-
//private fun path(path: String) = OsPath.createOrThrow(OsType.native, path)
3330
private fun String.toOsPathFromNative() = OsPath.createOrThrow(OsType.native, this)
34-
private fun String.toOsPathFromOsSpecific(osType: OsType) = OsPath.createOrThrow(osType, this).toNativeOsPath()
31+
private fun String.toOsPathFromOsSpecific(osType: OsType) = OsPath.createOrThrow(osType, this)
32+
private fun String.toOsPathFromEnvVariable(osType: OsType) = when (osType) {
33+
//MSYS automatically converts any path in env to windows format
34+
OsType.MSYS -> OsPath.createOrThrow(OsType.native, this)
35+
else -> OsPath.createOrThrow(osType, this)
36+
}.toNativeOsPath()
37+
3538
private fun Properties.getPropertyOrNull(name: String) = this.getProperty(name).nullIfBlank()
3639
private fun Map<String, String?>.getEnvVariableOrNull(name: String) = this[name].nullIfBlank()
3740
private fun String?.nullIfBlank() = if (this.isNullOrBlank()) null else this
@@ -46,7 +49,7 @@ class ConfigBuilder(
4649
val selfName: String = selfName ?: environment.getEnvVariableOrNull("KSCRIPT_NAME") ?: "kscript"
4750

4851
val kscriptDir: OsPath? =
49-
kscriptDir ?: environment.getEnvVariableOrNull("KSCRIPT_DIRECTORY")?.toOsPathFromNative()
52+
kscriptDir ?: environment.getEnvVariableOrNull("KSCRIPT_DIRECTORY")?.toOsPathFromEnvVariable(osType)
5053

5154
val cacheDir: OsPath = cacheDir ?: kscriptDir?.resolve("cache") ?: when {
5255
osType.isWindowsLike() -> environment.getEnvVariableOrNull("LOCALAPPDATA")?.toOsPathFromNative() ?: tempDir
@@ -63,6 +66,7 @@ class ConfigBuilder(
6366
val configFile: OsPath = configFile ?: kscriptDir?.resolve("kscript.properties") ?: when {
6467
osType.isWindowsLike() -> environment.getEnvVariableOrNull("LOCALAPPDATA")?.toOsPathFromNative()
6568
?: userHomeDir.resolve(".config")
69+
6670
osType == OsType.MACOS -> userHomeDir.resolve("Library", "Application Support")
6771
else -> environment.getEnvVariableOrNull("XDG_CONFIG_DIR")?.toOsPathFromNative()
6872
?: userHomeDir.resolve(".config")
@@ -108,17 +112,12 @@ class ConfigBuilder(
108112
val repositoryPassword = repositoryPassword ?: environment.getEnvVariableOrNull("KSCRIPT_REPOSITORY_PASSWORD")
109113
?: configProperties.getPropertyOrNull("scripting.repository.password") ?: ""
110114

111-
val artifactsDir: OsPath? =
112-
artifactsDir ?: environment.getEnvVariableOrNull("KSCRIPT_DIRECTORY_ARTIFACTS")?.toOsPathFromOsSpecific(osType)
113-
?: configProperties.getPropertyOrNull("scripting.directory.artifacts")?.toOsPathFromOsSpecific(osType)
115+
val artifactsDir: OsPath? = artifactsDir ?: environment.getEnvVariableOrNull("KSCRIPT_DIRECTORY_ARTIFACTS")
116+
?.toOsPathFromEnvVariable(osType) ?: configProperties.getPropertyOrNull("scripting.directory.artifacts")
117+
?.toOsPathFromOsSpecific(osType)
114118

115119
val scriptingConfig = ScriptingConfig(
116-
customPreamble,
117-
providedKotlinOpts,
118-
repositoryUrl,
119-
repositoryUser,
120-
repositoryPassword,
121-
artifactsDir
120+
customPreamble, providedKotlinOpts, repositoryUrl, repositoryUser, repositoryPassword, artifactsDir
122121
)
123122

124123
return Config(osConfig, scriptingConfig)

0 commit comments

Comments
 (0)