Skip to content

Commit d62377a

Browse files
committed
test/system: Test 'completion' with two invalid and valid arguments
... in addition to the existing tests for one invalid or valid argument. This is meant to further ensure that the 'completion' command takes exactly one positional argument from the ones listed in cobra.Command.ValidArgs, and as specified by cobra.ExactValidArgs(1). #1776
1 parent 966c823 commit d62377a

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

test/system/108-completion.bats

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ setup() {
6262
assert [ ${#stderr_lines[@]} -eq 2 ]
6363
}
6464

65-
@test "completion: Try with invalid arguments" {
65+
@test "completion: Try with one invalid argument" {
6666
run --keep-empty-lines --separate-stderr "$TOOLBX" completion foo
6767

6868
assert_failure
@@ -73,6 +73,28 @@ setup() {
7373
assert [ ${#stderr_lines[@]} -eq 2 ]
7474
}
7575

76+
@test "completion: Try with two invalid arguments" {
77+
run --keep-empty-lines --separate-stderr "$TOOLBX" completion foo bar
78+
79+
assert_failure
80+
assert [ ${#lines[@]} -eq 0 ]
81+
lines=("${stderr_lines[@]}")
82+
assert_line --index 0 "Error: accepts 1 arg(s), received 2"
83+
assert_line --index 1 "Run 'toolbox --help' for usage."
84+
assert [ ${#stderr_lines[@]} -eq 2 ]
85+
}
86+
87+
@test "completion: Try with two valid arguments" {
88+
run --keep-empty-lines --separate-stderr "$TOOLBX" completion bash fish
89+
90+
assert_failure
91+
assert [ ${#lines[@]} -eq 0 ]
92+
lines=("${stderr_lines[@]}")
93+
assert_line --index 0 "Error: accepts 1 arg(s), received 2"
94+
assert_line --index 1 "Run 'toolbox --help' for usage."
95+
assert [ ${#stderr_lines[@]} -eq 2 ]
96+
}
97+
7698
@test "completion: Try with unknown flag" {
7799
run --keep-empty-lines --separate-stderr "$TOOLBX" completion --foo
78100

0 commit comments

Comments
 (0)