tests: add and use bt_grep
[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
407d3b10 35bt_grep --silent 'Description: CTF input and output' "${stdout}"
4bf5c85f
SM
36ok $? "help ctf plugin expected output"
37
38is_empty "${stderr}"
39ok $? "help ctf plugin produces no error"
40
41# Test with a working component class name.
42bt_cli "${stdout}" "${stderr}" help src.ctf.fs
43ok $? "help src.ctf.fs component class exit status"
44
407d3b10 45bt_grep --silent 'Description: Read CTF traces from the file system.' "${stdout}"
4bf5c85f
SM
46ok $? "help src.ctf.fs component class expected output"
47
48is_empty "${stderr}"
49ok $? "help src.ctf.fs component class produces no error"
50
51# Test without parameter.
52bt_cli "${stdout}" "${stderr}" help
53isnt $? 0 "help without parameter exit status"
54
407d3b10 55bt_grep --silent "Missing plugin name or component class descriptor." "${stderr}"
4bf5c85f
SM
56ok $? "help without parameter produces expected error"
57
58is_empty "${stdout}"
59ok $? "help without parameter produces no output"
60
61# Test with too many parameters.
62bt_cli "${stdout}" "${stderr}" help ctf fs
63isnt $? 0 "help with too many parameters exit status"
64
407d3b10 65bt_grep --silent "Extraneous command-line argument specified to \`help\` command:" "${stderr}"
4bf5c85f
SM
66ok $? "help with too many parameters produces expected error"
67
68is_empty "${stdout}"
69ok $? "help with too many parameters produces no output"
70
71# Test with unknown plugin name.
72bt_cli "${stdout}" "${stderr}" help zigotos
73isnt $? 0 "help with unknown plugin name"
74
407d3b10 75bt_grep --silent 'Cannot find plugin: plugin-name="zigotos"' "${stderr}"
4bf5c85f
SM
76ok $? "help with unknown plugin name produces expected error"
77
78is_empty "${stdout}"
79ok $? "help with unknown plugin name produces no output"
80
81# Test with unknown component class name (but known plugin).
82bt_cli "${stdout}" "${stderr}" help src.ctf.bob
83isnt $? 0 "help with unknown component class name"
84
407d3b10 85bt_grep --silent 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=SOURCE' "${stderr}"
4bf5c85f
SM
86ok $? "help with unknown component class name produces expected error"
87
407d3b10 88bt_grep --silent 'Description: CTF input and output' "${stdout}"
4bf5c85f
SM
89ok $? "help with unknown component class name prints plugin help"
90
91# Test with unknown component class plugin
92bt_cli "${stdout}" "${stderr}" help src.bob.fs
93isnt $? 0 "help with unknown component class plugin"
94
407d3b10 95bt_grep --silent 'Cannot find plugin: plugin-name="bob"' "${stderr}"
4bf5c85f
SM
96ok $? "help with unknown component class plugin produces expected error"
97
98is_empty "${stdout}"
99ok $? "help with unknown component class plugin produces no output"
365a0459
SM
100
101rm -f "${stdout}" "${stderr}"
This page took 0.050944 seconds and 4 git commands to generate.