From c1dc06dfd1d329f8c6499dbe2166725ab9c35e17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 20 Jul 2018 15:31:13 +0200 Subject: Implement bash module --- tests/bash/buildfile | 5 ++ tests/bash/testscript | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/common.test | 6 +- 3 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 tests/bash/buildfile create mode 100644 tests/bash/testscript (limited to 'tests') 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 <+build/bootstrap.build + using test + using install + EOI + + +cat <=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 <=sub.bash/build/bootstrap.build + project = sub.bash + using install + EOI + +cat <=sub.bash/build/root.build + using bash + EOI + +cat <=sub.bash/build/export.build + $out_root/ + { + include sub/ + } + export $src_root/sub/bash{foo} + EOI + +cat <=sub.bash/buildfile + ./: dir{*/ -build/} + EOI + +mkdir sub.bash/sub + +cat <=sub.bash/sub/foo.bash + echo sub + EOI + +cat <=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 <=hello.bash; + function hello () { echo "Hello, $@!"; } + EOI + + cat <=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 <=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 <=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 <=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 <=test.bash.in; + @import sub/foo@ + EOI + + cat <=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 <=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 <=driver.in; + #!/usr/bin/env bash + @import sub/foo@ + EOI + + cat <=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 + } + #\ + } +} diff --git a/tests/common.test b/tests/common.test index a1c9316..586e793 100644 --- a/tests/common.test +++ b/tests/common.test @@ -32,7 +32,11 @@ project = test amalgamation = EOI -test.options += --serial-stop --quiet --buildfile - +test.options += --serial-stop --quiet + +if ($null($buildfile) || !$buildfile) + test.options += --buildfile - +end # By default just load the buildfile. # -- cgit v1.1