diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-05-22 11:25:29 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-05-22 11:34:55 +0300 |
commit | eb3c27b8f47c793244436cd082512bb8235bea89 (patch) | |
tree | f48a26e4b9185ffbdabe2cbf136b7dfe6e94fc86 /tests/path-entry/driver.cxx | |
parent | 912fbc4de72b8efbae5d49c502aad197177f03bf (diff) |
Add path-entry test
Diffstat (limited to 'tests/path-entry/driver.cxx')
-rw-r--r-- | tests/path-entry/driver.cxx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/path-entry/driver.cxx b/tests/path-entry/driver.cxx new file mode 100644 index 0000000..4f36f61 --- /dev/null +++ b/tests/path-entry/driver.cxx @@ -0,0 +1,48 @@ +// file : tests/path-entry/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <iostream> +#include <system_error> + +#include <libbutl/utility.hxx> // operator<<(ostream, exception) +#include <libbutl/filesystem.hxx> + +using namespace std; +using namespace butl; + +// Usage: argv[0] <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. +// +int +main (int argc, const char* argv[]) +try +{ + assert (argc == 2); + + auto es (path_entry (argv[1])); + + if (!es.first) + return 1; + + switch (es.second.type) + { + case entry_type::unknown: cout << "unknown"; break; + case entry_type::regular: cout << "regular"; break; + case entry_type::directory: cout << "directory"; break; + case entry_type::symlink: cout << "symlink"; break; + case entry_type::other: cout << "other"; break; + } + + cout << endl << es.second.size << endl; + return 0; +} +catch (const system_error& e) +{ + cerr << e << endl; + return 2; +} |