aboutsummaryrefslogtreecommitdiff
path: root/tests
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
parent12b450c33ddd804581a9212c7b88ccaa1d95b636 (diff)
Add ignore_dangling parameter to dir_iterator() ctor
Diffstat (limited to 'tests')
-rw-r--r--tests/dir-iterator/driver.cxx54
-rw-r--r--tests/dir-iterator/testscript19
-rw-r--r--tests/link/driver.cxx4
-rw-r--r--tests/wildcard/testscript16
4 files changed, 74 insertions, 19 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
+}
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<pair<entry_type, path>> 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<pair<entry_type, path>> 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