#######################################################
#
# Delete a file in a nonexistent directory.
#
#######################################################
body common control
{
  inputs => { "../../default.sub.cf" };
  bundlesequence => { default("$(this.promise_filename)") };
  version => "1.0";
  cache_system_functions => "false";
}

#######################################################
bundle agent init
{
  vars:
    "checkdir" string => "$(G.testdir)/should-not-show-up-in-output";

  files:
    "$(checkdir)/." create => "true";
}

#######################################################
bundle agent test
{
  vars:
    "agent"
      string => execresult(
        "$(sys.cf_agent) -Kf $(this.promise_filename).sub -D AUTO 2>&1",
        "useshell"
      );
}

#######################################################
bundle agent check
{
  classes:
    "checkpoint_fail" not => regcmp(".*CHECKPOINT.*", $(test.agent));

    "fail"
      or => {
        checkpoint_fail,
        regcmp(".*Unable to read link.*", $(test.agent)),
        regcmp(".*$(init.checkdir).*", $(test.agent)),
      };

  reports:
    DEBUG::
      "This should only pass if $(this.promise_filename).sub does not output anything about failing to readlink";
      "Output from $(this.promise_filename).sub: $(test.agent)";

    DEBUG.checkpoint_fail::
      "The secondary policy in $(this.promise_filename).sub did not checkpoint correctly";

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

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

### PROJECT_ID: core
### CATEGORY_ID: 27
