#######################################################
#
# Test GLOB_BRACE with findfiles()
#
#######################################################

body common control
{
      inputs => { "../../default.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };
      version => "1.0";
}

bundle common findfiles
{
  vars:
      "names" slist => { "a", "bc", "d/e/f", "g/h/i/j", "klm/nop/qrs" };
}

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

bundle agent init
{
  files:
      "$(G.testdir)/$(findfiles.names)"
      create => "true";

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


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

bundle agent test
{
  meta:
      "description" -> { "CFE-3292" }
        string => "Test that findfiles() works as expected.";

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

      "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
{
  vars:
      "expected[GLOB_BRACE]" string => "$(G.testdir)$(const.dirsep)a,$(G.testdir)$(const.dirsep)bc";

      "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";
}
