3 # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
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.
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
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.
18 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
19 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
21 UTILSSH
="$(dirname "$0")/../../utils/utils.sh"
24 # shellcheck source=../../utils/utils.sh
25 SH_TAP
=1 source "$UTILSSH"
31 data_dir
="${BT_TESTS_DATADIR}/cli/query"
32 plugin_dir
="${data_dir}"
34 stdout_expected_file
=$
(mktemp
-t test_cli_query_stdout_xpected.XXXXXX
)
35 stdout_file
=$
(mktemp
-t test_cli_query_stdout.XXXXXX
)
36 stderr_file
=$
(mktemp
-t test_cli_query_stderr.XXXXXX
)
39 local expected_str
="$1"
43 echo "$expected_str" > "$stdout_expected_file"
45 bt_diff_cli
"$stdout_expected_file" /dev
/null \
46 --plugin-path "$plugin_dir" \
47 query
"src.query.SourceWithQueryThatPrintsParams" \
53 local expected_str
="$1"
56 local test_name
="${args[*]}"
58 echo -n > "$stdout_expected_file"
60 bt_cli
"$stdout_file" "$stderr_file" \
61 --plugin-path "$plugin_dir" \
64 isnt
"$?" 0 "${test_name}: exit code is not 0"
66 bt_diff
/dev
/null
"$stdout_file"
67 ok
"$?" "${test_name}: nothing output on stout"
69 # Ensure that a CLI error stack is printed (and that babeltrace doesn't
71 grep --silent "^ERROR: " "${stderr_file}"
72 ok $?
"${test_name}: babeltrace produces an error stack"
74 grep --silent "${expected_str}" "${stderr_file}"
75 ok
"$?" "${test_name}: expect \`${expected_str}\` error message on stderr"
78 expect_success
'the-object:{}' \
80 expect_success
"the-object:{a=2}" \
83 # Check that -p parameters are processed in order.
84 expect_success
"the-object:{a=3, ben=kin, voyons=donc}" \
85 'the-object' -p 'a=2,ben=kin' -p 'voyons=donc,a=3'
87 # Failure inside the component class' query method.
88 expect_failure
"ValueError: catastrophic failure" \
89 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2'
91 # Non-existent component class.
92 expect_failure
'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=1' \
93 'src.query.NonExistentSource' 'the-object' '-p' 'a=2'
96 rm -f "$stdout_expected_file"