Fix: src.ctf.fs: initialize the other_entry variable
[babeltrace.git] / tests / cli / query / test_query
CommitLineData
0076e742
SM
1#!/bin/bash
2#
3# Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
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
18if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
19 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
20else
21 UTILSSH="$(dirname "$0")/../../utils/utils.sh"
22fi
23
24# shellcheck source=../../utils/utils.sh
25SH_TAP=1 source "$UTILSSH"
26
927c0693 27NUM_TESTS=15
0076e742
SM
28
29plan_tests $NUM_TESTS
30
31data_dir="${BT_TESTS_DATADIR}/cli/query"
32plugin_dir="${data_dir}"
33
34stdout_expected_file=$(mktemp -t test_cli_query_stdout_xpected.XXXXXX)
35stdout_file=$(mktemp -t test_cli_query_stdout.XXXXXX)
36stderr_file=$(mktemp -t test_cli_query_stderr.XXXXXX)
37
38expect_success() {
39 local expected_str="$1"
40 shift 1
41 local args=("$@")
42
43 echo "$expected_str" > "$stdout_expected_file"
44
45 bt_diff_cli "$stdout_expected_file" /dev/null \
46 --plugin-path "$plugin_dir" \
47 query "src.query.SourceWithQueryThatPrintsParams" \
48 "${args[@]}"
49 ok "$?" "${args[*]}"
50}
51
52expect_failure() {
53 local expected_str="$1"
54 shift 1
55 local args=("$@")
56 local test_name="${args[*]}"
57
58 echo -n > "$stdout_expected_file"
59
60 bt_cli "$stdout_file" "$stderr_file" \
61 --plugin-path "$plugin_dir" \
62 query \
63 "${args[@]}"
64 isnt "$?" 0 "${test_name}: exit code is not 0"
65
66 bt_diff /dev/null "$stdout_file"
67 ok "$?" "${test_name}: nothing output on stout"
68
69 # Ensure that a CLI error stack is printed (and that babeltrace doesn't
70 # abort before that).
71 grep --silent "^ERROR: " "${stderr_file}"
72 ok $? "${test_name}: babeltrace produces an error stack"
73
74 grep --silent "${expected_str}" "${stderr_file}"
75 ok "$?" "${test_name}: expect \`${expected_str}\` error message on stderr"
76}
77
78expect_success 'the-object:{}' \
79 'the-object'
80expect_success "the-object:{a=2}" \
81 'the-object' -p 'a=2'
82
83# Check that -p parameters are processed in order.
84expect_success "the-object:{a=3, ben=kin, voyons=donc}" \
85 'the-object' -p 'a=2,ben=kin' -p 'voyons=donc,a=3'
86
87# Failure inside the component class' query method.
88expect_failure "ValueError: catastrophic failure" \
89 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2'
90
91# Non-existent component class.
92expect_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'
94
927c0693
SM
95# Wrong parameter syntax.
96expect_failure "Invalid format for --params option's argument:" \
97 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=3,'
0076e742
SM
98
99rm -f "$stdout_expected_file"
100rm -f "$stdout_file"
101rm -f "$stderr_file"
This page took 0.031185 seconds and 4 git commands to generate.