Skip to content

Commit 50cd733

Browse files
committed
bugfix: issue #347 - improved interoperability with Windows, but not yet fixed
feature: improved test suite
1 parent 4197a46 commit 50cd733

File tree

4 files changed

+48
-33
lines changed

4 files changed

+48
-33
lines changed

src/main/kotlin/kscript/app/model/ConfigBuilder.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import kscript.app.util.ShellUtils.guessKotlinHome
44
import java.io.File
55
import java.nio.file.Path
66
import java.nio.file.Paths
7+
import kotlin.io.path.absolute
78

89
class ConfigBuilder internal constructor() {
910
var selfName: String = System.getenv("CUSTOM_KSCRIPT_NAME") ?: "kscript"
1011
var kscriptDir: Path = Paths.get(System.getenv("KSCRIPT_DIR") ?: (System.getProperty("user.home")!! + "/.kscript"))
1112
var customPreamble: String = System.getenv("CUSTOM_KSCRIPT_PREAMBLE") ?: ""
1213
var intellijCommand: String = System.getenv("KSCRIPT_IDEA_COMMAND") ?: "idea"
1314
var gradleCommand: String = System.getenv("KSCRIPT_GRADLE_COMMAND") ?: "gradle"
14-
var kotlinHome: Path? = (System.getenv("KOTLIN_HOME") ?: guessKotlinHome())?.let { Paths.get(it) }
15+
var kotlinHome: Path? = (System.getenv("KOTLIN_HOME") ?: guessKotlinHome())?.let { Paths.get(it).absolute() }
1516
var classPathSeparator: String = if (System.getProperty("os.name").lowercase().contains("windows")) ";" else ":"
1617
var separatorChar: Char = File.separatorChar
1718
var homeDir: Path = Paths.get(System.getProperty("user.home")!!)

src/main/kotlin/kscript/app/resolver/CommandResolver.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import kscript.app.model.KotlinOpt
77
import kscript.app.model.Script
88
import java.nio.file.Path
99
import java.nio.file.Paths
10-
import kotlin.io.path.absolute
1110
import kotlin.io.path.absolutePathString
1211
import kotlin.io.path.div
1312

1413
class CommandResolver(private val config: Config, private val script: Script) {
1514
fun compileKotlin(jar: Path, dependencies: Set<Path>, filePaths: Set<Path>): String {
1615
val compilerOptsStr = resolveCompilerOpts(script.compilerOpts)
1716
val classpath = resolveClasspath(dependencies)
18-
val files = filePaths.joinToString(" ") { it.absolute().toString() }
17+
val files = filePaths.joinToString(" ") { "'${it.absolutePathString()}'" }
1918

20-
val kotlinc = if (config.kotlinHome != null) (config.kotlinHome / "bin" / "kotlinc").toString() else "kotlinc"
19+
val kotlinc =
20+
if (config.kotlinHome != null) (config.kotlinHome / "bin" / "kotlinc").absolutePathString() else "kotlinc"
2121

22-
return "$kotlinc $compilerOptsStr $classpath -d '${jar.absolute()}' $files"
22+
return "'$kotlinc' $compilerOptsStr $classpath -d '${jar.absolutePathString()}' $files"
2323
}
2424

2525
fun executeKotlin(jarArtifact: JarArtifact, dependencies: Set<Path>, userArgs: List<String>): String {
@@ -64,6 +64,6 @@ class CommandResolver(private val config: Config, private val script: Script) {
6464
private fun resolveUserArgs(userArgs: List<String>) =
6565
userArgs.joinToString(" ") { "\"${it.replace("\"", "\\\"")}\"" }
6666

67-
private fun resolveClasspath(dependencies: Set<Path>) =
68-
if (dependencies.isEmpty()) "" else "-classpath " + dependencies.joinToString(config.classPathSeparator) { it.absolutePathString() }
67+
private fun resolveClasspath(dependencies: Set<Path>) = if (dependencies.isEmpty()) ""
68+
else "-classpath " + dependencies.joinToString(config.classPathSeparator) { "'${it.absolutePathString()}'" }
6969
}

test/setup_environment.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ assert_stderr(){
5151
assert "( $1 ) 2>&1 >/dev/null" "$2"
5252
}
5353

54+
# $1 - suite name; $2 - requested suites
55+
start_suite() {
56+
if [[ "${2}" =~ "${1}" ]] || [[ "${2}" == "ALL" ]]; then
57+
echo
58+
echo "Starting '$1' tests:"
59+
return 0
60+
fi
61+
62+
echo "Skipping '$1' tests..."
63+
return 1
64+
}
65+
5466
#http://stackoverflow.com/questions/3005963/how-can-i-have-a-newline-in-a-string-in-sh
5567
export NL=$'\n'
5668

test/test_suite.sh

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
11
#!/usr/bin/env bash
22

3-
# Provide suite names which you want to execute as a parameter or nothing if you want to execute all
3+
# Provide suite names which you want to execute as a parameter
4+
# Example:
5+
# no parameters or 'ALL' - execute all test suites
6+
# '-' (dash) - just compile - no suites executed
7+
# 'junit' - execute just unit tests
48

59
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
610
PROJECT_DIR=$(realpath "$SCRIPT_DIR/../")
711

8-
echo "Starting KScript test suite..."
9-
10-
REQUESTED_SUITES=${1:-ALL}
11-
echo "Requested test suites: $REQUESTED_SUITES"
12-
13-
# $1 - suite name; $2 - requested suites
14-
start_suite() {
15-
if [[ "${2}" =~ "${1}" ]] || [[ "${2}" == "ALL" ]]; then
16-
echo
17-
echo "Starting $1 tests:"
18-
return 0
19-
fi
20-
21-
echo "Skipping $1 tests..."
22-
return 1
23-
}
12+
REQUESTED_SUITES="${@:-ALL}"
13+
echo "Starting KScript test suites: $REQUESTED_SUITES"
14+
echo
2415

2516
kscript --clear-cache
17+
echo
2618

2719
########################################################################################################################
28-
SUITE="JUnit"
29-
echo
30-
echo "Starting $SUITE test suite... Compiling... Please wait..."
20+
echo "Compiling KScript... Please wait..."
3121

3222
cd $PROJECT_DIR
33-
./gradlew clean build
34-
status=$?
23+
./gradlew clean assemble
24+
EXIT_CODE="$?"
3525
cd -
3626

37-
if [[ "$status" -ne "0" ]]; then
27+
if [[ "$EXIT_CODE" -ne "0" ]]; then
3828
echo
39-
echo "KScript build terminated with invalid exit code $status..."
29+
echo "KScript build terminated with invalid exit code $EXIT_CODE..."
4030
exit 1
4131
fi
4232

43-
echo "$SUITE test suite successfully accomplished."
44-
4533
########################################################################################################################
4634

4735
source "$SCRIPT_DIR/setup_environment.sh"
36+
echo
37+
38+
########################################################################################################################
39+
SUITE="junit"
40+
if start_suite $SUITE $REQUESTED_SUITES; then
41+
cd $PROJECT_DIR
42+
./gradlew test
43+
EXIT_CODE="$?"
44+
cd -
45+
46+
assert "echo $EXIT_CODE" "0"
47+
48+
assert_end "$SUITE"
49+
fi
4850

4951
########################################################################################################################
5052
SUITE="script_input_modes"

0 commit comments

Comments
 (0)