Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFE-3292: Removed soft fail related to the use of globs #5413

Merged
merged 9 commits into from
Feb 26, 2024
1 change: 1 addition & 0 deletions libpromises/dbm_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <known_dirs.h>
#include <string_lib.h>
#include <time.h> /* time() */
#include <glob_lib.h>


static bool DBPathLock(FileLock *lock, const char *filename);
Expand Down
2 changes: 2 additions & 0 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <string_lib.h>
#include <version_comparison.h>
#include <mutex.h> /* ThreadWait */
#include <glob_lib.h>

#include <math_eval.h>

Expand Down Expand Up @@ -8755,6 +8756,7 @@ static FnCallResult FnCallFindfilesUp(ARG_UNUSED EvalContext *ctx, ARG_UNUSED co
return FnFailure();
}

MapName(path); // Makes sure we get host native path separators
DeleteRedundantSlashes(path);

size_t len = strlen(path);
Expand Down
13 changes: 1 addition & 12 deletions tests/acceptance/01_vars/02_functions/findfiles-GLOB_BRACE.cf
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ body common control
bundle common findfiles
{
vars:
# * in filenames not allowed on win
windows::
"names" slist => { "a", "bc", "d/e/f", "g/h/i/j", "klm/nop/qrs" };
!windows::
"names" slist => { "a", "bc", "d/e/f", "g/h/i/j", "klm/nop/qrs", "tu/*" };
}

#######################################################
Expand All @@ -43,13 +39,6 @@ bundle agent test
"description" -> { "CFE-3292" }
string => "Test that findfiles() works as expected.";

#"test_suppress_fail" string => "windows",
# meta => { "redmine4730" };
# This test should be merged with findfiles.cf when it's fixed.
# In order to soft-fail it as requested, I had to strip it to a separate-test
"test_soft_fail" string => "any",
meta => { "CFE-3292" };

vars:
"patterns[GLOB_BRACE]" string => "$(G.testdir)/{a,bc}";

Expand All @@ -70,7 +59,7 @@ bundle agent test
bundle agent check
{
vars:
"expected[GLOB_BRACE]" string => "$(G.testdir)/a,$(G.testdir)/bc";
"expected[GLOB_BRACE]" string => "$(G.testdir)$(const.dirsep)a,$(G.testdir)$(const.dirsep)bc";

"expects" slist => getindices("expected");

Expand Down
33 changes: 18 additions & 15 deletions tests/acceptance/01_vars/02_functions/findfiles.cf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bundle common findfiles
# * in filenames not allowed on win
windows::
"names" slist => { "a", "bc", "d/e/f", "g/h/i/j", "klm/nop/qrs" };
!windows::
!windows::
"names" slist => { "a", "bc", "d/e/f", "g/h/i/j", "klm/nop/qrs", "tu/*" };
}

Expand All @@ -39,10 +39,6 @@ bundle agent init

bundle agent test
{
meta:
"test_suppress_fail" string => "windows",
meta => { "redmine4730,ENT-2145" };

vars:
"patterns[a]" string => "$(G.testdir)/?";
"patterns[b]" string => "$(G.testdir)/*";
Expand All @@ -52,13 +48,14 @@ bundle agent test
"patterns[relative_path_1]" string => "./*";
"patterns[relative_path_2]" string => "**";
"patterns[relative_path_3]" string => "../**";

!windows::
!windows::
# First of all '*' is an illegal filename on Windows. Also you cannot
# escape wildcards with backslash when it is a file separator.
"patterns[f]" string => "$(G.testdir)/tu/\\*";
"patterns[g]" string => "$(G.testdir)/**";
any::
"patterns[g]" string => "$(G.testdir)/*/**";
"patterns[h]" string => "$(G.testdir)/**/j";

any::
"pnames" slist => getindices("patterns");

"found[$(pnames)]" slist => findfiles("$(patterns[$(pnames)])");
Expand All @@ -76,27 +73,33 @@ bundle agent test
bundle agent check
{
vars:
"expected[a]" string => "$(G.testdir)/a,$(G.testdir)/d,$(G.testdir)/g";
windows::
"expected[b]" string => "$(G.testdir)/a,$(G.testdir)/bc,$(G.testdir)/d,$(G.testdir)/g,$(G.testdir)/klm";
!windows::
"expected[a]" string => "$(G.testdir)/a,$(G.testdir)/d,$(G.testdir)/g";
"expected[b]" string => "$(G.testdir)/a,$(G.testdir)/bc,$(G.testdir)/d,$(G.testdir)/g,$(G.testdir)/klm,$(G.testdir)/tu";

any::
"expected[c]" string => "$(G.testdir)/d/e,$(G.testdir)/g/h";
"expected[d]" string => "$(G.testdir)/a,$(G.testdir)/bc";
"expected[e]" string => "";

!windows::
"expected[f]" string => "$(G.testdir)/tu/*";
"expected[g]" string => "$(G.testdir)/a,$(G.testdir)/bc,$(G.testdir)/d,$(G.testdir)/g,$(G.testdir)/klm,$(G.testdir)/tu,$(G.testdir)/d/e,$(G.testdir)/g/h,$(G.testdir)/klm/nop,$(G.testdir)/tu/*,$(G.testdir)/d/e/f,$(G.testdir)/g/h/i,$(G.testdir)/klm/nop/qrs,$(G.testdir)/g/h/i/j";
"expected[h]" string => "$(G.testdir)/g/h/i/j";
windows::
"expected[a]" string => "$(G.testdir)\\a,$(G.testdir)\\d,$(G.testdir)\\g";
"expected[b]" string => "$(G.testdir)\\a,$(G.testdir)\\bc,$(G.testdir)\\d,$(G.testdir)\\g,$(G.testdir)\\klm";

"expected[c]" string => "$(G.testdir)\\d\\e,$(G.testdir)\\g\\h";
"expected[d]" string => "$(G.testdir)\\a,$(G.testdir)\\bc";
"expected[e]" string => "";

"expected[g]" string => "$(G.testdir)\\a,$(G.testdir)\\bc,$(G.testdir)\\d,$(G.testdir)\\g,$(G.testdir)\\klm,$(G.testdir)\\d\\e,$(G.testdir)\\g\\h,$(G.testdir)\\klm\\nop,$(G.testdir)\\d\\e\\f,$(G.testdir)\\g\\h\\i,$(G.testdir)\\klm\\nop\\qrs,$(G.testdir)\\g\\h\\i\\j";
"expected[h]" string => "$(G.testdir)\\g\\h\\i\\j";
any::
# relative paths are skipped, thus return empty list
"expected[relative_path_1]" string => "";
"expected[relative_path_2]" string => "";
"expected[relative_path_3]" string => "";

any::
"expects" slist => getindices("expected");

"fstring" slist => getindices("test.found_string");
Expand Down
114 changes: 114 additions & 0 deletions tests/acceptance/01_vars/02_functions/findfiles_glob_bracket.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#######################################################
#
# Test that square bracket works in glob patterns
#
#######################################################

body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => { "init", "test", "check" };
version => "1.0";
}

#######################################################

bundle agent init
{
vars:
"filenames"
slist => { "foo", "bar", "baz" };

files:
"$(G.testdir)/$(filenames)"
create => "true";

reports:
DEBUG::
"Created $(G.testdir)/$(filenames)";
}


#######################################################

bundle agent test
{
meta:
"description"
string => "Test that square bracket works in glob patterns.";

vars:
"patterns[a]"
string => "$(G.testdir)/[f]oo";
"patterns[b]"
string => "$(G.testdir)/b[a]r";
"patterns[c]"
string => "$(G.testdir)/ba[z]";
"patterns[d]"
string => "$(G.testdir)/[a-z][a-z][a-z]";
"patterns[e]"
string => "$(G.testdir)/ba[rz]";
"patterns[f]"
string => "$(G.testdir)/[fb][oa][orz]";

"pnames"
slist => getindices("patterns");
"found[$(pnames)]"
slist => findfiles("$(patterns[$(pnames)])");
"found_string[$(pnames)]"
string => join(",", "found[$(pnames)]");

reports:
DEBUG::
"findfiles pattern $(pnames) '$(patterns[$(pnames)])' => '$(found_string[$(pnames)])'";
}


#######################################################

bundle agent check
{
meta:
"test_skip_needs_work" string => "windows",
meta => { "ENT-11176" };

vars:
"expected[a]"
string => "$(G.testdir)$(const.dirsep)foo";
"expected[b]"
string => "$(G.testdir)$(const.dirsep)bar";
"expected[c]"
string => "$(G.testdir)$(const.dirsep)baz";
"expected[d]"
string => "$(G.testdir)$(const.dirsep)bar,$(G.testdir)$(const.dirsep)baz,$(G.testdir)$(const.dirsep)foo";
"expected[e]"
string => "$(G.testdir)$(const.dirsep)bar,$(G.testdir)$(const.dirsep)baz";
"expected[f]"
string => "$(G.testdir)$(const.dirsep)bar,$(G.testdir)$(const.dirsep)baz,$(G.testdir)$(const.dirsep)foo";

"expects"
slist => getindices("expected");
"fstring"
slist => getindices("test.found_string");
"joint_condition"
string => join(".", "expects");

classes:
"$(expects)"
expression => strcmp("$(test.found_string[$(expects)])", "$(expected[$(expects)])");
"ok"
expression => "$(joint_condition)";

reports:
DEBUG::
"pattern $(expects) matches as expected: '$(expected[$(expects)])'"
if => "$(expects)";

"pattern $(expects) does NOT match expected: '$(test.found_string[$(expects)])' != '$(expected[$(expects)])'"
if => "!$(expects)";

ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}
Loading
Loading