From b946e380d4e414cec85082ebe67c8ffed6579277 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 16 May 2018 22:20:49 +0300 Subject: Add ignore_dangling parameter to dir_iterator() ctor --- tests/dir-iterator/driver.cxx | 54 ++++++++++++++++++++++++++++++++----------- tests/dir-iterator/testscript | 19 +++++++++++++-- tests/link/driver.cxx | 4 ++-- tests/wildcard/testscript | 16 ++++++++++++- 4 files changed, 74 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/dir-iterator/driver.cxx b/tests/dir-iterator/driver.cxx index 1adef6f..bad9e58 100644 --- a/tests/dir-iterator/driver.cxx +++ b/tests/dir-iterator/driver.cxx @@ -41,45 +41,71 @@ operator<< (ostream& os, entry_type e) return os << entry_type_string[static_cast (e)]; } -// @@ Should we make the test silent unless -v arg passed. In silen mode could -// compare the output with a set of predefined dir entries. +// Usage: argv[0] [-v] [-i] +// +// Iterates over a directory filesystem sub-entries, obtains their types and +// target types for symlinks. +// +// -v +// Print the filesystem entries types and names to STDOUT. +// +// -i +// Ignore dangling symlinks, rather than fail trying to obtain the target +// type. // int main (int argc, const char* argv[]) { - if (!(argc == 2 || (argc == 3 && argv[1] == string ("-v")))) + assert (argc > 0); + + bool verbose (false); + bool ignore_dangling (false); + + int i (1); + for (; i != argc; ++i) + { + string v (argv[i]); + + if (v == "-v") + verbose = true; + else if (v == "-i") + ignore_dangling = true; + else + break; + } + + if (i != argc - 1) { - cerr << "usage: " << argv[0] << " [-v] " << endl; + cerr << "usage: " << argv[0] << " [-v] [-i] " << endl; return 1; } - bool v (argc == 3); - const char* d (argv[argc - 1]); + const char* d (argv[i]); try { - for (const dir_entry& de: dir_iterator (dir_path (d))) + for (const dir_entry& de: dir_iterator (dir_path (d), ignore_dangling)) { entry_type lt (de.ltype ()); - entry_type t (lt == entry_type::symlink ? de.ltype () : lt); + entry_type t (lt == entry_type::symlink ? de.type () : lt); const path& p (de.path ()); - if (v) + if (verbose) { - cerr << lt << " "; + cout << lt << " "; if (lt == entry_type::symlink) - cerr << t; + cout << t; else - cerr << " "; + cout << " "; - cerr << " " << p << endl; + cout << " " << p << endl; } } } catch (const exception& e) { - cerr << argv[1] << ": " << e << endl; + cerr << e << endl; return 1; } } diff --git a/tests/dir-iterator/testscript b/tests/dir-iterator/testscript index 75a1ca6..f592c78 100644 --- a/tests/dir-iterator/testscript +++ b/tests/dir-iterator/testscript @@ -8,9 +8,24 @@ test.options = -v : mkdir a; touch a/b; -$* a 2>"reg b" +$* a >"reg b" : dir : mkdir -p a/b; -$* a 2>"dir b" +$* a >"dir b" + +: dangling-link +: +if ($cxx.target.class != 'windows') +{ + +mkdir a + +touch --no-cleanup a/b + +ln -s a/b a/l + +rm a/b + + +touch a/c + + $* ../a >! 2>! != 0 : keep + $* -i ../a >'reg c' : skip +} diff --git a/tests/link/driver.cxx b/tests/link/driver.cxx index 463ad23..7ee8c3b 100644 --- a/tests/link/driver.cxx +++ b/tests/link/driver.cxx @@ -96,11 +96,11 @@ link_dir (const dir_path& target, dir_path tp (target.absolute () ? target : link.directory () / target); set> te; - for (const dir_entry& de: dir_iterator (tp)) + for (const dir_entry& de: dir_iterator (tp, false /* ignore_dangling */)) te.emplace (de.ltype (), de.path ()); set> le; - for (const dir_entry& de: dir_iterator (link)) + for (const dir_entry& de: dir_iterator (link, false /* ignore_dangling */)) le.emplace (de.ltype (), de.path ()); return te == le; diff --git a/tests/wildcard/testscript b/tests/wildcard/testscript index 489f724..85f5a33 100644 --- a/tests/wildcard/testscript +++ b/tests/wildcard/testscript @@ -113,7 +113,7 @@ : absolute : - : When cross-testing we can't guarantee that host absolute paths are + : When cross-testing we cannot guarantee that host absolute paths are : recognized by the target process. : if ($test.target == $build.host) @@ -566,6 +566,20 @@ } } } + + : dangling-link + : + if ($cxx.target.class != 'windows') + { + mkdir a; + touch --no-cleanup a/b; + ln -s a/b a/l; + rm a/b; + + touch a/c; + + $* a/* >/'a/c' + } } : path-entry-search -- cgit v1.1