lib: remove some unnecessary uses of `GString`
[babeltrace.git] / tests / cli / test-help.sh
CommitLineData
4bf5c85f
SM
1#!/bin/bash
2#
0235b0db 3# SPDX-License-Identifier: GPL-2.0-only
4bf5c85f 4#
0235b0db 5# Copyright (C) 2019 EfficiOS Inc.
4bf5c85f 6#
4bf5c85f
SM
7
8SH_TAP=1
9
75e396f6 10if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
4bf5c85f
SM
11 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
12else
13 UTILSSH="$(dirname "$0")/../utils/utils.sh"
14fi
15
16# shellcheck source=../utils/utils.sh
17source "$UTILSSH"
18
19plan_tests 21
20
7132b838
PP
21stdout=$(mktemp -t test-help-stdout.XXXXXX)
22stderr=$(mktemp -t test-help-stderr.XXXXXX)
4bf5c85f
SM
23
24# Return 0 if file "$1" exists and is empty, non-0 otherwise.
25
26is_empty()
27{
28 [[ -f "$1" && ! -s "$1" ]]
29}
30
31# Test with a working plugin name.
32bt_cli "${stdout}" "${stderr}" help ctf
33ok $? "help ctf plugin exit status"
34
db01f759
SM
35bt_grep_ok \
36 'Description: CTF input and output' \
37 "${stdout}" \
38 "help ctf plugin expected output"
4bf5c85f
SM
39
40is_empty "${stderr}"
41ok $? "help ctf plugin produces no error"
42
43# Test with a working component class name.
44bt_cli "${stdout}" "${stderr}" help src.ctf.fs
45ok $? "help src.ctf.fs component class exit status"
46
db01f759
SM
47bt_grep_ok \
48 'Description: Read CTF traces from the file system.' \
49 "${stdout}" \
50 "help src.ctf.fs component class expected output"
4bf5c85f
SM
51
52is_empty "${stderr}"
53ok $? "help src.ctf.fs component class produces no error"
54
55# Test without parameter.
56bt_cli "${stdout}" "${stderr}" help
57isnt $? 0 "help without parameter exit status"
58
db01f759
SM
59bt_grep_ok \
60 "Missing plugin name or component class descriptor." \
61 "${stderr}" \
62 "help without parameter produces expected error"
4bf5c85f
SM
63
64is_empty "${stdout}"
65ok $? "help without parameter produces no output"
66
67# Test with too many parameters.
68bt_cli "${stdout}" "${stderr}" help ctf fs
69isnt $? 0 "help with too many parameters exit status"
70
db01f759
SM
71bt_grep_ok \
72 "Extraneous command-line argument specified to \`help\` command:" \
73 "${stderr}" \
74 "help with too many parameters produces expected error"
4bf5c85f
SM
75
76is_empty "${stdout}"
77ok $? "help with too many parameters produces no output"
78
79# Test with unknown plugin name.
80bt_cli "${stdout}" "${stderr}" help zigotos
81isnt $? 0 "help with unknown plugin name"
82
db01f759
SM
83bt_grep_ok \
84 'Cannot find plugin: plugin-name="zigotos"' \
85 "${stderr}" \
86 "help with unknown plugin name produces expected error"
4bf5c85f
SM
87
88is_empty "${stdout}"
89ok $? "help with unknown plugin name produces no output"
90
91# Test with unknown component class name (but known plugin).
92bt_cli "${stdout}" "${stderr}" help src.ctf.bob
93isnt $? 0 "help with unknown component class name"
94
db01f759
SM
95bt_grep_ok \
96 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=SOURCE' \
97 "${stderr}" \
98 "help with unknown component class name produces expected error"
4bf5c85f 99
db01f759
SM
100bt_grep_ok \
101 'Description: CTF input and output' \
102 "${stdout}" \
103 "help with unknown component class name prints plugin help"
4bf5c85f
SM
104
105# Test with unknown component class plugin
106bt_cli "${stdout}" "${stderr}" help src.bob.fs
107isnt $? 0 "help with unknown component class plugin"
108
db01f759
SM
109bt_grep_ok \
110 'Cannot find plugin: plugin-name="bob"' \
111 "${stderr}" \
112 "help with unknown component class plugin produces expected error"
4bf5c85f
SM
113
114is_empty "${stdout}"
115ok $? "help with unknown component class plugin produces no output"
365a0459
SM
116
117rm -f "${stdout}" "${stderr}"
This page took 0.060482 seconds and 4 git commands to generate.