Move to kernel style SPDX license identifiers
[babeltrace.git] / tests / cli / query / test_query
1 #!/bin/bash
2 #
3 # SPDX-License-Identifier: GPL-2.0-only
4 #
5 # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
6 #
7
8 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
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
17 NUM_TESTS=15
18
19 plan_tests $NUM_TESTS
20
21 data_dir="${BT_TESTS_DATADIR}/cli/query"
22 plugin_dir="${data_dir}"
23
24 stdout_expected_file=$(mktemp -t test_cli_query_stdout_xpected.XXXXXX)
25 stdout_file=$(mktemp -t test_cli_query_stdout.XXXXXX)
26 stderr_file=$(mktemp -t test_cli_query_stderr.XXXXXX)
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).
61 grep --silent "^ERROR: " "${stderr_file}"
62 ok $? "${test_name}: babeltrace produces an error stack"
63
64 grep --silent "${expected_str}" "${stderr_file}"
65 ok "$?" "${test_name}: expect \`${expected_str}\` error message on stderr"
66 }
67
68 expect_success 'the-object:{}' \
69 'the-object'
70 expect_success "the-object:{a=2}" \
71 'the-object' -p 'a=2'
72
73 # Check that -p parameters are processed in order.
74 expect_success "the-object:{a=3, ben=kin, voyons=donc}" \
75 'the-object' -p 'a=2,ben=kin' -p 'voyons=donc,a=3'
76
77 # Failure inside the component class' query method.
78 expect_failure "ValueError: catastrophic failure" \
79 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2'
80
81 # Non-existent component class.
82 expect_failure 'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=1' \
83 'src.query.NonExistentSource' 'the-object' '-p' 'a=2'
84
85 # Wrong parameter syntax.
86 expect_failure "Invalid format for --params option's argument:" \
87 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=3,'
88
89 rm -f "$stdout_expected_file"
90 rm -f "$stdout_file"
91 rm -f "$stderr_file"
This page took 0.04117 seconds and 4 git commands to generate.