Commit | Line | Data |
---|---|---|
4bf5c85f SM |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2019 EfficiOS Inc. | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify it | |
6 | # under the terms of the GNU General Public License, version 2 only, as | |
7 | # published by the Free Software Foundation. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | # more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License along with | |
15 | # this program; if not, write to the Free Software Foundation, Inc., 51 | |
16 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | ||
18 | SH_TAP=1 | |
19 | ||
20 | if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then | |
21 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" | |
22 | else | |
23 | UTILSSH="$(dirname "$0")/../utils/utils.sh" | |
24 | fi | |
25 | ||
26 | # shellcheck source=../utils/utils.sh | |
27 | source "$UTILSSH" | |
28 | ||
29 | plan_tests 21 | |
30 | ||
365a0459 SM |
31 | stdout=$(mktemp -t test_help_stdout.XXXXXX) |
32 | stderr=$(mktemp -t test_help_stderr.XXXXXX) | |
4bf5c85f SM |
33 | |
34 | # Return 0 if file "$1" exists and is empty, non-0 otherwise. | |
35 | ||
36 | is_empty() | |
37 | { | |
38 | [[ -f "$1" && ! -s "$1" ]] | |
39 | } | |
40 | ||
41 | # Test with a working plugin name. | |
42 | bt_cli "${stdout}" "${stderr}" help ctf | |
43 | ok $? "help ctf plugin exit status" | |
44 | ||
45 | grep --silent 'Description: CTF input and output' "${stdout}" | |
46 | ok $? "help ctf plugin expected output" | |
47 | ||
48 | is_empty "${stderr}" | |
49 | ok $? "help ctf plugin produces no error" | |
50 | ||
51 | # Test with a working component class name. | |
52 | bt_cli "${stdout}" "${stderr}" help src.ctf.fs | |
53 | ok $? "help src.ctf.fs component class exit status" | |
54 | ||
55 | grep --silent 'Description: Read CTF traces from the file system.' "${stdout}" | |
56 | ok $? "help src.ctf.fs component class expected output" | |
57 | ||
58 | is_empty "${stderr}" | |
59 | ok $? "help src.ctf.fs component class produces no error" | |
60 | ||
61 | # Test without parameter. | |
62 | bt_cli "${stdout}" "${stderr}" help | |
63 | isnt $? 0 "help without parameter exit status" | |
64 | ||
65 | grep --silent "Missing plugin name or component class descriptor." "${stderr}" | |
66 | ok $? "help without parameter produces expected error" | |
67 | ||
68 | is_empty "${stdout}" | |
69 | ok $? "help without parameter produces no output" | |
70 | ||
71 | # Test with too many parameters. | |
72 | bt_cli "${stdout}" "${stderr}" help ctf fs | |
73 | isnt $? 0 "help with too many parameters exit status" | |
74 | ||
75 | grep --silent "Extraneous command-line argument specified to \`help\` command:" "${stderr}" | |
76 | ok $? "help with too many parameters produces expected error" | |
77 | ||
78 | is_empty "${stdout}" | |
79 | ok $? "help with too many parameters produces no output" | |
80 | ||
81 | # Test with unknown plugin name. | |
82 | bt_cli "${stdout}" "${stderr}" help zigotos | |
83 | isnt $? 0 "help with unknown plugin name" | |
84 | ||
85 | grep --silent 'Cannot find plugin: plugin-name="zigotos"' "${stderr}" | |
86 | ok $? "help with unknown plugin name produces expected error" | |
87 | ||
88 | is_empty "${stdout}" | |
89 | ok $? "help with unknown plugin name produces no output" | |
90 | ||
91 | # Test with unknown component class name (but known plugin). | |
92 | bt_cli "${stdout}" "${stderr}" help src.ctf.bob | |
93 | isnt $? 0 "help with unknown component class name" | |
94 | ||
9c3869a9 | 95 | grep --silent 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=1' "${stderr}" |
4bf5c85f SM |
96 | ok $? "help with unknown component class name produces expected error" |
97 | ||
98 | grep --silent 'Description: CTF input and output' "${stdout}" | |
99 | ok $? "help with unknown component class name prints plugin help" | |
100 | ||
101 | # Test with unknown component class plugin | |
102 | bt_cli "${stdout}" "${stderr}" help src.bob.fs | |
103 | isnt $? 0 "help with unknown component class plugin" | |
104 | ||
105 | grep --silent 'Cannot find plugin: plugin-name="bob"' "${stderr}" | |
106 | ok $? "help with unknown component class plugin produces expected error" | |
107 | ||
108 | is_empty "${stdout}" | |
109 | ok $? "help with unknown component class plugin produces no output" | |
365a0459 SM |
110 | |
111 | rm -f "${stdout}" "${stderr}" |