Skip to content

Commit b949f14

Browse files
committed
Improved test suite and test execution description.
1 parent 6bc38c4 commit b949f14

File tree

2 files changed

+92
-52
lines changed

2 files changed

+92
-52
lines changed

test/TestsReadme.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
## How to run the unit-tests?
22

3-
4-
We use https://github.com/lehmannro/assert.sh for the tests. To install it just do:
5-
3+
#### 1. Install assert.sh
4+
We use https://github.com/lehmannro/assert.sh for the tests.
65

76
```bash
87
cd ~/bin
98
wget https://raw.githubusercontent.com/lehmannro/assert.sh/master/assert.sh
109
chmod u+x assert.sh
1110
```
1211

12+
#### 2. Install sdkman
13+
SdkMan https://sdkman.io/ is a nice package manager which makes it easy to install software development tools.
14+
15+
16+
```bash
17+
curl -s "https://get.sdkman.io" | bash
18+
```
19+
20+
#### 3. Install java, kotlin and gradle
21+
22+
```bash
23+
sdk install java 11.0.2-open
24+
sdk install kotlin 1.5.31
25+
sdk install gradle 7.2
26+
```
27+
28+
#### 4. Clone repository
29+
Put the cloned repository into $DIR directory.
30+
1331

32+
#### 5. Run test suite
1433
To run the tests, just run the [`test_suite.sh`](test_suite.sh)
1534

35+
```bash
36+
cd $DIR/test
37+
./test_suite.sh
38+
```
39+
40+
#### 6. Check if all tests passed...
41+
42+
---
43+
Useful commands:
44+
1645
```bash
1746
# scp /Users/brandl/projects/kotlin/kscript/kscript bioinfo:/home/brandl/bin/test/kscript/kscript
1847

@@ -38,7 +67,6 @@ which kscript
3867

3968

4069
## clean up the environment
41-
4270
kscript --clear-cache
4371

4472
# configure java and kotlin

test/test_suite.sh

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env bash
2-
#/bin/bash -x
32

43
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
5-
PROJECT_DIR=$(realpath $SCRIPT_DIR/../)
4+
PROJECT_DIR=$(realpath "$SCRIPT_DIR/../")
65

76
echo "Starting KScript test suite..."
87
echo "Script dir : $SCRIPT_DIR"
@@ -32,10 +31,33 @@ assert_stderr(){
3231
#http://stackoverflow.com/questions/3005963/how-can-i-have-a-newline-in-a-string-in-sh
3332
export NL=$'\n'
3433

34+
########################################################################################################################
35+
echo
36+
kscript --clear-cache
37+
38+
########################################################################################################################
39+
SUITE="JUnit"
40+
echo
41+
echo "Starting $SUITE test suite... Compiling... Please wait..."
42+
43+
# exit code of `true` is expected to be 0 (see https://github.com/lehmannro/assert.sh)
44+
cd "$PROJECT_DIR" || exit
45+
assert_raises "./gradlew build"
46+
cd - || exit
47+
48+
assert_end "$SUITE"
3549

3650
########################################################################################################################
3751
echo
38-
echo "Starting script input modes tests:"
52+
echo "Configuring KScript for further testing..."
53+
54+
export PATH=${PROJECT_DIR}/build/libs:$PATH
55+
echo "KScript path for testing: $(which kscript)"
56+
57+
########################################################################################################################
58+
SUITE="script input modes"
59+
echo
60+
echo "Starting $SUITE tests:"
3961

4062
## make sure that scripts can be piped into kscript
4163
assert "source ${PROJECT_DIR}/test/resources/direct_script_arg.sh" "kotlin rocks"
@@ -46,12 +68,10 @@ assert "kscript ''" ""
4668
## provide script as direct argument
4769
assert 'kscript "println(1+1)"' '2'
4870

49-
5071
## use dashed arguments (to prevent regression from https://github.com/holgerbrandl/kscript/issues/59)
5172
assert 'kscript "println(args.joinToString(\"\"))" --arg u ments' '--arguments'
5273
assert 'kscript -s "println(args.joinToString(\"\"))" --arg u ments' '--arguments'
5374

54-
5575
## provide script via stidin
5676
assert "echo 'println(1+1)' | kscript -" "2"
5777

@@ -93,11 +113,12 @@ assert "kscript ${PROJECT_DIR}/test/resources/depends_on_with_type.kts" "getBigD
93113
# repeated compilation of buggy same script should end up in error again
94114
assert_raises "kscript '1-'; kscript '1-'" 1
95115

96-
assert_end script_input_modes
116+
assert_end "$SUITE"
97117

98118
########################################################################################################################
99-
echo
100-
echo "Starting cli helper tests:"
119+
#SUITE="CLI helper"
120+
#echo
121+
#echo "Starting $SUITE tests:"
101122

102123
## interactive mode without dependencies
103124
#assert "kscript -i 'exitProcess(0)'" "To create a shell with script dependencies run:\nkotlinc -classpath ''"
@@ -108,11 +129,12 @@ echo "Starting cli helper tests:"
108129
#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'"
109130
#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'"
110131

111-
#assert_end cli_helper_tests
132+
#assert_end "$SUITE"
112133

113134
########################################################################################################################
135+
SUITE="Environment"
114136
echo
115-
echo "Starting environment tests:"
137+
echo "Starting $SUITE tests:"
116138

117139
## do not run interactive mode prep without script argument
118140
assert_raises "kscript -i" 1
@@ -127,11 +149,12 @@ f="${PROJECT_DIR}/test/resources/uses_self_file_name.kts"
127149
assert "$f" "Usage: $f [-ae] [--foo] file+"
128150

129151

130-
assert_end environment_tests
152+
assert_end "$SUITE"
131153

132154
########################################################################################################################
155+
SUITE="dependency lookup"
133156
echo
134-
echo "Starting dependency lookup tests:"
157+
echo "Starting $SUITE tests:"
135158

136159
resolve_deps() { kotlin -classpath ${PROJECT_DIR}/build/libs/kscript.jar kscript.app.DependencyUtil "$@";}
137160
export -f resolve_deps
@@ -152,11 +175,12 @@ assert_raises "resolve_deps log4j:::1.0" 1
152175
## one good dependency, one wrong
153176
assert_raises "resolve_deps org.org.docopt:org.docopt:0.9.0-SNAPSHOT log4j:log4j:1.2.14" 1
154177

155-
assert_end dependency_lookup
178+
assert_end "$SUITE"
156179

157180
########################################################################################################################
181+
SUITE="annotation-driven configuration"
158182
echo
159-
echo "Starting annotation-driven configuration tests:"
183+
echo "Starting $SUITE tests:"
160184

161185
# make sure that @file:DependsOn is parsed correctly
162186
assert "kscript ${PROJECT_DIR}/test/resources/depends_on_annot.kts" "kscript with annotations rocks!"
@@ -178,28 +202,27 @@ assert_stderr "kscript ${PROJECT_DIR}/test/resources/illegal_depends_on_arg.kts"
178202
assert "kscript ${PROJECT_DIR}/test/resources/script_with_compile_flags.kts" "hoo_ray"
179203

180204

181-
assert_end annotation_config
205+
assert_end "$SUITE"
182206

183207

184208
########################################################################################################################
209+
SUITE="support API"
185210
echo
186-
echo "Starting support api tests:"
211+
echo "Starting $SUITE tests:"
187212

188213
## make sure that one-liners include support-api
189214
assert 'echo "foo${NL}bar" | kscript -t "stdin.print()"' $'foo\nbar'
190215
assert 'echo "foo${NL}bar" | kscript -t "lines.print()"' $'foo\nbar'
191216
#echo "$'foo\nbar' | kscript 'lines.print()'
192217

193-
194-
195218
assert_statement 'echo "foo${NL}bar" | kscript --text "lines.split().select(1, 2, -3)"' "" "[ERROR] Can not mix positive and negative selections" 1
196219

197-
assert_end support_api
198-
220+
assert_end "$SUITE"
199221

200222
########################################################################################################################
223+
SUITE=".kt support"
201224
echo
202-
echo "Starting kt support tests:"
225+
echo "Starting $SUITE tests:"
203226

204227
## run kt via interpreter mode
205228
assert "${PROJECT_DIR}/test/resources/kt_tests/simple_app.kt" "main was called"
@@ -232,24 +255,25 @@ assert 'rm -f kscriptlet* && cmd=$(kscript --package "println(args.size)" 2>&1 |
232255
#assert "echo 1" "package_me_args_1_mem_4772593664"
233256
#assert_statement 'rm -f kscriptlet* && kscript --package "println(args.size)"' "foo" "bar" 0
234257

258+
assert_end "$SUITE"
235259

236260
########################################################################################################################
261+
SUITE="custom interpreters"
237262
echo
238-
echo "Starting custom interpreters tests:"
263+
echo "Starting $SUITE tests:"
239264

240265
export PATH=${PATH}:${PROJECT_DIR}/test/resources/custom_dsl
241266

242-
assert 'mydsl "println(foo)"' "bar"
243-
244-
assert '${PROJECT_DIR}/test/resources/custom_dsl/mydsl_test_with_deps.kts' "foobar"
245-
246-
assert_end custom_interpreters
267+
assert "mydsl \"println(foo)\"" "bar"
247268

269+
assert "${PROJECT_DIR}/test/resources/custom_dsl/mydsl_test_with_deps.kts" "foobar"
248270

271+
assert_end "$SUITE"
249272

250273
########################################################################################################################
274+
SUITE="misc"
251275
echo
252-
echo "Starting misc tests:"
276+
echo "Starting $SUITE tests:"
253277

254278

255279
## prevent regressions of #98 (it fails to process empty or space-containing arguments)
@@ -274,37 +298,25 @@ kscript_nocall() { kotlin -classpath ${PROJECT_DIR}/build/libs/kscript.jar kscri
274298
export -f kscript_nocall
275299

276300
## temp projects with include symlinks
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
301+
assert_raises "tmpDir=$(kscript_nocall --idea ${PROJECT_DIR}/test/resources/includes/include_variations.kts | cut -f2 -d ' ' | xargs echo); cd $tmpDir && gradle build" 0
278302

279303
## Ensure relative includes with in shebang mode
280304
assert_raises "${PROJECT_DIR}/test/resources/includes/shebang_mode_includes" 0
281305

282306
## support diamond-shaped include schemes (see #133)
283-
assert_raises 'tmpDir=$(kscript_nocall --idea ${PROJECT_DIR}/test/resources/includes/diamond.kts | cut -f2 -d" " | xargs echo); cd $tmpDir && gradle build' 0
284-
285-
## todo reenable interactive mode tests using kscript_nocall
286-
287-
assert_end misc
288-
289-
290-
########################################################################################################################
291-
echo
292-
echo "Starting junit suite tests:"
293-
294-
# exit code of `true` is expected to be 0 (see https://github.com/lehmannro/assert.sh)
295-
cd $PROJECT_DIR
296-
assert_raises "./gradlew test"
297-
cd $PROJECT_DIR/test
307+
assert_raises "tmpDir=$(kscript_nocall --idea ${PROJECT_DIR}/test/resources/includes/diamond.kts | cut -f2 -d ' ' | xargs echo); cd $tmpDir && gradle build" 0
298308

299-
assert_end junit_tests
309+
## todo re-enable interactive mode tests using kscript_nocall
300310

311+
assert_end "$SUITE"
301312

302313
########################################################################################################################
314+
SUITE="bootstrap headers"
303315
echo
304-
echo "Starting bootstrap headers tests:"
316+
echo "Starting $SUITE tests:"
305317

306318
f=/tmp/echo_stdin_args.kts
307-
cp ${PROJECT_DIR}/test/resources/echo_stdin_args.kts $f
319+
cp "${PROJECT_DIR}/test/resources/echo_stdin_args.kts" $f
308320

309321
# ensure script works as is
310322
assert 'echo stdin | '$f' --foo bar' "stdin | script --foo bar"
@@ -323,4 +335,4 @@ assert 'echo stdin | kscript '$f' --foo bar' "stdin | script --foo bar"
323335

324336
rm $f
325337

326-
assert_end bootstrap_header
338+
assert_end "$SUITE"

0 commit comments

Comments
 (0)