diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-06-01 01:23:55 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-06-01 01:23:55 +0300 |
commit | 8f0390dfa6d66ed322f6d4ad2306353c1669bfac (patch) | |
tree | db16403455af80a60a8fab8e13433a4445f51c33 | |
parent | 22dcb13424c3a098e2f87716a9ca6e72f610f845 (diff) |
Remove redundant assertion in path_match(path, path, dir_path)
-rw-r--r-- | libbutl/filesystem.cxx | 20 | ||||
-rw-r--r-- | tests/wildcard/driver.cxx | 61 |
2 files changed, 40 insertions, 41 deletions
diff --git a/libbutl/filesystem.cxx b/libbutl/filesystem.cxx index 1ea4cf8..0e1cda5 100644 --- a/libbutl/filesystem.cxx +++ b/libbutl/filesystem.cxx @@ -2126,21 +2126,13 @@ namespace butl auto match = [&entry, &r] (path&& p, const std::string&, bool interim) { - if (p == entry) + // If we found the entry (possibly through one of the recursive + // components) no need to search further. + // + if (p == entry && !interim) { - // If we found the entry (possibly through one of the recursive - // components) no need to search further. - // - if (!interim) - { - r = true; - return false; - } - else - // For self-matching the callback is first called in the interim - // mode (through the preopen function) with an empty path. - // - assert (p.empty ()); + r = true; + return false; } return true; diff --git a/tests/wildcard/driver.cxx b/tests/wildcard/driver.cxx index bbe75a8..cecee07 100644 --- a/tests/wildcard/driver.cxx +++ b/tests/wildcard/driver.cxx @@ -172,38 +172,45 @@ try else path_search (pattern, *entry, add, start); - // Test search in the directory tree represented by the path. + // It the search succeeds, then test search in the directory tree + // represented by each matched path. Otherwise, if the directory tree is + // specified, then make sure that it doesn't match the pattern. // - for (const auto& p: path_count) + if (!path_count.empty ()) { - // Will match multiple times if the pattern contains several recursive - // components. - // - size_t match_count (0); - - auto check = [&p, &match_count] (path&& pe, const string&, bool interim) + for (const auto& p: path_count) { - if (pe == p.first) + // Will match multiple times if the pattern contains several recursive + // components. + // + size_t match_count (0); + + auto check = [&p, &match_count] (path&& pe, const string&, bool inter) { - if (!interim) - ++match_count; - else - // For self-matching the callback is first called in the interim - // mode (through the preopen function) with an empty path. - // - assert (pe.empty ()); - } - - return true; - }; - - path_search (pattern, p.first, check, start); - assert (match_count == p.second); - - // Test path match. - // - assert (path_match (pattern, p.first, start)); + if (pe == p.first) + { + if (!inter) + ++match_count; + else + // For self-matching the callback is first called in the interim + // mode (through the preopen function) with an empty path. + // + assert (pe.empty ()); + } + + return true; + }; + + path_search (pattern, p.first, check, start); + assert (match_count == p.second); + + // Test path match. + // + assert (path_match (pattern, p.first, start)); + } } + else if (entry) + assert (!path_match (pattern, *entry, start)); // Print the found paths. // |