#######################################################
#
# Test that it is invalid to define variables in remote bundles
#
#######################################################

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

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

bundle agent test
{
  vars:
      "check.variable"
	string => "is defined from bundle $(this.bundle)",
        comment => "This should not be allowed, perhaps the first part
                    of the variable should be canonified, or it should
                    be a parser error";

      "prefix.variable"
        string => "value-ok",
        comment => "This should be allowed because there is no such
                    bundle called 'prefix'";

      "array[with.a.dot]"
	string => "value",
	comment => "dots should be allowed in array keys";
}
#######################################################

bundle agent check
{
  meta:
      "description" -> {"CFE-1915"}
        string => "Test that it is invalid to define variables in remote bundles";

  classes:
      "variable_defined" expression => isvariable("variable");
      "variable_has_content" expression => regcmp(".*", "$(variable)");
      "prefixed_var_fail" expression => not(strcmp("$(prefix.variable)", "value-ok"));
      "array_with_a_dot_fail" expression => not(strcmp("$(test.array[with.a.dot])", "value"));

      "fail" expression => "(variable_defined|variable_has_content|prefixed_var_fail|array_with_a_dot_fail)";

  reports:
    DEBUG::
      "'variable' in bundle '$(this.bundle)' is defined"
        if => "variable_defined";

      "'variable' in bundle '$(this.bundle)' = '$(variable)'"
        if => "variable_has_content";

      "'prefix.variable' = $(prefix.variable)"
        if => "prefixed_var_fail";

      "array[with.a.dot] has the value '$(test.array[with.a.dot])'"
        if => "array_with_a_dot_fail";

    !fail::
      "$(this.promise_filename) Pass";

    fail::
      "$(this.promise_filename) FAIL";
}
