From adf27f5e17f4de774b3121c3669e3947ad4c9ca5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 27 Oct 2016 12:10:58 +0300 Subject: Add support of cleanups to testscript parser --- build2/test/script/parser.cxx | 66 ++++++++++++++++++++++++++++--------------- build2/test/script/script | 2 ++ build2/test/script/script.cxx | 27 +++++++++++++++--- 3 files changed, 69 insertions(+), 26 deletions(-) (limited to 'build2/test/script') diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index a3f2f00..152f1f0 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -581,7 +581,8 @@ namespace build2 err_merge, err_string, err_document, - err_file + err_file, + clean }; pending p (pending::program); bool nn (false); // True if pending here-{str,doc} is "no-newline". @@ -632,23 +633,30 @@ namespace build2 hd.push_back (here_doc {&r, move (w), nn}); }; - auto add_file = - [&app, &l, this] (redirect& r, const char* n, string&& w) + auto parse_path = [&l, this] (const char* n, string&& w) { try { - r.file.path = path (move (w)); + path p (move (w)); - if (r.file.path.empty ()) - fail (l) << "empty " << n << " redirect file path"; + if (!p.empty ()) + return p; + error (l) << "empty " << n; } catch (const invalid_path& e) { - fail (l) << "invalid " << n << " redirect file path '" << e.path - << "'"; + error (l) << "invalid " << n << " '" << e.path << "'"; } + throw failed (); + }; + + auto add_file = + [&app, &parse_path] (redirect& r, string n, string&& w) + { + n += " redirect file path"; + r.file.path = parse_path (n.c_str (), move (w)); r.file.append = app; }; @@ -657,17 +665,7 @@ namespace build2 case pending::none: c.arguments.push_back (move (w)); break; case pending::program: { - try - { - c.program = path (move (w)); - - if (c.program.empty ()) - fail (l) << "empty program path"; - } - catch (const invalid_path& e) - { - fail (l) << "invalid program path '" << e.path << "'"; - } + c.program = parse_path ("program path", move (w)); break; } @@ -685,6 +683,12 @@ namespace build2 case pending::in_file: add_file (c.in, "stdin", move (w)); break; case pending::out_file: add_file (c.out, "stdout", move (w)); break; case pending::err_file: add_file (c.err, "stderr", move (w)); break; + + case pending::clean: + { + c.cleanups.push_back (parse_path ("cleanup path", move (w))); + break; + } } p = pending::none; @@ -713,6 +717,7 @@ namespace build2 case pending::err_string: what = "stderr here-string"; break; case pending::err_document: what = "stderr here-document end"; break; case pending::err_file: what = "stderr file"; break; + case pending::clean: what = "cleanup path"; break; } if (what != nullptr) @@ -902,6 +907,8 @@ namespace build2 case type::in_file: case type::out_file: case type::out_file_app: + + case type::clean: { if (pre_parse_) { @@ -966,12 +973,21 @@ namespace build2 case type::in_file: case type::out_file: case type::out_file_app: + { + parse_redirect (t, l); + break; + } - parse_redirect (t, l); - next (t, tt); - break; + case type::clean: + { + p = pending::clean; + break; + } + + default: assert (false); break; } + next (t, tt); break; } default: @@ -1115,6 +1131,12 @@ namespace build2 break; } + case type::clean: + { + p = pending::clean; + break; + } + case type::in_doc: case type::out_doc: diff --git a/build2/test/script/script b/build2/test/script/script index a21f0c6..a841d6c 100644 --- a/build2/test/script/script +++ b/build2/test/script/script @@ -121,6 +121,8 @@ namespace build2 redirect out; redirect err; + paths cleanups; + command_exit exit {exit_comparison::eq, 0}; }; diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx index 8de023f..bf53595 100644 --- a/build2/test/script/script.cxx +++ b/build2/test/script/script.cxx @@ -4,6 +4,8 @@ #include +#include + #include using namespace std; @@ -32,7 +34,19 @@ namespace build2 void to_stream (ostream& o, const command& c, command_to_stream m) { - auto print_redirect = [&o] (const redirect& r, const char* prefix) + auto print_path = [&o] (const path& p) + { + using build2::operator<<; + + ostringstream s; + stream_verb (s, stream_verb (o)); + s << p; + + to_stream_q (o, s.str ()); + }; + + auto print_redirect = + [&o, print_path] (const redirect& r, const char* prefix) { o << ' ' << prefix; @@ -72,11 +86,10 @@ namespace build2 } case redirect_type::file: { - using build2::operator<<; - // Add '>>' or '<<' (and so make it '<<<' or '>>>'). // - o << d << d << (r.file.append ? "&" : "") << r.file.path; + o << d << d << (r.file.append ? "&" : ""); + print_path (r.file.path); break; } } @@ -109,6 +122,12 @@ namespace build2 if (c.out.type != redirect_type::none) print_redirect (c.out, ">"); if (c.err.type != redirect_type::none) print_redirect (c.err, "2>"); + for (const auto& p: c.cleanups) + { + o << " &"; + print_path (p); + } + if (c.exit.comparison != exit_comparison::eq || c.exit.status != 0) { switch (c.exit.comparison) -- cgit v1.1