From 8f0390dfa6d66ed322f6d4ad2306353c1669bfac Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 1 Jun 2018 01:23:55 +0300 Subject: Remove redundant assertion in path_match(path, path, dir_path) --- libbutl/filesystem.cxx | 20 +++++----------- 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. // -- cgit v1.1