aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-03-14 21:22:26 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-03-15 19:52:39 +0300
commit5f55069b5bd01f2d5c157fa360fda400da6ba01f (patch)
treea590595c48d013f8289ec251833dde515541bbf8
parentdeb3ed0a579dadbd6cca7ef2e7fb10148387a1ca (diff)
Print sub-entries of non-empty testscript directory registered for cleanup
-rw-r--r--build2/test/script/runner.cxx49
-rw-r--r--tests/test/script/runner/cleanup.test25
2 files changed, 63 insertions, 11 deletions
diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx
index bcaca44..c7b8dab 100644
--- a/build2/test/script/runner.cxx
+++ b/build2/test/script/runner.cxx
@@ -112,7 +112,7 @@ namespace build2
if (buf[n - 1] == '\n')
buf[n - 1] = '\0';
- d << "\n" << buf;
+ d << '\n' << buf;
}
}
}
@@ -123,6 +123,32 @@ namespace build2
}
}
+ // Print first 10 directory sub-entries to the diag record. The directory
+ // must exist.
+ //
+ static void
+ print_dir (diag_record& d, const dir_path& p, const location& ll)
+ {
+ try
+ {
+ size_t n (0);
+ for (const dir_entry& de: dir_iterator (p))
+ {
+ if (n++ < 10)
+ d << '\n' << (de.ltype () == entry_type::directory
+ ? path_cast<dir_path> (de.path ())
+ : de.path ());
+ }
+
+ if (n > 10)
+ d << "\nand " << n - 10 << " more file(s)";
+ }
+ catch (const system_error& e)
+ {
+ fail (ll) << "unable to iterate over " << p << ": " << e;
+ }
+ }
+
// Save a string to the file. Fail if exception is thrown by underlying
// operations.
//
@@ -745,9 +771,12 @@ namespace build2
if (r != rmdir_status::not_empty)
return true;
- fail (ll) << "registered for cleanup directory " << sd
- << " is not empty" <<
- info << "wildcard: '" << p << "'";
+ diag_record dr (fail (ll));
+ dr << "registered for cleanup directory " << sd
+ << " is not empty";
+
+ print_dir (dr, sd, ll);
+ dr << info << "wildcard: '" << p << "'";
}
return true;
@@ -791,10 +820,14 @@ namespace build2
(r == rmdir_status::not_exist && t == cleanup_type::maybe))
continue;
- fail (ll) << "registered for cleanup directory " << d
- << (r == rmdir_status::not_empty
- ? " is not empty"
- : " does not exist");
+ diag_record dr (fail (ll));
+ dr << "registered for cleanup directory " << d
+ << (r == rmdir_status::not_empty
+ ? " is not empty"
+ : " does not exist");
+
+ if (r == rmdir_status::not_empty)
+ print_dir (dr, d, ll);
}
// Remove the file if exists. Fail otherwise. Removal of
diff --git a/tests/test/script/runner/cleanup.test b/tests/test/script/runner/cleanup.test
index 14e931e..fe72807 100644
--- a/tests/test/script/runner/cleanup.test
+++ b/tests/test/script/runner/cleanup.test
@@ -128,9 +128,25 @@ b += --no-column
:
: Test cleanup of a non-empty directory.
:
- $c <'$* -d a -f a/b &a/' && $b 2>>/EOE != 0
- testscript:1: error: registered for cleanup directory test/1/a/ is not empty
- EOE
+ {
+ : files
+ :
+ $c <<EOI && $b 2>>/~%EOE% != 0
+ $* -d a -f a/0 -f a/1 -f a/2 -f a/3 -f a/4 -f a/5 -f a/6 -f a/7 -f a/8 \
+ -f a/9 -f a/a -f a/b &a/
+ EOI
+ testscript:2: error: registered for cleanup directory test/1/a/ is not empty
+ %.%{10}
+ and 2 more file(s)
+ EOE
+
+ : dir
+ :
+ $c <'$* -d a/b' && $b 2>>/EOE != 0
+ testscript:1: error: registered for cleanup directory test/1/ is not empty
+ a/
+ EOE
+ }
: not-dir
:
@@ -231,6 +247,7 @@ b += --no-column
:
$c <'$* -d a/b/c -f a/b/d &a/**/' && $b 2>>/EOE != 0
testscript:1: error: registered for cleanup directory test/1/a/b/ is not empty
+ d
info: wildcard: 'test/1/a/**/'
EOE
}
@@ -268,6 +285,7 @@ $c <'$* -d a/b &a/ &a/b/' && $b
:
$c <'$* -o foo >=a &!a' && $b 2>>/EOE != 0
testscript:1: error: registered for cleanup directory test/1/ is not empty
+a
EOE
: explicit-overwrite
@@ -279,4 +297,5 @@ $* &!a;
$* -o foo >=a
EOO
testscript:2: error: registered for cleanup directory test/1/ is not empty
+a
EOE