aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-03-02 23:25:02 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-03-02 23:25:02 +0300
commit3045a5709df597526f474aa0c5a583a76d9921db (patch)
tree2748f8219f1f2abb837305935aead2370894636c /tests
parent4e56a2167c1091dd65b041a36bfd2b8307bafd0a (diff)
Backup
Diffstat (limited to 'tests')
-rw-r--r--tests/link/driver.cxx43
-rw-r--r--tests/mventry/testscript5
-rw-r--r--tests/path-entry/driver.cxx22
-rw-r--r--tests/path-entry/testscript9
4 files changed, 62 insertions, 17 deletions
diff --git a/tests/link/driver.cxx b/tests/link/driver.cxx
index 96ac880..79f381d 100644
--- a/tests/link/driver.cxx
+++ b/tests/link/driver.cxx
@@ -35,18 +35,33 @@ using namespace butl;
static const char text[] = "ABCDEF";
+enum class mklink
+{
+ sym,
+ hard,
+ any
+};
+
static bool
-link_file (const path& target, const path& link, bool hard, bool check_content)
+link_file (const path& target, const path& link, mklink ml, bool check_content)
{
try
{
- if (hard)
- mkhardlink (target, link);
- else
- mksymlink (target, link);
+ switch (ml)
+ {
+ case mklink::sym: mksymlink (target, link); break;
+ case mklink::hard: mkhardlink (target, link); break;
+ case mklink::any: mkanylink (target, link, true /* copy */); break;
+ }
}
- catch (const system_error&)
+ catch (const system_error& e)
+ {
+ cerr << e << endl;
+ return false;
+ }
+ catch (const pair<entry_type, system_error>& e)
{
+ cerr << e.second << endl;
return false;
}
@@ -139,22 +154,26 @@ main ()
// Create the file hard link.
//
- assert (link_file (fp, td / path ("hlink"), true, true));
+ assert (link_file (fp, td / path ("hlink"), mklink::hard, true));
#ifndef _WIN32
// Create the file symlink using an absolute path.
//
- assert (link_file (fp, td / path ("slink"), false, true));
+ assert (link_file (fp, td / path ("slink"), mklink::sym, true));
// Create the file symlink using a relative path.
//
- assert (link_file (fn, td / path ("rslink"), false, true));
+ assert (link_file (fn, td / path ("rslink"), mklink::sym, true));
// Create the file symlink using an unexistent file path.
//
- assert (link_file (fp + "-a", td / path ("sa"), false, false));
+ assert (link_file (fp + "-a", td / path ("sa"), mklink::sym, false));
#endif
+ // Create the file any link.
+ //
+ assert (link_file (fp, td / path ("alink"), mklink::any, true));
+
// Prepare the target directory.
//
dir_path dn ("dir");
@@ -169,8 +188,8 @@ main ()
}
#ifndef _WIN32
- assert (link_file (fp, dp / path ("hlink"), true, true));
- assert (link_file (fp, dp / path ("slink"), false, true));
+ assert (link_file (fp, dp / path ("hlink"), mklink::hard, true));
+ assert (link_file (fp, dp / path ("slink"), mklink::sym, true));
#endif
// Create the directory symlink using an absolute path.
diff --git a/tests/mventry/testscript b/tests/mventry/testscript
index ecd617a..8c41eb4 100644
--- a/tests/mventry/testscript
+++ b/tests/mventry/testscript
@@ -130,7 +130,7 @@ if ($test.target == $build.host)
: target stays intact.
:
echo 'foo' >=a;
- $lns;
+ $lns &b;
echo 'bar' >=c &!c;
$* c b;
cat a >'foo';
@@ -149,6 +149,7 @@ if ($test.target == $build.host)
: dir
:
{
+#\
: from
:
: Make sure that if source is a symlink it refers the same target after
@@ -160,7 +161,7 @@ if ($test.target == $build.host)
touch a/b;
test -f c/b;
test -d b == 1
-
+#\
: to
:
: Make sure that if destination is a symlink it is get overwritten and
diff --git a/tests/path-entry/driver.cxx b/tests/path-entry/driver.cxx
index d48bf49..e4dddf3 100644
--- a/tests/path-entry/driver.cxx
+++ b/tests/path-entry/driver.cxx
@@ -25,20 +25,36 @@ import butl.filesystem;
using namespace std;
using namespace butl;
-// Usage: argv[0] <path>
+// Usage: argv[0] [-l] <path>
//
// If path entry exists then print it's type and size (meaningful for the
// regular file only) to STDOUT, and exit with the zero code. Otherwise exit
// with the one code. Don't follow symlink. On failure print the error
// description to STDERR and exit with the two code.
//
+// -l
+// Follow symlinks.
+//
int
main (int argc, const char* argv[])
try
{
- assert (argc == 2);
+ bool follow_symlinks (false);
+
+ int i (1);
+ for (; i != argc; ++i)
+ {
+ string v (argv[i]);
+
+ if (v == "-l")
+ follow_symlinks = true;
+ else
+ break;
+ }
+
+ assert (i == argc - 1);
- auto es (path_entry (argv[1]));
+ auto es (path_entry (argv[i], follow_symlinks));
if (!es.first)
return 1;
diff --git a/tests/path-entry/testscript b/tests/path-entry/testscript
index 456f96f..35b6f6f 100644
--- a/tests/path-entry/testscript
+++ b/tests/path-entry/testscript
@@ -25,6 +25,15 @@
directory
/.
EOO
+
+ : followed-symlink
+ :
+ cat <:'abc' >=f;
+ ln -s f l;
+ $* -l l >>EOO
+ regular
+ 3
+ EOO
}
: non-existent