aboutsummaryrefslogtreecommitdiff
path: root/tests/link/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/link/driver.cxx')
-rw-r--r--tests/link/driver.cxx64
1 files changed, 55 insertions, 9 deletions
diff --git a/tests/link/driver.cxx b/tests/link/driver.cxx
index 352cadd..da7e5b4 100644
--- a/tests/link/driver.cxx
+++ b/tests/link/driver.cxx
@@ -7,6 +7,7 @@
#ifndef __cpp_lib_modules
#include <set>
#include <utility> // pair
+#include <iostream> // cerr
#include <system_error>
#endif
@@ -15,12 +16,17 @@
#ifdef __cpp_modules
#ifdef __cpp_lib_modules
import std.core;
+import std.io;
#endif
import butl.path;
+import butl.path_io;
+import butl.utility;
import butl.fdstream;
import butl.filesystem;
#else
#include <libbutl/path.mxx>
+#include <libbutl/path-io.mxx>
+#include <libbutl/utility.mxx>
#include <libbutl/fdstream.mxx>
#include <libbutl/filesystem.mxx>
#endif
@@ -55,7 +61,6 @@ link_file (const path& target, const path& link, bool hard, bool check_content)
return s == text;
}
-#ifndef _WIN32
static bool
link_dir (const dir_path& target,
const dir_path& link,
@@ -69,12 +74,22 @@ link_dir (const dir_path& target,
else
mksymlink (target, link);
}
- catch (const system_error& e)
+ catch (const system_error&)
{
//cerr << e << endl;
return false;
}
+ {
+ auto pe (path_entry (link, false /* follow_symlinks */));
+ assert (pe.first && pe.second.type == entry_type::symlink);
+ }
+
+ {
+ auto pe (path_entry (link, true /* follow_symlinks */));
+ assert (!pe.first || pe.second.type == entry_type::directory);
+ }
+
if (!check_content)
return true;
@@ -90,7 +105,6 @@ link_dir (const dir_path& target,
return te == le;
}
-#endif
int
main ()
@@ -101,7 +115,16 @@ main ()
// faulty run) for the test files. Delete the directory only if the test
// succeeds to simplify the failure research.
//
- try_rmdir_r (td);
+ try
+ {
+ try_rmdir_r (td);
+ }
+ catch (const system_error& e)
+ {
+ cerr << "unable to remove " << td << ": " << e << endl;
+ return 1;
+ }
+
assert (try_mkdir (td) == mkdir_status::success);
// Prepare the target file.
@@ -131,27 +154,50 @@ main ()
// Create the file symlink using an unexistent file path.
//
assert (link_file (fp + "-a", td / path ("sa"), false, false));
+#endif
// Prepare the target directory.
//
dir_path dn ("dir");
dir_path dp (td / dn);
+
assert (try_mkdir (dp) == mkdir_status::success);
+
+ {
+ ofdstream ofs (dp / path ("f"));
+ ofs << text;
+ ofs.close ();
+ }
+
+#ifndef _WIN32
assert (link_file (fp, dp / path ("hlink"), true, true));
assert (link_file (fp, dp / path ("slink"), false, true));
+#endif
// Create the directory symlink using an absolute path.
//
- assert (link_dir (dp, td / dir_path ("dslink"), false, true));
+ dir_path ld (td / dir_path ("dslink"));
+ assert (link_dir (dp, ld, false, true));
- // Create the directory symlink using a relative path.
- //
- assert (link_dir (dn, td / dir_path ("rdslink"), false, true));
+ rmsymlink (ld);
+#ifndef _WIN32
// Create the directory symlink using an unexistent directory path.
//
assert (link_dir (dp / dir_path ("a"), td / dir_path ("dsa"), false, false));
+
+ // Create the directory symlink using a relative path.
+ //
+ assert (link_dir (dn, td / dir_path ("rdslink"), false, true));
#endif
- rmdir_r (td);
+ try
+ {
+ rmdir_r (td);
+ }
+ catch (const system_error& e)
+ {
+ cerr << "unable to remove " << td << ": " << e << endl;
+ return 1;
+ }
}