3 # SPDX-License-Identifier: GPL-2.0-only
5 # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
8 if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
9 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
11 UTILSSH
="$(dirname "$0")/../../utils/utils.sh"
14 # shellcheck source=../../utils/utils.sh
15 SH_TAP
=1 source "$UTILSSH"
21 data_dir
="${BT_TESTS_DATADIR}/cli/query"
22 plugin_dir
="${data_dir}"
24 stdout_expected_file
=$
(mktemp
-t test-cli-query-stdout-expected.XXXXXX
)
25 stdout_file
=$
(mktemp
-t test-cli-query-stdout.XXXXXX
)
26 stderr_file
=$
(mktemp
-t test-cli-query-stderr.XXXXXX
)
29 local expected_str
="$1"
33 echo "$expected_str" > "$stdout_expected_file"
35 bt_diff_cli
"$stdout_expected_file" /dev
/null \
36 --plugin-path "$plugin_dir" \
37 query
"src.query.SourceWithQueryThatPrintsParams" \
43 local expected_str
="$1"
46 local test_name
="${args[*]}"
48 echo -n > "$stdout_expected_file"
50 bt_cli
"$stdout_file" "$stderr_file" \
51 --plugin-path "$plugin_dir" \
54 isnt
"$?" 0 "${test_name}: exit code is not 0"
56 bt_diff
/dev
/null
"$stdout_file"
57 ok
"$?" "${test_name}: nothing output on stout"
59 # Ensure that a CLI error stack is printed (and that babeltrace doesn't
64 "${test_name}: babeltrace produces an error stack"
69 "${test_name}: expect \`${expected_str}\` error message on stderr"
72 expect_success
'the-object:{}' \
74 expect_success
"the-object:{a=2}" \
77 # Check that -p parameters are processed in order.
78 expect_success
"the-object:{a=3, ben=kin, voyons=donc}" \
79 'the-object' -p 'a=2,ben=kin' -p 'voyons=donc,a=3'
81 # Failure inside the component class' query method.
82 expect_failure
"ValueError: catastrophic failure" \
83 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2'
85 # Non-existent component class.
86 expect_failure
'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=SOURCE' \
87 'src.query.NonExistentSource' 'the-object' '-p' 'a=2'
89 # Wrong parameter syntax.
90 expect_failure
"Invalid format for --params option's argument:" \
91 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=3,'
93 rm -f "$stdout_expected_file"