Commit | Line | Data |
---|---|---|
0076e742 SM |
1 | #!/bin/bash |
2 | # | |
0235b0db | 3 | # SPDX-License-Identifier: GPL-2.0-only |
0076e742 | 4 | # |
0235b0db | 5 | # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com> |
0076e742 | 6 | # |
0076e742 | 7 | |
75e396f6 | 8 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
0076e742 SM |
9 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
10 | else | |
11 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" | |
12 | fi | |
13 | ||
14 | # shellcheck source=../../utils/utils.sh | |
15 | SH_TAP=1 source "$UTILSSH" | |
16 | ||
927c0693 | 17 | NUM_TESTS=15 |
0076e742 SM |
18 | |
19 | plan_tests $NUM_TESTS | |
20 | ||
21 | data_dir="${BT_TESTS_DATADIR}/cli/query" | |
22 | plugin_dir="${data_dir}" | |
23 | ||
7132b838 PP |
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) | |
0076e742 SM |
27 | |
28 | expect_success() { | |
29 | local expected_str="$1" | |
30 | shift 1 | |
31 | local args=("$@") | |
32 | ||
33 | echo "$expected_str" > "$stdout_expected_file" | |
34 | ||
35 | bt_diff_cli "$stdout_expected_file" /dev/null \ | |
36 | --plugin-path "$plugin_dir" \ | |
37 | query "src.query.SourceWithQueryThatPrintsParams" \ | |
38 | "${args[@]}" | |
39 | ok "$?" "${args[*]}" | |
40 | } | |
41 | ||
42 | expect_failure() { | |
43 | local expected_str="$1" | |
44 | shift 1 | |
45 | local args=("$@") | |
46 | local test_name="${args[*]}" | |
47 | ||
48 | echo -n > "$stdout_expected_file" | |
49 | ||
50 | bt_cli "$stdout_file" "$stderr_file" \ | |
51 | --plugin-path "$plugin_dir" \ | |
52 | query \ | |
53 | "${args[@]}" | |
54 | isnt "$?" 0 "${test_name}: exit code is not 0" | |
55 | ||
56 | bt_diff /dev/null "$stdout_file" | |
57 | ok "$?" "${test_name}: nothing output on stout" | |
58 | ||
59 | # Ensure that a CLI error stack is printed (and that babeltrace doesn't | |
60 | # abort before that). | |
db01f759 SM |
61 | bt_grep_ok \ |
62 | "^ERROR: " \ | |
63 | "${stderr_file}" \ | |
64 | "${test_name}: babeltrace produces an error stack" | |
65 | ||
66 | bt_grep_ok \ | |
67 | "${expected_str}" \ | |
68 | "${stderr_file}" \ | |
69 | "${test_name}: expect \`${expected_str}\` error message on stderr" | |
0076e742 SM |
70 | } |
71 | ||
72 | expect_success 'the-object:{}' \ | |
73 | 'the-object' | |
74 | expect_success "the-object:{a=2}" \ | |
75 | 'the-object' -p 'a=2' | |
76 | ||
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' | |
80 | ||
81 | # Failure inside the component class' query method. | |
82 | expect_failure "ValueError: catastrophic failure" \ | |
83 | 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2' | |
84 | ||
85 | # Non-existent component class. | |
6375b942 | 86 | expect_failure 'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=SOURCE' \ |
0076e742 SM |
87 | 'src.query.NonExistentSource' 'the-object' '-p' 'a=2' |
88 | ||
927c0693 SM |
89 | # Wrong parameter syntax. |
90 | expect_failure "Invalid format for --params option's argument:" \ | |
91 | 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=3,' | |
0076e742 SM |
92 | |
93 | rm -f "$stdout_expected_file" | |
94 | rm -f "$stdout_file" | |
95 | rm -f "$stderr_file" |