Commit | Line | Data |
---|---|---|
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 | ||
18 | if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then | |
19 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" | |
20 | else | |
21 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" | |
22 | fi | |
23 | ||
24 | # shellcheck source=../../utils/utils.sh | |
25 | SH_TAP=1 source "$UTILSSH" | |
26 | ||
927c0693 | 27 | NUM_TESTS=15 |
0076e742 SM |
28 | |
29 | plan_tests $NUM_TESTS | |
30 | ||
31 | data_dir="${BT_TESTS_DATADIR}/cli/query" | |
32 | plugin_dir="${data_dir}" | |
33 | ||
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) | |
37 | ||
38 | expect_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 | ||
52 | expect_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 | ||
78 | expect_success 'the-object:{}' \ | |
79 | 'the-object' | |
80 | expect_success "the-object:{a=2}" \ | |
81 | 'the-object' -p 'a=2' | |
82 | ||
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' | |
86 | ||
87 | # Failure inside the component class' query method. | |
88 | expect_failure "ValueError: catastrophic failure" \ | |
89 | 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2' | |
90 | ||
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' | |
94 | ||
927c0693 SM |
95 | # Wrong parameter syntax. |
96 | expect_failure "Invalid format for --params option's argument:" \ | |
97 | 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=3,' | |
0076e742 SM |
98 | |
99 | rm -f "$stdout_expected_file" | |
100 | rm -f "$stdout_file" | |
101 | rm -f "$stderr_file" |