aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/build/root.build1
-rw-r--r--tests/recipe/cxx/testscript269
-rw-r--r--tests/test/script/runner/driver.cxx25
-rw-r--r--tests/test/script/runner/env.testscript7
4 files changed, 159 insertions, 143 deletions
diff --git a/tests/build/root.build b/tests/build/root.build
index e3f0f61..5bf6731 100644
--- a/tests/build/root.build
+++ b/tests/build/root.build
@@ -22,7 +22,6 @@ import.build2 = [null]
import! [metadata] b = build2%exe{b}
static = $($b:b.static) # True if testing statically-linked build system.
-shared = (!$static) # For '$shared || exit' idiom.
testscript{*}: test = $b
diff --git a/tests/recipe/cxx/testscript b/tests/recipe/cxx/testscript
index 6601c0a..6b11c0f 100644
--- a/tests/recipe/cxx/testscript
+++ b/tests/recipe/cxx/testscript
@@ -1,168 +1,169 @@
# file : tests/recipe/cxx/testscript
# license : MIT; see accompanying LICENSE file
-# Ad hoc C++ recipes not supported in a statically-linked build system.
+# Ad hoc C++ recipes not supported in a statically-linked build system. Also
+# disable when cross-testing for the sake of simplicity.
#
-+$shared || exit
-
-+mkdir build
-+cat <<EOI >=build/bootstrap.build
- project = test
- amalgamation =
- subprojects =
-
- using config
- using test
- EOI
-
-+cat <<EOI >=build/root.build
- EOI
-
-+cat <<EOI >=buildfile
- ./:
- {{ c++ 1
- // Dummy recipe to trigger cleanup.
- }}
- EOI
-
-: update-clean
-:
+if (!$static && $test.target == $build.host)
{
- echo 'bar' >=bar;
+ +mkdir build
+ +cat <<EOI >=build/bootstrap.build
+ project = test
+ amalgamation =
+ subprojects =
+
+ using config
+ using test
+ EOI
- cat <<EOI >=buildfile;
- foo: bar
- % update clean
- {{ c++ 1
- recipe
- apply (action a, target& xt) const override
- {
- file& t (xt.as<file> ());
+ +cat <<EOI >=build/root.build
+ EOI
- t.derive_path ();
- inject_fsdir (a, t);
- match_prerequisite_members (a, t);
+ +cat <<EOI >=buildfile
+ ./:
+ {{ c++ 1
+ // Dummy recipe to trigger cleanup.
+ }}
+ EOI
- switch (a)
+ : update-clean
+ :
+ {
+ echo 'bar' >=bar;
+
+ cat <<EOI >=buildfile;
+ foo: bar
+ % update clean
+ {{ c++ 1
+ recipe
+ apply (action a, target& xt) const override
{
- case perform_update_id: return perform_update;
- case perform_clean_id: return perform_clean_depdb;
- default: assert (false); return noop_recipe;
+ file& t (xt.as<file> ());
+
+ t.derive_path ();
+ inject_fsdir (a, t);
+ match_prerequisite_members (a, t);
+
+ switch (a)
+ {
+ case perform_update_id: return perform_update;
+ case perform_clean_id: return perform_clean_depdb;
+ default: assert (false); return noop_recipe;
+ }
}
- }
- static target_state
- perform_update (action a, const target& xt)
- {
- const file& t (xt.as<file> ());
- const path& tp (t.path ());
+ static target_state
+ perform_update (action a, const target& xt)
+ {
+ const file& t (xt.as<file> ());
+ const path& tp (t.path ());
- timestamp mt (t.load_mtime ());
- auto pr (execute_prerequisites<file> (a, t, mt));
+ timestamp mt (t.load_mtime ());
+ auto pr (execute_prerequisites<file> (a, t, mt));
- bool update (!pr.first);
- target_state r (update ? target_state::changed : *pr.first);
+ bool update (!pr.first);
+ target_state r (update ? target_state::changed : *pr.first);
- const file& s (pr.second);
- const path& sp (s.path ());
+ const file& s (pr.second);
+ const path& sp (s.path ());
- depdb dd (tp + ".d");
- dd.expect (sp);
+ depdb dd (tp + ".d");
+ dd.expect (sp);
- if (dd.writing () || dd.mtime > mt)
- update = true;
+ if (dd.writing () || dd.mtime > mt)
+ update = true;
- dd.close ();
+ dd.close ();
- if (!update)
- return r;
+ if (!update)
+ return r;
- if (verb == 1)
- text << "cp " << t;
- else if (verb >= 2)
- text << "cp " << sp << ' ' << tp;
+ if (verb == 1)
+ text << "cp " << t;
+ else if (verb >= 2)
+ text << "cp " << sp << ' ' << tp;
- cpfile (sp, tp);
- return target_state::changed;
- }
- }}
- EOI
+ cpfile (sp, tp);
+ return target_state::changed;
+ }
+ }}
+ EOI
- $* 2>>~%EOE%;
- %^(c\+\+|ld).*%+
- cp file{foo}
- EOE
+ env BDEP_SYNC=0 -- $* 2>>~%EOE%;
+ %^(c\+\+|ld).*%+
+ cp file{foo}
+ EOE
- cat <<<foo >'bar';
+ cat <<<foo >'bar';
- # While at it, make sure there is no rebuild.
- #
- $* 2>/'info: dir{./} is up to date';
+ # While at it, make sure there is no rebuild.
+ #
+ env BDEP_SYNC=0 -- $* 2>/'info: dir{./} is up to date';
- $* clean 2>-
-}
+ env BDEP_SYNC=0 -- $* clean 2>-
+ }
-#\
-@@ TMP disabled: env BDEP_SYNC=0
-: test
-:
-{
- echo 'bar' >=bar;
+ : test
+ :
+ {
+ echo 'bar' >=bar;
- cat <<EOI >=buildfile;
- foo: bar
- {{
- cp $path($<) $path($>)
- }}
- % test
- {{ c++ 1 --
+ cat <<EOI >=buildfile;
+ foo: bar
+ {{
+ cp $path($<) $path($>)
+ }}
+ % test
+ {{ c++ 1 --
- #include <iostream>
+ #include <iostream>
- --
+ --
- recipe
- apply (action a, target& t) const override
- {
- if (a.outer ())
+ recipe
+ apply (action a, target& t) const override
{
- match_inner (a, t);
- return execute_inner;
+ if (a.outer ())
+ {
+ match_inner (a, t);
+ return execute_inner;
+ }
+ else
+ return perform_test;
}
- else
- return perform_test;
- }
-
- static target_state
- perform_test (action, const target& xt)
- {
- const file& t (xt.as<file> ());
- const path& tp (t.path ());
-
- if (verb == 1)
- text << "test " << t;
- else if (verb >= 2)
- text << "cat " << tp;
-
- ifdstream ifs (tp);
- if (ifs.peek () != ifdstream::traits_type::eof ())
- std::cerr << ifs.rdbuf ();
- ifs.close ();
-
- return target_state::changed;
- }
- }}
- EOI
- $* test 2>>~%EOE%;
- %^(c\+\+|ld).*%+
- cp file{foo}
- test file{foo}
- bar
- EOE
+ static target_state
+ perform_test (action, const target& xt)
+ {
+ const file& t (xt.as<file> ());
+ const path& tp (t.path ());
- $* clean 2>-
-}
-#\
+ if (verb == 1)
+ text << "test " << t;
+ else if (verb >= 2)
+ text << "cat " << tp;
+
+ ifdstream ifs (tp);
+ if (ifs.peek () != ifdstream::traits_type::eof ())
+ std::cerr << ifs.rdbuf ();
+ ifs.close ();
--$* clean 2>- # Clean recipe builds.
+ return target_state::changed;
+ }
+ }}
+ EOI
+
+ env BDEP_SYNC=0 -- $* test 2>>~%EOE%;
+ %^(c\+\+|ld).*%+
+ cp file{foo}
+ test file{foo}
+ bar
+ EOE
+
+ env BDEP_SYNC=0 -- $* clean 2>-
+ }
+
+ # Clean recipe builds if the testscript is enabled (see above for details).
+ #
+ -$* clean 2>-
+}
diff --git a/tests/test/script/runner/driver.cxx b/tests/test/script/runner/driver.cxx
index 08d5bba..d5a74a4 100644
--- a/tests/test/script/runner/driver.cxx
+++ b/tests/test/script/runner/driver.cxx
@@ -34,22 +34,22 @@ main (int argc, char* argv[])
using butl::optional;
// Usage: driver [-i <int>] (-o <string>)* (-e <string>)* (-f <file>)*
- // (-d <dir>)* [(-t (a|m|s|z)) | (-s <int>)]
+ // (-d <dir>)* (-v <name>)* [(-t (a|m|s|z)) | (-s <int>)]
//
- // Execute actions specified by -i, -o, -e, -f, -d options in the order as
- // they appear on the command line. After that terminate abnormally if -t
- // option is provided, otherwise exit normally with the status specified by
- // -s option (0 by default).
+ // Execute actions specified by -i, -o, -e, -f, -d, and -v options in the
+ // order as they appear on the command line. After that terminate abnormally
+ // if -t option is provided, otherwise exit normally with the status
+ // specified by -s option (0 by default).
//
// -i <fd>
- // Forward STDIN data to the standard stream denoted by the file
+ // Forward stdin data to the standard stream denoted by the file
// descriptor. Read and discard if 0.
//
// -o <string>
- // Print the line to STDOUT.
+ // Print the line to stdout.
//
// -e <string>
- // Print the line to STDERR.
+ // Print the line to stderr.
//
// -f <path>
// Create an empty file with the path specified.
@@ -58,6 +58,10 @@ main (int argc, char* argv[])
// Create a directory with the path specified. Create parent directories
// if required.
//
+ // -v <name>
+ // If the specified variable is set the print its value to stdout and the
+ // string '<none>' otherwise.
+ //
// -t <method>
// Abnormally terminate itself using one of the following methods:
//
@@ -135,6 +139,11 @@ main (int argc, char* argv[])
{
try_mkdir_p (dir_path (v));
}
+ else if (o == "-v")
+ {
+ optional<string> var (getenv (v));
+ cout << (var ? *var : "<none>") << endl;
+ }
else if (o == "-t")
{
assert (aterm == '\0' && !status); // Make sure exit method is not set.
diff --git a/tests/test/script/runner/env.testscript b/tests/test/script/runner/env.testscript
new file mode 100644
index 0000000..6fcedfa
--- /dev/null
+++ b/tests/test/script/runner/env.testscript
@@ -0,0 +1,7 @@
+# file : tests/test/script/runner/env.testscript
+# license : MIT; see accompanying LICENSE file
+
+.include ../common.testscript
+
+$c <'env abc=xyz -- $* -v abc >xyz' && $b : set
+$c <'env --unset=abc -- $* -v abc >"<none>"' && env abc=xyz -- $b : unset