tests: declare and assign variables separately in test_exit_status
[babeltrace.git] / tests / cli / test_exit_status
CommitLineData
851802b1
FD
1#!/bin/bash
2#
3# Copyright (C) 2019 EfficiOS Inc.
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
18SH_TAP=1
19
20if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
21 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
22else
23 UTILSSH="$(dirname "$0")/../utils/utils.sh"
24fi
25
26# shellcheck source=../utils/utils.sh
27source "$UTILSSH"
28
29data_dir="$BT_TESTS_DATADIR/cli/exit_status"
30source_name="src.test_exit_status.StatusSrc"
31
32test_interrupted_graph() {
33 local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"INTERRUPTED\"")
0374584e
SM
34 local actual_stdout
35 local actual_stderr
36
37 actual_stdout=$(mktemp -t test_cli_exit_status_stdout_actual.XXXXXX)
38 actual_stderr=$(mktemp -t test_cli_exit_status_stderr_actual.XXXXXX)
851802b1
FD
39
40 bt_cli "$actual_stdout" "$actual_stderr" "${cli_args[@]}"
41
42 is $? 2 "Interrupted graph exits with status 2"
43
44 bt_diff /dev/null "$actual_stdout"
45 ok $? "Interrupted graph gives no stdout"
46
47 bt_diff /dev/null "$actual_stderr"
48 ok $? "Interrupted graph gives no stderr"
49
50 rm -f "${actual_stdout}"
51 rm -f "${actual_stderr}"
52}
53
54test_error_graph() {
55 local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"ERROR\"")
0374584e
SM
56 local actual_stdout
57 local actual_stderr
58
59 actual_stdout=$(mktemp -t test_cli_exit_status_stdout_actual.XXXXXX)
60 actual_stderr=$(mktemp -t test_cli_exit_status_stderr_actual.XXXXXX)
851802b1
FD
61
62 bt_cli "$actual_stdout" "$actual_stderr" "${cli_args[@]}"
63
64 is $? 1 "Erroring graph exits with status 1"
65
66 bt_diff /dev/null "$actual_stdout"
67 ok $? "Erroring graph gives expected stdout"
68
69 like "$(cat "${actual_stderr}")" "TypeError: Raising type error" \
70 "Erroring graph gives expected error message"
71
72 rm -f "${actual_stdout}"
73 rm -f "${actual_stderr}"
74}
75
76test_stop_graph() {
77 local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"STOP\"")
0374584e
SM
78 local actual_stdout
79 local actual_stderr
80
81 actual_stdout=$(mktemp -t test_cli_exit_status_stdout_actual.XXXXXX)
82 actual_stderr=$(mktemp -t test_cli_exit_status_stderr_actual.XXXXXX)
851802b1
FD
83
84 bt_cli "$actual_stdout" "$actual_stderr" "${cli_args[@]}"
85
86 is $? 0 "Successful graph exits with status 0"
87
88 bt_diff /dev/null "$actual_stdout"
89 ok $? "Successful graph gives no stdout"
90
91 bt_diff /dev/null "$actual_stderr"
92 ok $? "Successful graph gives no stderr"
93
94 rm -f "${actual_stdout}"
95 rm -f "${actual_stderr}"
96}
97
98plan_tests 9
99
100test_interrupted_graph
101test_error_graph
102test_stop_graph
This page took 0.028378 seconds and 4 git commands to generate.