11#! /usr/bin/env bash
22# /bin/bash -x
33
4+ SCRIPT_DIR=" $( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
5+ PROJECT_DIR=$( realpath $SCRIPT_DIR /../)
6+
7+ echo " Starting KScript test suite..."
8+ echo " Script dir : $SCRIPT_DIR "
9+ echo " Project dir: $PROJECT_DIR "
10+ echo
11+
412export DEBUG=" --verbose"
513
614. assert.sh
@@ -21,16 +29,16 @@ assert_stderr(){
2129}
2230# assert_stderr "echo foo" "bar"
2331
24- # http://stackoverflow.com/questions/3005963/how-can-i-have-a-newline-in-a-string-in-sh
2532# http://stackoverflow.com/questions/3005963/how-can-i-have-a-newline-in-a-string-in-sh
2633export NL=$' \n '
2734
2835
2936# #######################################################################################################################
30- # # script_input_modes
37+ echo
38+ echo " Starting script input modes tests:"
3139
3240# # make sure that scripts can be piped into kscript
33- assert " source ${KSCRIPT_HOME } /test/resources/direct_script_arg.sh" " kotlin rocks"
41+ assert " source ${PROJECT_DIR } /test/resources/direct_script_arg.sh" " kotlin rocks"
3442
3543# # also allow for empty programs
3644assert " kscript ''" " "
@@ -51,25 +59,24 @@ assert "echo 'println(1+1)' | kscript -" "2"
5159assert " echo 'println(1+3)' | kscript - --foo" " 4"
5260
5361# # make sure that heredoc is accepted as argument
54- assert " source ${KSCRIPT_HOME } /test/resources/here_doc_test.sh" " hello kotlin"
62+ assert " source ${PROJECT_DIR } /test/resources/here_doc_test.sh" " hello kotlin"
5563
5664# # make sure that command substitution works as expected
57- assert " source ${KSCRIPT_HOME } /test/resources/cmd_subst_test.sh" " command substitution works as well"
65+ assert " source ${PROJECT_DIR } /test/resources/cmd_subst_test.sh" " command substitution works as well"
5866
5967# # make sure that it runs with local script files
60- assert " source ${KSCRIPT_HOME } /test/resources/local_script_file.sh" " kscript rocks!"
68+ assert " source ${PROJECT_DIR } /test/resources/local_script_file.sh" " kscript rocks!"
6169# assert "echo foo" "bar" # known to fail
6270
6371# # make sure that it runs with local script files
64- assert " kscript ${KSCRIPT_HOME } /test/resources/multi_line_deps.kts" " kscript is cool!"
72+ assert " kscript ${PROJECT_DIR } /test/resources/multi_line_deps.kts" " kscript is cool!"
6573
6674# # scripts with dashes in the file name should work as well
67- assert " kscript ${KSCRIPT_HOME } /test/resources/dash-test.kts" " dash alarm!"
75+ assert " kscript ${PROJECT_DIR } /test/resources/dash-test.kts" " dash alarm!"
6876
6977# # scripts with additional dots in the file name should work as well.
7078# # We also test innner uppercase letters in file name here by using .*T*est
71- assert " kscript ${KSCRIPT_HOME} /test/resources/dot.Test.kts" " dot alarm!"
72-
79+ assert " kscript ${PROJECT_DIR} /test/resources/dot.Test.kts" " dot alarm!"
7380
7481# # missing script
7582assert_raises " kscript i_do_not_exist.kts" 1
@@ -81,17 +88,16 @@ assert "kscript https://git.io/fxHBv" "main was called"
8188
8289# # there are some dependencies which are not jar, but maybe pom, aar, ..
8390# # make sure they work, too
84- assert " kscript ${KSCRIPT_HOME } /test/resources/depends_on_with_type.kts" " getBigDecimal(1L): 1"
91+ assert " kscript ${PROJECT_DIR } /test/resources/depends_on_with_type.kts" " getBigDecimal(1L): 1"
8592
8693# repeated compilation of buggy same script should end up in error again
8794assert_raises " kscript '1-'; kscript '1-'" 1
8895
8996assert_end script_input_modes
9097
91-
92-
9398# #######################################################################################################################
94- # # cli_helper_tests
99+ echo
100+ echo " Starting cli helper tests:"
95101
96102# # interactive mode without dependencies
97103# assert "kscript -i 'exitProcess(0)'" "To create a shell with script dependencies run:\nkotlinc -classpath ''"
@@ -105,7 +111,8 @@ assert_end script_input_modes
105111# assert_end cli_helper_tests
106112
107113# #######################################################################################################################
108- # # environment_tests
114+ echo
115+ echo " Starting environment tests:"
109116
110117# # do not run interactive mode prep without script argument
111118assert_raises " kscript -i" 1
@@ -116,20 +123,19 @@ assert "unset KOTLIN_HOME; echo 'println(99)' | kscript -" "99"
116123# # todo test what happens if kotlin/kotlinc/java/maven is not in PATH
117124
118125# # run script that tries to find out its own filename via environment variable
119- f=" ${KSCRIPT_HOME } /test/resources/uses_self_file_name.kts"
126+ f=" ${PROJECT_DIR } /test/resources/uses_self_file_name.kts"
120127assert " $f " " Usage: $f [-ae] [--foo] file+"
121128
122129
123130assert_end environment_tests
124131
125132# #######################################################################################################################
126- # # dependency_lookup
133+ echo
134+ echo " Starting dependency lookup tests:"
127135
128- # export KSCRIPT_HOME="/Users/brandl/projects/kotlin/kscript"; export PATH=${KSCRIPT_HOME}:${PATH}
129- resolve_deps () { kotlin -classpath ${KSCRIPT_HOME} /build/libs/kscript.jar kscript.app.DependencyUtil " $@ " ; }
136+ resolve_deps () { kotlin -classpath ${PROJECT_DIR} /build/libs/kscript.jar kscript.app.DependencyUtil " $@ " ; }
130137export -f resolve_deps
131138
132-
133139assert_stderr " resolve_deps log4j:log4j:1.2.14" " ${HOME} /.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar"
134140
135141# # impossible version
@@ -149,33 +155,35 @@ assert_raises "resolve_deps org.org.docopt:org.docopt:0.9.0-SNAPSHOT log4j:log4j
149155assert_end dependency_lookup
150156
151157# #######################################################################################################################
152- # # annotation-driven configuration
158+ echo
159+ echo " Starting annotation-driven configuration tests:"
153160
154161# make sure that @file:DependsOn is parsed correctly
155- assert " kscript ${KSCRIPT_HOME } /test/resources/depends_on_annot.kts" " kscript with annotations rocks!"
162+ assert " kscript ${PROJECT_DIR } /test/resources/depends_on_annot.kts" " kscript with annotations rocks!"
156163
157164# make sure that @file:DependsOnMaven is parsed correctly
158- assert " kscript ${KSCRIPT_HOME } /test/resources/depends_on_maven_annot.kts" " kscript with annotations rocks!"
165+ assert " kscript ${PROJECT_DIR } /test/resources/depends_on_maven_annot.kts" " kscript with annotations rocks!"
159166
160167# make sure that dynamic versions are matched properly
161- assert " kscript ${KSCRIPT_HOME } /test/resources/depends_on_dynamic.kts" " dynamic kscript rocks!"
168+ assert " kscript ${PROJECT_DIR } /test/resources/depends_on_dynamic.kts" " dynamic kscript rocks!"
162169
163170# make sure that @file:MavenRepository is parsed correctly
164- assert " kscript ${KSCRIPT_HOME } /test/resources/custom_mvn_repo_annot.kts" " kscript with annotations rocks!"
171+ assert " kscript ${PROJECT_DIR } /test/resources/custom_mvn_repo_annot.kts" " kscript with annotations rocks!"
165172
166173
167- assert_stderr " kscript ${KSCRIPT_HOME } /test/resources/illegal_depends_on_arg.kts" ' [kscript] [ERROR] Artifact locators must be provided as separate annotation arguments and not as comma-separated list: [com.squareup.moshi:moshi:1.5.0,com.squareup.moshi:moshi-adapters:1.5.0]'
174+ assert_stderr " kscript ${PROJECT_DIR } /test/resources/illegal_depends_on_arg.kts" ' [kscript] [ERROR] Artifact locators must be provided as separate annotation arguments and not as comma-separated list: [com.squareup.moshi:moshi:1.5.0,com.squareup.moshi:moshi-adapters:1.5.0]'
168175
169176
170177# make sure that @file:MavenRepository is parsed correctly
171- assert " kscript ${KSCRIPT_HOME } /test/resources/script_with_compile_flags.kts" " hoo_ray"
178+ assert " kscript ${PROJECT_DIR } /test/resources/script_with_compile_flags.kts" " hoo_ray"
172179
173180
174181assert_end annotation_config
175182
176183
177184# #######################################################################################################################
178- # # support_api
185+ echo
186+ echo " Starting support api tests:"
179187
180188# # make sure that one-liners include support-api
181189assert ' echo "foo${NL}bar" | kscript -t "stdin.print()"' $' foo\n bar'
@@ -190,58 +198,59 @@ assert_end support_api
190198
191199
192200# #######################################################################################################################
193- # # kt support
201+ echo
202+ echo " Starting kt support tests:"
194203
195204# # run kt via interpreter mode
196- assert " ${KSCRIPT_HOME } /test/resources/kt_tests/simple_app.kt" " main was called"
205+ assert " ${PROJECT_DIR } /test/resources/kt_tests/simple_app.kt" " main was called"
197206
198207# # run kt via interpreter mode with dependencies
199- assert " kscript ${KSCRIPT_HOME } /test/resources/kt_tests/main_with_deps.kt" " made it!"
208+ assert " kscript ${PROJECT_DIR } /test/resources/kt_tests/main_with_deps.kt" " made it!"
200209
201210# # test misc entry point with or without package configurations
202211
203- assert " kscript ${KSCRIPT_HOME } /test/resources/kt_tests/custom_entry_nopckg.kt" " foo companion was called"
212+ assert " kscript ${PROJECT_DIR } /test/resources/kt_tests/custom_entry_nopckg.kt" " foo companion was called"
204213
205- assert " kscript ${KSCRIPT_HOME } /test/resources/kt_tests/custom_entry_withpckg.kt" " foo companion was called"
214+ assert " kscript ${PROJECT_DIR } /test/resources/kt_tests/custom_entry_withpckg.kt" " foo companion was called"
206215
207- assert " kscript ${KSCRIPT_HOME } /test/resources/kt_tests/default_entry_nopckg.kt" " main was called"
216+ assert " kscript ${PROJECT_DIR } /test/resources/kt_tests/default_entry_nopckg.kt" " main was called"
208217
209- assert " kscript ${KSCRIPT_HOME } /test/resources/kt_tests/default_entry_withpckg.kt" " main was called"
218+ assert " kscript ${PROJECT_DIR } /test/resources/kt_tests/default_entry_withpckg.kt" " main was called"
210219
211220
212221# # also make sure that kts in package can be run via kscript
213- assert " ${KSCRIPT_HOME} /test/resources/script_in_pckg.kts" " I live in a package!"
214-
215-
222+ assert " ${PROJECT_DIR} /test/resources/script_in_pckg.kts" " I live in a package!"
216223
217224# # can we resolve relative imports when using tmp-scripts (see #95)
218- assert " rm -f ./ package_example && kscript --package test/resources/package_example.kts &>/dev/null && . /package_example 1" " package_me_args_1_mem_5368709120"
225+ assert " rm -f ${PROJECT_DIR} /test/ package_example && kscript --package ${PROJECT_DIR} / test/resources/package_example.kts &>/dev/null && ${PROJECT_DIR} /test /package_example 1" " package_me_args_1_mem_5368709120"
219226
220227# # https://unix.stackexchange.com/questions/17064/how-to-print-only-last-column
221- assert ' rm -f kscriptlet* && cmd=$(kscript --package "println(args.size)" 2>&1 | tail -n1 | cut -f 5 -d " ") && $cmd three arg uments' " 3"
228+ assert ' rm -f kscriptlet* && cmd=$(kscript --package "println(args.size)" 2>&1 | tail -n1 | cut -f 5 -d " ") && $cmd three arg uments' " 3"
222229
223230# assert "kscript --package test/resources/package_example.kts" "foo"
224231# assert "./package_example 1" "package_me_args_1_mem_4772593664"da
225232# assert "echo 1" "package_me_args_1_mem_4772593664"
226233# assert_statement 'rm -f kscriptlet* && kscript --package "println(args.size)"' "foo" "bar" 0
227234
228235
229-
230236# #######################################################################################################################
231- # # custom interpreters
237+ echo
238+ echo " Starting custom interpreters tests:"
232239
233- export PATH=${PATH} :${KSCRIPT_HOME } /test/resources/custom_dsl
240+ export PATH=${PATH} :${PROJECT_DIR } /test/resources/custom_dsl
234241
235242assert ' mydsl "println(foo)"' " bar"
236243
237- assert ' ${KSCRIPT_HOME }/test/resources/custom_dsl/mydsl_test_with_deps.kts' " foobar"
244+ assert ' ${PROJECT_DIR }/test/resources/custom_dsl/mydsl_test_with_deps.kts' " foobar"
238245
239246assert_end custom_interpreters
240247
241248
242249
243250# #######################################################################################################################
244- # # misc
251+ echo
252+ echo " Starting misc tests:"
253+
245254
246255# # prevent regressions of #98 (it fails to process empty or space-containing arguments)
247256assert ' kscript "println(args.size)" foo bar' 2 # # regaular args
@@ -255,43 +264,47 @@ assert 'echo "println(123)" > 123foo.kts; kscript 123foo.kts' "123"
255264
256265
257266# # prevent regression of #185
258- assert " source ${KSCRIPT_HOME } /test/resources/home_dir_include.sh" " 42"
267+ assert " source ${PROJECT_DIR } /test/resources/home_dir_include.sh" " 42"
259268
260269# # prevent regression of #173
261- assert " source ${KSCRIPT_HOME } /test/resources/compiler_opts_with_includes.sh" " hello42"
270+ assert " source ${PROJECT_DIR } /test/resources/compiler_opts_with_includes.sh" " hello42"
262271
263272
264- kscript_nocall () { kotlin -classpath ${KSCRIPT_HOME } /build/libs/kscript.jar kscript.app.KscriptKt " $@ " ; }
273+ kscript_nocall () { kotlin -classpath ${PROJECT_DIR } /build/libs/kscript.jar kscript.app.KscriptKt " $@ " ; }
265274export -f kscript_nocall
266275
267276# # temp projects with include symlinks
268- assert_raises ' tmpDir=$(kscript_nocall --idea test/resources/includes/include_variations.kts | cut -f2 -d" " | xargs echo); cd $tmpDir && gradle build' 0
277+ assert_raises ' tmpDir=$(kscript_nocall --idea ${PROJECT_DIR}/ test/resources/includes/include_variations.kts | cut -f2 -d" " | xargs echo); cd $tmpDir && gradle build' 0
269278
270279# # Ensure relative includes with in shebang mode
271- assert_raises " ${KSCRIPT_HOME } /test/resources/includes/shebang_mode_includes" 0
280+ assert_raises " ${PROJECT_DIR } /test/resources/includes/shebang_mode_includes" 0
272281
273282# # support diamond-shaped include schemes (see #133)
274- assert_raises ' tmpDir=$(kscript_nocall --idea test/resources/includes/diamond.kts | cut -f2 -d" " | xargs echo); cd $tmpDir && gradle build' 0
283+ assert_raises ' tmpDir=$(kscript_nocall --idea ${PROJECT_DIR}/ test/resources/includes/diamond.kts | cut -f2 -d" " | xargs echo); cd $tmpDir && gradle build' 0
275284
276285# # todo reenable interactive mode tests using kscript_nocall
277286
278287assert_end misc
279288
280289
281290# #######################################################################################################################
282- # # run junit-test suite
291+ echo
292+ echo " Starting junit suite tests:"
283293
284294# exit code of `true` is expected to be 0 (see https://github.com/lehmannro/assert.sh)
295+ cd $PROJECT_DIR
285296assert_raises " ./gradlew test"
297+ cd $PROJECT_DIR /test
286298
287299assert_end junit_tests
288300
289301
290302# #######################################################################################################################
291- # # bootstrap header
303+ echo
304+ echo " Starting bootstrap headers tests:"
292305
293306f=/tmp/echo_stdin_args.kts
294- cp ${KSCRIPT_HOME } /test/resources/echo_stdin_args.kts $f
307+ cp ${PROJECT_DIR } /test/resources/echo_stdin_args.kts $f
295308
296309# ensure script works as is
297310assert ' echo stdin | ' $f ' --foo bar' " stdin | script --foo bar"
@@ -308,7 +321,6 @@ assert 'echo stdin | '$f' --foo bar' "stdin | script --foo bar"
308321# ensure scripts works with header invoked with explicit `kscript`
309322assert ' echo stdin | kscript ' $f ' --foo bar' " stdin | script --foo bar"
310323
311-
312324rm $f
313325
314326assert_end bootstrap_header
0 commit comments