Skip to content

Commit aa6daab

Browse files
committed
Fixed #32: Script with dash in filename doesn't work
1 parent 3889437 commit aa6daab

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

kscript

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
## note: always use a patch release even if it's 0
4-
KSCRIPT_VERSION=1.5.1
4+
KSCRIPT_VERSION=1.5.2
55

66
## make sure that all requirements (java, kotlinc, maven) to run kscript are met
77
assertInPath(){ if [ -z "$(which $1)" ]; then echo "[ERROR] Could not locate '$1'" 1>&2; exit 1; fi }
@@ -122,6 +122,7 @@ fi
122122

123123
## ... or use a cached version of it if possible
124124
#scriptFile="./test.kts"
125+
#scriptFile="test-script.kts"
125126
scriptFile="$1"
126127
shift
127128

@@ -250,8 +251,8 @@ scriptCheckSum=$(kscript_md5 ${scriptFile})
250251
jarFile=${KSCRIPT_CACHE_DIR}/$(basename ${scriptFile} .kts).${scriptCheckSum}.jar
251252

252253

253-
## capitalize first letter (since this is what kotlin compiler is doing for the wrapper
254-
className=$(basename ${scriptFile} .kts)
254+
## capitalize first letter and get rid of dashes (since this is what kotlin compiler is doing for the wrapper to create a valid java class name)
255+
className=$(basename ${scriptFile} .kts | tr '-' '_')
255256
#className="${className^}" ## disabled because requires bash4 and thus not on macos
256257
className=$(echo ${className:0:1} | tr '[a-z]' '[A-Z]')${className:1}
257258

test/resources/dash-test.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
println("dash alarm!")

test/test_suite.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ assert "source ${KSCRIPT_HOME}/test/resources/local_script_file.sh" "kscript roc
4242
## make sure that it runs with local script files
4343
assert "kscript ${KSCRIPT_HOME}/test/resources/multi_line_deps.kts" "kscript is cool!"
4444

45+
## scripts with dashes in the file name should work as well
46+
assert "kscript ${KSCRIPT_HOME}/test/resources/dash-test.kts" "dash alarm!"
47+
48+
4549
## missing script
4650
assert_raises "kscript i_do_not_exist.kts" 1
4751
assert "kscript i_do_not_exist.kts 2>&1" "[ERROR] Could not open script file 'i_do_not_exist.kts'"

0 commit comments

Comments
 (0)