aboutsummaryrefslogtreecommitdiff
path: root/tests/dir-iterator
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-05-16 22:20:49 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-05-18 11:15:38 +0300
commitb946e380d4e414cec85082ebe67c8ffed6579277 (patch)
treeba2fd4ffca5d66dfdd7d450dad98d37d03d0045a /tests/dir-iterator
parent12b450c33ddd804581a9212c7b88ccaa1d95b636 (diff)
Add ignore_dangling parameter to dir_iterator() ctor
Diffstat (limited to 'tests/dir-iterator')
-rw-r--r--tests/dir-iterator/driver.cxx54
-rw-r--r--tests/dir-iterator/testscript19
2 files changed, 57 insertions, 16 deletions
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<size_t> (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] <dir>
+//
+// 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] <dir>" << endl;
+ cerr << "usage: " << argv[0] << " [-v] [-i] <dir>" << 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
+}