1######################################################
2#
3#  Test that not() behaves as expected
4#
5#####################################################
6body common control
7{
8    inputs => { "../../default.cf.sub" };
9    bundlesequence  => { default("$(this.promise_filename)") };
10    version => "1.0";
11}
12
13#######################################################
14
15bundle agent test
16{
17  meta:
18    "description" -> { "CFE-3470" }
19      string => "Test that not() behaves as expected";
20
21  classes:
22    "ok"
23      scope => "namespace",
24      and => {
25        # Simple case:
26        "any",
27        not("!any"),
28        "cfengine",
29        not("!cfengine"),
30
31        # Variable expansion:
32        "$(true_variable)",
33        not("$(false_variable)"),
34        not(not("$(true_variable)")),
35        not(not(not("$(false_variable)"))),
36
37        # Double expand:
38        not(not("$($(true_variable_name))")),
39        not(not(not("$($(false_variable_name))"))),
40
41        # Triple expand:
42        not(not("$($($(true_variable_name_name)))")),
43        not(not(not("$($($(false_variable_name_name)))"))),
44
45        # not() should always return any or !any,
46        # this is important for backwards compatibility:
47        strcmp(not("any"), "!any"),
48        strcmp(not("!any"), "any"),
49        strcmp(not("!cfengine"), "any"),
50        strcmp(not("!(cfengine.!cfengine)"), "!any"),
51        strcmp(not("$(true_variable)"), "!any"),
52        strcmp(not("$(false_variable)"), "any"),
53      };
54
55    # In both of these cases we expect the function call (and promise)
56    # to be skipped because of the unresolved variable:
57    # This tests function/promise skipping because of unresolved variables,
58    # but also that there is no syntax / type error, when the unresolved
59    # function call stays in the and list forever (Never resolved).
60    "fail_one"
61      and => {
62        "any",
63        not("$(unresolved_var)"),
64      };
65    "fail_two"
66      and => {
67        "any",
68        not(not("$(unresolved_var)")),
69      };
70    "fail"
71      scope => "namespace",
72      expression => "fail_one|fail_two";
73
74  vars:
75    "false_variable"
76      string => "cfengine.(!cfengine)";
77    "true_variable"
78      string => "cfengine|(!cfengine)";
79    "false_variable_name"
80      string => "false_variable";
81    "true_variable_name"
82      string => "true_variable";
83    "false_variable_name_name"
84      string => "false_variable_name";
85    "true_variable_name_name"
86      string => "true_variable_name";
87
88}
89
90#######################################################
91
92bundle agent check
93{
94
95  reports:
96    ok.(!fail)::
97      "$(this.promise_filename) Pass";
98    (!ok)|fail::
99      "$(this.promise_filename) FAIL";
100}
101