Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
569 changes: 369 additions & 200 deletions src/cfengine_cli/lint.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/lint/008_namespace.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
methods:
"x" usebundle => default:target("arg");
^------------^
Error: Call to unknown function / bundle / body 'default:target' at tests/lint/008_namespace.x.cf:15:22
Error: Call to unknown bundle 'default:target' at tests/lint/008_namespace.x.cf:15:22
FAIL: tests/lint/008_namespace.x.cf (1 error)
Failure, 1 error in total.
3 changes: 3 additions & 0 deletions tests/lint/014_num_args_body.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
perms => mog("644");
^--------^
Error: Expected 3 arguments, received 1 for body 'mog' at tests/lint/014_num_args_body.x.cf:13:16
Hint: The body 'mog' is defined at tests/lint/014_num_args_body.x.cf:1:12

create => "true",
perms => mog("644", "root");
^----------------^
Error: Expected 3 arguments, received 2 for body 'mog' at tests/lint/014_num_args_body.x.cf:16:16
Hint: The body 'mog' is defined at tests/lint/014_num_args_body.x.cf:1:12

create => "true",
perms => mog("644", "root", "root", "root");
^--------------------------------^
Error: Expected 3 arguments, received 4 for body 'mog' at tests/lint/014_num_args_body.x.cf:22:16
Hint: The body 'mog' is defined at tests/lint/014_num_args_body.x.cf:1:12
FAIL: tests/lint/014_num_args_body.x.cf (3 errors)
Failure, 3 errors in total.
3 changes: 3 additions & 0 deletions tests/lint/014_num_args_bundle.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
usebundle => test();
^----^
Error: Expected 2 arguments, received 0 for bundle 'test' at tests/lint/014_num_args_bundle.x.cf:5:20
Hint: The bundle 'test' is defined at tests/lint/014_num_args_bundle.x.cf:13:14

"test2"
usebundle => test("a");
^-------^
Error: Expected 2 arguments, received 1 for bundle 'test' at tests/lint/014_num_args_bundle.x.cf:7:20
Hint: The bundle 'test' is defined at tests/lint/014_num_args_bundle.x.cf:13:14

"test4"
usebundle => test("a", "b", "c");
^-----------------^
Error: Expected 2 arguments, received 3 for bundle 'test' at tests/lint/014_num_args_bundle.x.cf:11:20
Hint: The bundle 'test' is defined at tests/lint/014_num_args_bundle.x.cf:13:14
FAIL: tests/lint/014_num_args_bundle.x.cf (3 errors)
Failure, 3 errors in total.
2 changes: 2 additions & 0 deletions tests/lint/016_macro_multi_def_bundle.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
usebundle => test();
^----^
Error: Expected 1 or 2 arguments, received 0 for bundle 'test' at tests/lint/016_macro_multi_def_bundle.x.cf:20:20
Hint: The bundle 'test' is defined at tests/lint/016_macro_multi_def_bundle.x.cf:2:14 and tests/lint/016_macro_multi_def_bundle.x.cf:8:14

"test2"
usebundle => test("hello", "world", "!");
^-------------------------^
Error: Expected 1 or 2 arguments, received 3 for bundle 'test' at tests/lint/016_macro_multi_def_bundle.x.cf:23:20
Hint: The bundle 'test' is defined at tests/lint/016_macro_multi_def_bundle.x.cf:2:14 and tests/lint/016_macro_multi_def_bundle.x.cf:8:14
FAIL: tests/lint/016_macro_multi_def_bundle.x.cf (2 errors)
Failure, 2 errors in total.
29 changes: 25 additions & 4 deletions tests/lint/018_implies_body.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,37 @@
"/tmp/test1"
copy_from => helper("oops");
^----^
Error: Call to unknown function / bundle / body 'helper' at tests/lint/018_implies_body.x.cf:17:20
Error: Expected a body but 'helper' is a bundle at tests/lint/018_implies_body.x.cf:17:20

"/tmp/test2"
copy_from => unknown_name("oops");
^----------^
Error: Call to unknown function / bundle / body 'unknown_name' at tests/lint/018_implies_body.x.cf:19:20
Error: Call to unknown body 'unknown_name' at tests/lint/018_implies_body.x.cf:19:20

"/tmp/test3"
copy_from => mycopy("/src");
^------------^
Error: Expected 2 arguments, received 1 for body 'mycopy' at tests/lint/018_implies_body.x.cf:21:20
FAIL: tests/lint/018_implies_body.x.cf (3 errors)
Failure, 3 errors in total.
Hint: The body 'mycopy' is defined at tests/lint/018_implies_body.x.cf:1:16

"/tmp/test4"
copy_from => readfile("/etc/file", "100");
^------^
Error: Expected a body but 'readfile' is a built-in function at tests/lint/018_implies_body.x.cf:23:20

"test5"
usebundle => mycopy("/src", "host");
^----^
Error: Expected a bundle but 'mycopy' is a body at tests/lint/018_implies_body.x.cf:26:20

"test6"
usebundle => readfile("/etc/file", "100");
^------^
Error: Expected a bundle but 'readfile' is a built-in function at tests/lint/018_implies_body.x.cf:28:20

"test7"
usebundle => unknown_bundle("oops");
^------------^
Error: Call to unknown bundle 'unknown_bundle' at tests/lint/018_implies_body.x.cf:30:20
FAIL: tests/lint/018_implies_body.x.cf (7 errors)
Failure, 7 errors in total.
9 changes: 9 additions & 0 deletions tests/lint/018_implies_body.x.cf
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ bundle agent main
copy_from => unknown_name("oops");
"/tmp/test3"
copy_from => mycopy("/src");
"/tmp/test4"
copy_from => readfile("/etc/file", "100");
methods:
"test5"
usebundle => mycopy("/src", "host");
"test6"
usebundle => readfile("/etc/file", "100");
"test7"
usebundle => unknown_bundle("oops");
}
22 changes: 22 additions & 0 deletions tests/lint/019_nested_calls.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
body copy_from mycopy(from)
{
source => "$(from)";
}

bundle agent helper(arg)
{
reports:
"$(arg)";
}

bundle agent main
{
files:
"/tmp/test"
copy_from => mycopy(readfile("/etc/source", "100"));
methods:
"test"
usebundle => helper(format("hello %s", "world"));
vars:
"x" string => format("nested: %s", getuid("root"));
}
22 changes: 22 additions & 0 deletions tests/lint/019_nested_calls.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

"test1"
usebundle => helper(helper("nested-bundle"));
^----^
Error: Expected a built-in function but 'helper' is a bundle at tests/lint/019_nested_calls.x.cf:16:27

"test2"
usebundle => helper(mycopy("nested-body"));
^----^
Error: Expected a built-in function but 'mycopy' is a body at tests/lint/019_nested_calls.x.cf:18:27

"test3"
usebundle => helper(unknown_name("oops"));
^----------^
Error: Call to unknown function 'unknown_name' at tests/lint/019_nested_calls.x.cf:20:27

"/tmp/test4"
copy_from => mycopy(unknown_name("oops"));
^----------^
Error: Call to unknown function 'unknown_name' at tests/lint/019_nested_calls.x.cf:23:27
FAIL: tests/lint/019_nested_calls.x.cf (4 errors)
Failure, 4 errors in total.
24 changes: 24 additions & 0 deletions tests/lint/019_nested_calls.x.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
body copy_from mycopy(from)
{
source => "$(from)";
}

bundle agent helper(arg)
{
reports:
"$(arg)";
}

bundle agent main
{
methods:
"test1"
usebundle => helper(helper("nested-bundle"));
"test2"
usebundle => helper(mycopy("nested-body"));
"test3"
usebundle => helper(unknown_name("oops"));
files:
"/tmp/test4"
copy_from => mycopy(unknown_name("oops"));
}
Loading