Skip to content

Commit fad84fe

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

5 files changed

Lines changed: 42 additions & 24 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import org.junit.jupiter.api.Test
99
class EnvironmentTest : TestBase {
1010
@Test
1111
@Tag("posix")
12+
@Tag("windows")
1213
fun `Do not run interactive mode prep without script argument`() {
1314
verify("kscript -i", 1, "", startsWith("kscript - Enhanced scripting support for Kotlin"))
1415
}
1516

1617
@Test
1718
@Tag("posix")
19+
@Tag("windows")
1820
fun `Make sure that KOTLIN_HOME can be guessed from kotlinc correctly`() {
19-
verify("unset KOTLIN_HOME; echo 'println(99)' | kscript -", 0, "99\n")
21+
verify("echo 'println(99)' | kscript -", 0, "99\n") { env -> env.remove("KOTLIN_HOME") }
2022
}
2123

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

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.github.kscripting.kscript.integration
33
import io.github.kscripting.kscript.integration.tools.TestAssertion.any
44
import io.github.kscripting.kscript.integration.tools.TestAssertion.contains
55
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
6-
import io.github.kscripting.kscript.integration.tools.TestContext.osType
76
import io.github.kscripting.kscript.integration.tools.TestContext.projectDir
87
import io.github.kscripting.kscript.integration.tools.TestContext.resolvePath
98
import io.github.kscripting.kscript.integration.tools.TestContext.testDir
@@ -90,18 +89,13 @@ class MiscTest : TestBase {
9089
fun `Test local jar dir referenced in ENV variable`() {
9190
val shellPath = resolvePath("$projectDir/test/resources/config/")
9291

93-
94-
val envSetter = if (osType.isWindowsLike()) {
95-
"set KSCRIPT_DIRECTORY_ARTIFACTS=${shellPath.resolve("jars")} &&"
96-
} else {
97-
"KSCRIPT_DIRECTORY_ARTIFACTS=${shellPath.resolve("jars")}"
98-
}
99-
10092
verify(
101-
"$envSetter kscript ${shellPath.resolve("script_with_local_jars.kts")}",
93+
"kscript ${shellPath.resolve("script_with_local_jars.kts")}",
10294
0,
10395
"I am living in Test1 class...\nAnd I come from Test2 class...\n",
10496
""
105-
)
97+
) { env ->
98+
env["KSCRIPT_DIRECTORY_ARTIFACTS"] = shellPath.resolve("jars").stringPath()
99+
}
106100
}
107101
}

src/integration/kotlin/io/github/kscripting/kscript/integration/tools/TestAssertion.kt

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.github.kscripting.kscript.integration.tools
22

33
import io.github.kscripting.kscript.integration.tools.TestContext.runProcess
44
import io.github.kscripting.shell.model.GobbledProcessResult
5+
import io.github.kscripting.shell.process.EnvAdjuster
56

67
object TestAssertion {
78
fun <T : Any> geq(value: T) = GenericEquals(value)
@@ -15,20 +16,34 @@ object TestAssertion {
1516
command: String,
1617
exitCode: Int = 0,
1718
stdOut: TestMatcher<String>,
18-
stdErr: String = ""
19-
): GobbledProcessResult =
20-
verify(command, exitCode, stdOut, eq(stdErr))
19+
stdErr: String = "",
20+
envAdjuster: EnvAdjuster = {}
21+
): GobbledProcessResult = verify(command, exitCode, stdOut, eq(stdErr), envAdjuster)
2122

22-
fun verify(command: String, exitCode: Int = 0, stdOut: String, stdErr: TestMatcher<String>): GobbledProcessResult =
23-
verify(command, exitCode, eq(stdOut), stdErr)
23+
fun verify(
24+
command: String,
25+
exitCode: Int = 0,
26+
stdOut: String,
27+
stdErr: TestMatcher<String>,
28+
envAdjuster: EnvAdjuster = {}
29+
): GobbledProcessResult = verify(command, exitCode, eq(stdOut), stdErr, envAdjuster)
2430

25-
fun verify(command: String, exitCode: Int = 0, stdOut: String = "", stdErr: String = ""): GobbledProcessResult =
26-
verify(command, exitCode, eq(stdOut), eq(stdErr))
31+
fun verify(
32+
command: String,
33+
exitCode: Int = 0,
34+
stdOut: String = "",
35+
stdErr: String = "",
36+
envAdjuster: EnvAdjuster = {}
37+
): GobbledProcessResult = verify(command, exitCode, eq(stdOut), eq(stdErr), envAdjuster)
2738

2839
fun verify(
29-
command: String, exitCode: Int = 0, stdOut: TestMatcher<String>, stdErr: TestMatcher<String>
40+
command: String,
41+
exitCode: Int = 0,
42+
stdOut: TestMatcher<String>,
43+
stdErr: TestMatcher<String>,
44+
envAdjuster: EnvAdjuster = {}
3045
): GobbledProcessResult {
31-
val processResult = runProcess(command)
46+
val processResult = runProcess(command, envAdjuster)
3247
val extCde = geq(exitCode)
3348

3449
extCde.checkAssertion("ExitCode", processResult.exitCode)

src/integration/kotlin/io/github/kscripting/kscript/integration/tools/TestContext.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import io.github.kscripting.kscript.util.ShellUtils
44
import io.github.kscripting.kscript.util.ShellUtils.which
55
import io.github.kscripting.shell.ShellExecutor
66
import io.github.kscripting.shell.model.*
7+
import io.github.kscripting.shell.process.EnvAdjuster
78

89
object TestContext {
9-
val osType: OsType = OsType.findOrThrow(System.getProperty("osType"))
10+
private val osType: OsType = OsType.findOrThrow(System.getProperty("osType"))
1011
private val nativeType = if (osType.isPosixHostedOnWindows()) OsType.WINDOWS else osType
1112

1213
private val projectPath: OsPath = OsPath.createOrThrow(nativeType, System.getProperty("projectPath"))
@@ -37,15 +38,21 @@ object TestContext {
3738
return OsPath.createOrThrow(osType, path)
3839
}
3940

40-
fun runProcess(command: String): GobbledProcessResult {
41+
fun runProcess(command: String, envAdjuster: EnvAdjuster): GobbledProcessResult {
4142
//In MSYS all quotes should be single quotes, otherwise content is interpreted e.g. backslashes.
4243
//(MSYS bash interpreter is also replacing double quotes into the single quotes: see: bash -xc 'kscript "println(1+1)"')
4344
val newCommand = when {
4445
osType.isPosixHostedOnWindows() -> command.replace('"', '\'')
4546
else -> command
4647
}
4748

48-
val result = ShellExecutor.evalAndGobble(osType, newCommand, null, ::adjustEnv)
49+
fun internalEnvAdjuster(map: MutableMap<String, String>) {
50+
ShellUtils.environmentAdjuster(map)
51+
map[pathEnvName] = envPath
52+
envAdjuster(map)
53+
}
54+
55+
val result = ShellExecutor.evalAndGobble(osType, newCommand, null, ::internalEnvAdjuster)
4956
println(result)
5057

5158
return result

src/main/kotlin/io/github/kscripting/kscript/util/FileUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ object FileUtils {
6565
}
6666
}
6767

68-
return artifacts.sortedBy { it.leaf }
68+
return artifacts.sortedBy { it.stringPath() }
6969
}
7070
}

0 commit comments

Comments
 (0)