diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wildcard/driver.cxx | 49 | ||||
-rw-r--r-- | tests/wildcard/testscript | 624 |
2 files changed, 632 insertions, 41 deletions
diff --git a/tests/wildcard/driver.cxx b/tests/wildcard/driver.cxx index 1e600f6..9e3d1b7 100644 --- a/tests/wildcard/driver.cxx +++ b/tests/wildcard/driver.cxx @@ -12,6 +12,7 @@ #include <libbutl/path.hxx> #include <libbutl/utility.hxx> // operator<<(ostream, exception) +#include <libbutl/optional.hxx> #include <libbutl/filesystem.hxx> using namespace std; @@ -28,25 +29,37 @@ using namespace butl; int _CRT_glob = 0; #endif -// Usage: argv[0] (-m <pattern> <name> | -s [-n] <pattern> [<dir>]) +// Usages: // -// Execute actions specified by -m or -s options. Exit with code 0 if succeed, +// argv[0] -mn <pattern> <name> +// argv[0] -sd [-n] <pattern> [<dir>] +// argv[0] -sp [-n] <pattern> <path> [<dir>] +// +// Execute actions specified by the first option. Exit with code 0 if succeed, // 1 if fail, 2 on the underlying OS error (print error description to STDERR). // -// -m +// -mn // Match a name against the pattern. // -// -s +// -sd // Search for paths matching the pattern in the directory specified (absent // directory means the current one). Print the matching canonicalized paths // to STDOUT in the ascending order. Succeed if at least one matching path -// is found. Note that this option must go first in the command line. +// is found. For each matching path we will assert that it is also get +// matched being searched in the directory tree represented by this path +// itself. +// +// Note that the driver excludes from search file system entries which names +// start from dot, unless the pattern explicitly matches them. // -// Also note that the driver excludes from search file system entries which -// names start from dot, unless the pattern explicitly matches them. +// -sp +// Same as above, but behaves as if the directory tree being searched +// through contains only the specified entry. The start directory is used if +// the first pattern component is a self-matching wildcard. // // -n -// Do not sort paths found. +// Do not sort paths found. Meaningful in combination with -sd or -sp +// options and must follow it, if specified in the command line. // int main (int argc, const char* argv[]) @@ -55,10 +68,8 @@ try assert (argc >= 2); string op (argv[1]); - bool match (op == "-m"); - assert (match || op == "-s"); - if (match) + if (op == "-mn") { assert (argc == 4); @@ -66,9 +77,9 @@ try string name (argv[3]); return path_match (pattern, name) ? 0 : 1; } - else + else if (op == "-sd" || op == "-sp") { - assert (argc >= 3); + assert (argc >= (op == "-sd" ? 3 : 4)); bool sort (true); int i (2); @@ -84,6 +95,11 @@ try assert (i != argc); // Still need pattern. path pattern (argv[i++]); + optional<path> entry; + + if (op == "-sp") + entry = path (argv[i++]); + dir_path start; if (i != argc) start = dir_path (argv[i++]); @@ -133,7 +149,10 @@ try return true; }; - path_search (pattern, add, start); + if (!entry) + path_search (pattern, add, start); + else + path_search (pattern, *entry, add, start); // Test search in the directory tree represented by the path. // @@ -178,6 +197,8 @@ try return paths.empty () ? 1 : 0; } + else + assert (false); } catch (const invalid_path& e) { diff --git a/tests/wildcard/testscript b/tests/wildcard/testscript index 48159e2..489f724 100644 --- a/tests/wildcard/testscript +++ b/tests/wildcard/testscript @@ -2,10 +2,10 @@ # copyright : Copyright (c) 2014-2017 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -: path-match +: path-name-match : { - test.options = -m + test.options = -mn $* foo/ foo == 1 : dir-vs-file $* foo foo/ == 1 : file-vs-dir @@ -89,10 +89,10 @@ } } -: path-search +: path-directory-search : { - test.options = -s + test.options = -sd : start : @@ -163,17 +163,17 @@ : self-recursive : - { - : start - : + { + : start + : $* f*** ../../foo >>/EOO bar/fox EOO : current : - mkdir -p bar/fox; - touch bar/fox/cox; + mkdir -p bar/fox; + touch bar/fox/cox; $* c*** >>/EOO bar/fox/cox EOO @@ -201,12 +201,12 @@ : self-recursive : - { - : start - : - : Note that the start dir is represented as an empty path being - : found. - : + { + : start + : + : Note that the start dir is represented as an empty path being + : found. + : $* f***/ ../../foo >>/EOO bar/fox/ @@ -214,7 +214,7 @@ : current : - mkdir -p bar/cox/box/; + mkdir -p bar/cox/box/; $* c***/ >>/EOO bar/cox/ @@ -249,9 +249,9 @@ : self-recursive : - { - : pattern - : + { + : pattern + : $* foo/f*** ../.. >>/EOO foo/fox EOO @@ -264,12 +264,12 @@ : current : - mkdir -p bar; - touch bar/cox; + mkdir -p bar; + touch bar/cox; $* c*** >>/EOO bar/cox EOO - } + } } : dir @@ -297,9 +297,9 @@ : self-recursive : - { - : pattern - : + { + : pattern + : $* foo/f***/b**/ ../.. >>/EOO foo/bar/ foo/fox/box/ @@ -316,13 +316,13 @@ : current : - mkdir -p bar/cox/box/; + mkdir -p bar/cox/box/; $* c***/b**/ >>/EOO bar/ bar/cox/box/ bar/cox/box/ EOO - } + } } } @@ -567,3 +567,573 @@ } } } + +: path-entry-search +: +{ + test.options = -sp + + : match + : + { + : fast-forward + : + { + : partial + : + $* foo/f** foo/fox >>/EOO + foo/fox + EOO + + : reduce + : + { + : file + : + $* foo foo >>EOO + foo + EOO + + : dir + : + $* foo/ foo/ >>/EOO + foo/ + EOO + } + } + + : iterating + : + { + : simple + : + { + : immediate + : + { + : file + : + $* f* foo >>EOO + foo + EOO + + : dir + : + $* f*/ foo/ >>/EOO + foo/ + EOO + } + + : distant + : + { + : file + : + $* f*/b* foo/bar >>/EOO + foo/bar + EOO + + : dir + : + $* f*/b*/ foo/bar/ >>/EOO + foo/bar/ + EOO + } + } + + : recursive + : + { + : immediate + : + { + : file + : + $* f** foo >>EOO + foo + EOO + + : dir + : + $* f**/ foo/ >>/EOO + foo/ + EOO + } + + : distant + : + { + : file + : + $* f** foo/fox >>/EOO + foo/fox + EOO + + : dir + : + $* f**/ foo/fox/ >>/EOO + foo/ + foo/fox/ + EOO + } + } + + : self + : + { + : immediate + : + { + : file + : + $* f*** foo fox/ >>EOO + foo + EOO + + : dir + : + $* f***/ foo/ fox/ >>/EOO + + foo/ + EOO + } + + : distant + : + { + : file + : + $* f*** foo/fox >>/EOO + foo/fox + EOO + + : dir + : + $* f***/ foo/fox/ foo/ >>/EOO + + foo/ + foo/fox/ + EOO + } + } + } + + : absolute + : + : When cross-testing we can't guarantee that host absolute paths are + : recognized by the target process. + : + if ($test.target == $build.host) + { + wd = $~ + + : both + : + { + : reduce + : + $* $wd/foo $wd/foo >>/"EOO" + $wd/foo + EOO + + : iterate + : + $* $wd/f**/ $wd/foo/fox/ >>/"EOO" + $wd/foo/ + $wd/foo/fox/ + EOO + } + + : pattern + : + { + : reduce + : + $* $wd/foo foo $wd >>/"EOO" + $wd/foo + EOO + + : iterate + : + $* $wd/f**/ foo/fox/ >>/"EOO" + $wd/pattern/iterate/foo/ + $wd/pattern/iterate/foo/fox/ + EOO + } + + : entry + : + { + : reduce + : + $* foo $wd/foo $wd >>/"EOO" + foo + EOO + + : iterate + : + $* f**/ $wd/entry/iterate/foo/fox/ >>/"EOO" + foo/ + foo/fox/ + EOO + } + } + } + + : no-match + : + { + : fast-forward + : + { + : partial + : + $* foo/f** fox/bar/baz/fix == 1 + + : reduce + : + { + : file + : + { + : not-exists + : + $* foo fox == 1 + + : not-file + : + $* foo foo/ == 1 + + : empy + : + { + : both + : + $* '' '' == 1 + + : pattern + : + $* '' foo == 1 + + : path + : + $* foo '' == 1 + } + } + + : dir + : + { + : not-exists + : + $* foo/ fox/ == 1 + + : not-dir + : + $* foo/ foo == 1 + + : empy + : + { + : pattern + : + $* '' foo/ == 1 + + : path + : + $* foo/ '' == 1 + } + } + } + } + + : iterating + : + { + : simple + : + { + : immediate + : + { + : file + : + { + : not-exists + : + $* f* bar == 1 + + : not-file + : + $* f* foo/ == 1 + + : empty + : + $* f* '' == 1 + } + + : dir + : + { + : not-exists + : + $* f*/ bar/ == 1 + + : not-dir + : + $* f*/ foo == 1 + + : empty + : + $* f*/ '' == 1 + } + } + + : distant + : + { + : file + : + { + : not-exists-other + : + $* f*/b* foo/fox == 1 + + : not-exists-none + : + $* f*/b* foo/ == 1 + + : not-file + : + $* f*/b* foo/bar/ == 1 + } + + : dir + : + { + : not-exists-other + : + $* f*/b*/ foo/fox/ == 1 + + : not-exists-none + : + $* f*/b*/ foo/ == 1 + + : not-dir + : + $* f*/b*/ foo/bar == 1 + } + } + } + + : recursive + : + { + : immediate + : + { + : file + : + { + : not-exists + : + $* f** bar == 1 + + : not-file + : + $* f** foo/ == 1 + } + + : dir + : + { + : not-exists + : + $* f**/ bar/ == 1 + + : not-dir + : + $* f**/ foo == 1 + } + } + + : distant + : + { + : file + : + { + : not-exists-other + : + $* f** foo/bar == 1 + + : not-exists-none + : + $* f** foo/ == 1 + + : not-file + : + $* f** foo/fox/ == 1 + } + + : dir + : + { + : not-exists-other + : + $* f*/b*/ foo/fox/ == 1 + + : not-exists-none + : + $* f*/b*/ foo/ == 1 + + : not-dir + : + $* f*/b*/ foo/bar == 1 + } + } + } + + + : self + : + { + : immediate + : + { + : file + : + { + : not-exists + : + $* f*** bar baz/ == 1 + + : not-file + : + $* f*** foo/ fox/ == 1 + } + + : dir + : + { + : not-exists + : + $* f***/ bar/ baz/ == 1 + + : not-dir + : + $* f***/ foo == 1 + } + } + + : distant + : + { + : file + : + { + : not-exists-other + : + $* f*** foo/bar == 1 + + : not-exists-none + : + $* f*** foo/ == 1 + + : not-file + : + $* f*** foo/fox/ fix/ == 1 + } + + : dir + : + { + : not-exists-other + : + $* f***/ bar/baz/ bak/ == 1 + + : not-exists-none + : + $* f***/ bar/ == 1 + + : not-dir + : + $* f***/ bar/foo == 1 + } + } + } + } + + : absolute + : + : When cross-testing we can't guarantee that host absolute paths are + : recognized by the target process. + : + if ($test.target == $build.host) + { + : reduce + : + { + : file + : + { + : not-exists + : + $* foo $~/fox == 1 + + : not-file + : + $* $~/foo foo/ == 1 + } + + : dir + : + { + : not-exists + : + $* $~/foo/ fox/ == 1 + + : not-dir + : + $* foo/ $~/foo == 1 + } + } + + : iterating + : + { + : file + : + { + : not-exists-other + : + $* $~/f** foo/bar == 1 + + : not-exists-none + : + $* f** $~/foo/ == 1 + + : not-file + : + $* $~/f** $~/foo/fox/ == 1 + } + + : dir + : + { + : not-exists-other + : + $* $~/f*/b*/ $~/foo/fox/ == 1 + + : not-exists-none + : + $* $~/f*/b*/ foo/ == 1 + + : not-dir + : + $* f*/b*/ $~/foo/bar == 1 + } + } + } + } +} |