Skip to content

Commit e74c980

Browse files
committed
Add shell test for format --line-length subcommand
1 parent 8e215c5 commit e74c980

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/cfengine_cli/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def _get_arg_parser():
4343
subp.add_parser("deploy", help="Deploy a built policy set")
4444
fmt = subp.add_parser("format", help="Autoformat .json and .cf files")
4545
fmt.add_argument("files", nargs="*", help="Files to format")
46-
fmt.add_argument(
47-
"--line-length", default=80, type=int, help="Maximum line length"
48-
)
46+
fmt.add_argument("--line-length", default=80, type=int, help="Maximum line length")
4947
subp.add_parser(
5048
"lint",
5149
help="Look for syntax errors and other simple mistakes",

tests/shell/003-format.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
# Verify that the line length parameter shows up in help
7+
cfengine format -h | grep -- "--line-length"
8+
9+
# Test three common line length
10+
for ll in 80 100 120; do
11+
# Format the following HEREDOC and let wc count the longest line
12+
l=$(cfengine format --line-length $ll - <<-EOF |
13+
bundle agent slists
14+
{
15+
vars:
16+
"variable_name"
17+
slist => { "one", "two", "three", "four", "five", "six" };
18+
"variable_name"
19+
slist => { "one", "two", "three", "four", "five", "six", "seven" };
20+
"variable_name"
21+
slist => {
22+
"one", "two", "three", "four", "five", "six", "seven", "eight"
23+
};
24+
"variable_name"
25+
slist => {
26+
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen",
27+
};
28+
"variable_name"
29+
slist => {
30+
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen"
31+
};
32+
}
33+
EOF
34+
wc -L)
35+
# Verify that the actual longest line has less or equal characters
36+
[[ $l -le $ll ]]
37+
done

0 commit comments

Comments
 (0)