aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/runner.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-11-01 17:25:14 +0300
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:37 +0200
commit675d243e0ddeb627c0881b03e7cd5be746a5a7d3 (patch)
tree05c72dbf5f6ef152f2954f624d836a85749cb3f7 /build2/test/script/runner.cxx
parent4a4e5ad3c50619ad7653b01b562af9794c97aa80 (diff)
Add support for cleanup types to testscript runner
Diffstat (limited to 'build2/test/script/runner.cxx')
-rw-r--r--build2/test/script/runner.cxx59
1 files changed, 40 insertions, 19 deletions
diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx
index 7271234..2af5865 100644
--- a/build2/test/script/runner.cxx
+++ b/build2/test/script/runner.cxx
@@ -215,9 +215,17 @@ namespace build2
for (const auto& c: reverse_iterate (sp.cleanups))
{
+ cleanup_type t (c.type);
+
+ // Skip whenever the path exists or not.
+ //
+ if (t == cleanup_type::never)
+ continue;
+
const path& p (c.path);
- // Remove directory if exists and empty. Fail otherwise.
+ // Remove directory if exists and empty. Fail otherwise. Removal of
+ // non-existing directory is not an error for 'maybe' cleanup type.
//
if (p.to_directory ())
{
@@ -232,22 +240,30 @@ namespace build2
//
rmdir_status r (rmdir (d, 2));
- if (r != rmdir_status::success)
- fail (ll) << "registered for cleanup directory " << d
- << (r == rmdir_status::not_empty
- ? " is not empty"
- : " does not exist");
+ if (r == rmdir_status::success ||
+ (r == rmdir_status::not_exist && t == cleanup_type::maybe))
+ continue;
- continue;
+ fail (ll) << "registered for cleanup directory " << d
+ << (r == rmdir_status::not_empty
+ ? " is not empty"
+ : " does not exist");
}
// Remove directory recursively if not current. Fail otherwise.
- // Recursive removal of non-existing directory is not an error.
+ // Recursive removal of non-existing directory is not an error for
+ // 'maybe' cleanup type.
//
// Note that if some file system entry of non-directory type exists
// with such a name it is not removed but the operation still
- // succeeds. The removal of this entry can be handled at the time of
- // the containing directory removed.
+ // succeeds for 'maybe' cleanup type. The removal of this entry can
+ // be handled at the time of the containing directory cleanup.
+ //
+ // @@ The behavior in the situation described differes for &?a/***
+ // and &?a/ due to build2::rmdir_r() implementation details which
+ // checks for directory existence before trying to remove it.
+ // Shouldn't rmdir_r() behave the same way as rmdir() in regards
+ // to non-directory removal?
//
if (p.leaf ().string () == "***")
{
@@ -258,21 +274,26 @@ namespace build2
rmdir_status r (
rmdir_r (p.directory (), true, static_cast<uint16_t> (2)));
- // Directory is current. That's unlikely to happen but let's keep
- // for completeness.
- //
- if (r == rmdir_status::not_empty)
- fail (ll) << "registered for cleanup wildcard " << p
- << " matches the current directory";
+ if (r == rmdir_status::success ||
+ (r == rmdir_status::not_exist && t == cleanup_type::maybe))
+ continue;
- continue;
+ // The directory is unlikely to be current but let's keep for
+ // completeness.
+ //
+ fail (ll) << "registered for cleanup wildcard " << p
+ << (r == rmdir_status::not_empty
+ ? " matches the current directory"
+ : " doesn't match a directory");
}
- // Remove file if exists. Fail otherwise.
+ // Remove file if exists. Fail otherwise. Removal of non-existing
+ // file is not an error for 'maybe' cleanup type.
//
verify (p, p, "file");
- if (rmfile (p, 2) == rmfile_status::not_exist)
+ if (rmfile (p, 2) == rmfile_status::not_exist &&
+ t == cleanup_type::always)
fail (ll) << "registered for cleanup file " << p
<< " does not exist";
}