-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path20-help.bats
More file actions
78 lines (64 loc) · 1.61 KB
/
20-help.bats
File metadata and controls
78 lines (64 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bats
#
# 20 - cli tests
#
load app
@test "help prints, app exits with status code 1 when no arguments are passed" {
run $APP
[ $status -eq 1 ]
[[ "$output" == *"Usage:"* ]]
}
@test "help prints, warns on invalid flags and arguments" {
run $APP invalid-argument
[ $status -eq 10 ]
[[ "$output" == *"unrecognized command"* ]]
run $APP --invalid-flag
[ $status -eq 10 ]
[[ "$output" == *"unrecognized flag"* ]]
}
#
# subcommands...
#
@test "help is provided for all dex commands" {
for cmd in ${APP_CMDS[@]} ; do
echo "testing $cmd"
run $APP help $cmd
[ $status -eq 0 ]
done
}
@test "help is provided whenever -h or --help flags are passed to a command" {
for cmd in ${APP_CMDS[@]} ; do
echo "testing $cmd"
run $APP $cmd -h
[ $status -eq 0 ]
[ -n "$output" ]
diff <($APP $cmd -h) <($APP help $cmd)
diff <($APP $cmd --help) <($APP help $cmd)
done
}
@test "help exits with status code 1 when no arguments are passed to a command" {
for cmd in ${APP_CMDS[@]} ; do
echo "testing $cmd"
[ "$cmd" = "ls" ] && continue
run $APP $cmd
[ $status -eq 1 ]
done
}
@test "help exits with status code 10 when invalid arguments are passed to a command" {
local skip_args=(
install
ls
run
)
for cmd in ${APP_CMDS[@]} ; do
echo "testing $cmd"
run $APP $cmd --invalid-flag
[ $status -eq 10 ]
[[ "$output" == *"unrecognized flag"* ]]
is/in_list "$cmd" "${skip_args[@]}" && continue
run $APP $cmd invalid-argument
echo "${lines[@]}"
[ $status -eq 10 ]
[[ "$output" == *"unrecognized argument"* ]]
done
}