aboutsummaryrefslogtreecommitdiff
path: root/tests/bash
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-07-20 15:31:13 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-07-20 16:10:26 +0200
commitc1dc06dfd1d329f8c6499dbe2166725ab9c35e17 (patch)
tree97449ae7263490473a833944cfeb3d889a2f580d /tests/bash
parentb4286df8c9bafdab1934cef99ccc0506ec4555e2 (diff)
Implement bash module
Diffstat (limited to 'tests/bash')
-rw-r--r--tests/bash/buildfile5
-rw-r--r--tests/bash/testscript223
2 files changed, 228 insertions, 0 deletions
diff --git a/tests/bash/buildfile b/tests/bash/buildfile
new file mode 100644
index 0000000..92fd280
--- /dev/null
+++ b/tests/bash/buildfile
@@ -0,0 +1,5 @@
+# file : tests/bash/buildfile
+# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+./: testscript $b
diff --git a/tests/bash/testscript b/tests/bash/testscript
new file mode 100644
index 0000000..39f247b
--- /dev/null
+++ b/tests/bash/testscript
@@ -0,0 +1,223 @@
+# file : tests/bash/testscript
+# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+# Only native testing on non-Windows platforms
+#
+: dummy
+:
+if ($test.target == $build.host && $build.host.class != 'windows')
+ {
+ buildfile = true
+ test.arguments =
+
+ .include ../common.test
+
+ +cat <<EOI >+build/bootstrap.build
+ using test
+ using install
+ EOI
+
+ +cat <<EOI >=build/root.build
+ using bash
+ test/bash{*}: install.subdirs = true
+ exe{*}: test = true
+ EOI
+
+ # Setup a subproject that we can import a module from.
+ #
+ # Note: used by multiple tests so should be static.
+ #
+ +mkdir -p sub.bash/build
+ +cat <<EOI >=sub.bash/build/bootstrap.build
+ project = sub.bash
+ using install
+ EOI
+ +cat <<EOI >=sub.bash/build/root.build
+ using bash
+ EOI
+ +cat <<EOI >=sub.bash/build/export.build
+ $out_root/
+ {
+ include sub/
+ }
+ export $src_root/sub/bash{foo}
+ EOI
+ +cat <<EOI >=sub.bash/buildfile
+ ./: dir{*/ -build/}
+ EOI
+ +mkdir sub.bash/sub
+ +cat <<EOI >=sub.bash/sub/foo.bash
+ echo sub
+ EOI
+ +cat <<EOI >=sub.bash/sub/buildfile
+ ./: bash{foo}
+ EOI
+
+ # This scopes creates the test/ subdirectory corresponding to our project in
+ # the import path. A bit of a hack but the alternative would be creating a
+ # project for each test.
+ #
+ : test
+ :
+ {
+ : basics
+ :
+ {
+ cat <<EOI >=hello.bash;
+ function hello () { echo "Hello, $@!"; }
+ EOI
+
+ cat <<EOI >=hello.in;
+ #!/usr/bin/env bash
+
+ if [[ "$OSTYPE" == darwin* ]]; then
+ function readlink ()
+ {
+ if [ "$1" != -f ]; then
+ command readlink "$@"
+ else
+ echo "$2"
+ fi
+ }
+ fi
+
+ @import test/basics/hello@
+
+ hello "$@"
+ EOI
+
+ cat <<EOI >=buildfile;
+ exe{hello}: in{hello} bash{hello}
+ exe{hello}: test.arguments = 'World'
+ EOI
+
+ $* test >'Hello, World!';
+
+ $* install config.install.root=tmp;
+ tmp/bin/hello 'John' >'Hello, John!';
+ $* uninstall config.install.root=tmp;
+
+ $* clean
+ }
+
+ : import
+ :
+ {
+ cat <<EOI >=driver.in;
+ #!/usr/bin/env bash
+
+ if [[ "$OSTYPE" == darwin* ]]; then
+ function readlink ()
+ {
+ if [ "$1" != -f ]; then
+ command readlink "$@"
+ else
+ echo "$2"
+ fi
+ }
+ fi
+
+ @import sub/foo@
+ EOI
+
+ cat <<EOI >=buildfile;
+ import mods = sub.bash%bash{foo}
+ exe{driver}: in{driver} $mods
+ EOI
+
+ $* test >'sub';
+
+ $* install config.install.root=tmp;
+ tmp/bin/driver >'sub';
+ $* uninstall config.install.root=tmp;
+
+ $* clean
+ }
+
+ : recursive
+ :
+ {
+ cat <<EOI >=test.bash.in;
+ @import sub/foo@
+ EOI
+
+ cat <<EOI >=driver.in;
+ #!/usr/bin/env bash
+
+ if [[ "$OSTYPE" == darwin* ]]; then
+ function readlink ()
+ {
+ if [ "$1" != -f ]; then
+ command readlink "$@"
+ else
+ local r="$2"
+ if test -L "$r"; then
+ r="$(command readlink "$r")"
+ if [[ "$r" != /* ]]; then
+ r="$(dirname "$2")/$r"
+ fi
+ fi
+ echo "$r"
+ fi
+ }
+ fi
+
+ @import test/recursive/test@
+ EOI
+
+ cat <<EOI >=buildfile;
+ import mods = sub.bash%bash{foo}
+ exe{driver}: in{driver} bash{test}
+ bash{test}: in{test} $mods
+ EOI
+
+ $* test >'sub';
+
+ $* install config.install.root=tmp;
+
+ tmp/bin/driver >'sub';
+
+ # Test execution via symlink.
+ #
+ mkdir bin;
+ ln -s tmp/bin/driver bin/driver;
+ bin/driver >'sub';
+
+ # Test execution via PATH.
+ #
+ #@@ TODO: add $~/bin to the PATH environment variable.
+ #driver >'sub';
+
+ $* uninstall config.install.root=tmp;
+ $* clean
+ }
+
+ #\
+ : import-installed
+ :
+ {
+ # Note that here we import the project as sub, not sub.bash in order
+ # to avoid importing as a subproject.
+ #
+ cat <<EOI >=driver.in;
+ #!/usr/bin/env bash
+ @import sub/foo@
+ EOI
+
+ cat <<EOI >=buildfile;
+ import mods = sub%bash{foo}
+ exe{driver}: in{driver} $mods
+ EOI
+
+ $* 'install(../../sub.bash/)' config.install.root=tmp;
+
+ #@@ TODO: add $~/tmp/bin to the PATH environment variable.
+ $* test clean >'sub';
+ $* clean;
+
+ $* 'uninstall(../../sub.bash/)' config.install.root=tmp
+ }
+ #\
+ }
+}