From eb3c27b8f47c793244436cd082512bb8235bea89 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 22 May 2017 11:25:29 +0300 Subject: Add path-entry test --- tests/path-entry/buildfile | 7 +++++++ tests/path-entry/driver.cxx | 48 +++++++++++++++++++++++++++++++++++++++++++++ tests/path-entry/testscript | 33 +++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 tests/path-entry/buildfile create mode 100644 tests/path-entry/driver.cxx create mode 100644 tests/path-entry/testscript (limited to 'tests/path-entry') diff --git a/tests/path-entry/buildfile b/tests/path-entry/buildfile new file mode 100644 index 0000000..2b5b0a1 --- /dev/null +++ b/tests/path-entry/buildfile @@ -0,0 +1,7 @@ +# file : tests/path-entry/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +exe{driver}: cxx{driver} ../../libbutl/lib{butl} test{testscript} + +include ../../libbutl/ 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 +#include + +#include // operator<<(ostream, exception) +#include + +using namespace std; +using namespace butl; + +// Usage: argv[0] +// +// 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; +} diff --git a/tests/path-entry/testscript b/tests/path-entry/testscript new file mode 100644 index 0000000..a9f2c2e --- /dev/null +++ b/tests/path-entry/testscript @@ -0,0 +1,33 @@ +# file : tests/path-entry/testscript +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: existing +: +{ + : file + : + : Note that the newline character is translated into 2 characters being + : printed on Windows. This why we exclude it, to get consistent behavior on + : both POSIX and Windows. + : + cat <:'abc' >=f; + $* f >>EOO + regular + 3 + EOO + + : dir + : + : Note that the size value is meaningless for directory entries. + : + mkdir -p d; + $* d >>~/EOO/ + directory + /. + EOO +} + +: non-existent +: +$* f == 1 -- cgit v1.1