diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-10-31 21:21:17 +0300 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-04 09:26:37 +0200 |
commit | 35c9e7698e768883065d944b2c43e5af9cb37ee4 (patch) | |
tree | c9a5299b90af3264c95f189c8595a0573d2d0b9f | |
parent | 4876a5f56c72f64a54627f9b6d0656878b7ca547 (diff) |
Update test runner to accommodate cleanup types
-rw-r--r-- | build2/test/script/parser.cxx | 3 | ||||
-rw-r--r-- | build2/test/script/runner.cxx | 14 | ||||
-rw-r--r-- | build2/test/script/script | 6 | ||||
-rw-r--r-- | build2/test/script/script.cxx | 21 |
4 files changed, 28 insertions, 16 deletions
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index e3194cb..4c7b17b 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -912,7 +912,8 @@ namespace build2 case pending::clean: { - c.cleanups.push_back (parse_path (move (w), "cleanup path")); + c.cleanups.push_back ( + {cleanup_type::always, parse_path (move (w), "cleanup path")}); break; } } diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx index f42299e..ee7b5df 100644 --- a/build2/test/script/runner.cxx +++ b/build2/test/script/runner.cxx @@ -86,7 +86,7 @@ namespace build2 try { ofdstream os (orp); - sp.clean (orp); + sp.clean ({cleanup_type::always, orp}, true); os << (rd.type == redirect_type::here_string ? rd.str @@ -190,7 +190,7 @@ namespace build2 // assert (empty (sp.wd_path)); - sp.clean (sp.wd_path); + sp.clean ({cleanup_type::always, sp.wd_path}, true); } void concurrent_runner:: @@ -213,8 +213,10 @@ namespace build2 << " is out of working directory " << sp.wd_path; }; - for (const auto& p: reverse_iterate (sp.cleanups)) + for (const auto& c: reverse_iterate (sp.cleanups)) { + const path& p (c.path); + // Remove directory if exists and empty. Fail otherwise. // if (p.to_directory ()) @@ -401,7 +403,7 @@ namespace build2 } open_stdin (); - sp.clean (stdin); + sp.clean ({cleanup_type::always, stdin}, true); break; } @@ -473,7 +475,7 @@ namespace build2 fail (cl) << "unable to write " << p << ": " << e.what (); } - sp.clean (p); + sp.clean ({cleanup_type::always, p}, true); return os.fd (); }; @@ -506,7 +508,7 @@ namespace build2 // Register command-created paths for cleanup. // for (const auto& p: c.cleanups) - sp.clean (normalize (p)); + sp.clean ({p.type, normalize (p.path)}, false); // If there is no correct exit status by whatever reason then dump // stderr (if cached), print the proper diagnostics and fail. diff --git a/build2/test/script/script b/build2/test/script/script index ab54ad0..0b3a05e 100644 --- a/build2/test/script/script +++ b/build2/test/script/script @@ -151,7 +151,7 @@ namespace build2 redirect out; redirect err; - build2::cleanups cleanups; + script::cleanups cleanups; command_exit exit {exit_comparison::eq, 0}; }; @@ -200,7 +200,7 @@ namespace build2 optional<description> desc; - build2::cleanups cleanups; + test::script::cleanups cleanups; // Variables. // @@ -236,7 +236,7 @@ namespace build2 // cleanup type if this path is already registered. // void - clean (cleanup p, bool implicit); + clean (cleanup, bool implicit); public: virtual diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx index 058720a..77b8902 100644 --- a/build2/test/script/script.cxx +++ b/build2/test/script/script.cxx @@ -126,7 +126,11 @@ namespace build2 for (const auto& p: c.cleanups) { o << " &"; - print_path (p); + + if (p.type != cleanup_type::always) + o << (p.type == cleanup_type::maybe ? '?' : '!'); + + print_path (p.path); } if (c.exit.comparison != exit_comparison::eq || c.exit.status != 0) @@ -288,15 +292,20 @@ namespace build2 const_cast<dir_path&> (wd_path) = dir_path (p->wd_path) /= id; } - // command - // void scope:: - clean (path p) + clean (cleanup c, bool implicit) { using std::find; // Hidden by scope::find(). - if (find (cleanups.begin (), cleanups.end (), p) == cleanups.end ()) - cleanups.emplace_back (move (p)); + assert (!implicit || c.type == cleanup_type::always); + + auto pr = [&c] (const cleanup& v) -> bool {return v.path == c.path;}; + auto i (find_if (cleanups.begin (), cleanups.end (), pr)); + + if (i == cleanups.end ()) + cleanups.emplace_back (move (c)); + else if (!implicit) + i->type = c.type; } // script_base |