Commit | Line | Data |
---|---|---|
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 | ||
18 | SH_TAP=1 | |
19 | ||
20 | if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then | |
21 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" | |
22 | else | |
23 | UTILSSH="$(dirname "$0")/../utils/utils.sh" | |
24 | fi | |
25 | ||
26 | # shellcheck source=../utils/utils.sh | |
27 | source "$UTILSSH" | |
28 | ||
29 | data_dir="$BT_TESTS_DATADIR/cli/exit_status" | |
30 | source_name="src.test_exit_status.StatusSrc" | |
31 | ||
32 | test_interrupted_graph() { | |
33 | local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"INTERRUPTED\"") | |
34 | local actual_stdout=$(mktemp -t test_cli_exit_status_stdout_actual.XXXXXX) | |
35 | local actual_stderr=$(mktemp -t test_cli_exit_status_stderr_actual.XXXXXX) | |
36 | ||
37 | bt_cli "$actual_stdout" "$actual_stderr" "${cli_args[@]}" | |
38 | ||
39 | is $? 2 "Interrupted graph exits with status 2" | |
40 | ||
41 | bt_diff /dev/null "$actual_stdout" | |
42 | ok $? "Interrupted graph gives no stdout" | |
43 | ||
44 | bt_diff /dev/null "$actual_stderr" | |
45 | ok $? "Interrupted graph gives no stderr" | |
46 | ||
47 | rm -f "${actual_stdout}" | |
48 | rm -f "${actual_stderr}" | |
49 | } | |
50 | ||
51 | test_error_graph() { | |
52 | local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"ERROR\"") | |
53 | local actual_stdout=$(mktemp -t test_cli_exit_status_stdout_actual.XXXXXX) | |
54 | local actual_stderr=$(mktemp -t test_cli_exit_status_stderr_actual.XXXXXX) | |
55 | ||
56 | bt_cli "$actual_stdout" "$actual_stderr" "${cli_args[@]}" | |
57 | ||
58 | is $? 1 "Erroring graph exits with status 1" | |
59 | ||
60 | bt_diff /dev/null "$actual_stdout" | |
61 | ok $? "Erroring graph gives expected stdout" | |
62 | ||
63 | like "$(cat "${actual_stderr}")" "TypeError: Raising type error" \ | |
64 | "Erroring graph gives expected error message" | |
65 | ||
66 | rm -f "${actual_stdout}" | |
67 | rm -f "${actual_stderr}" | |
68 | } | |
69 | ||
70 | test_stop_graph() { | |
71 | local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"STOP\"") | |
72 | local actual_stdout=$(mktemp -t test_cli_exit_status_stdout_actual.XXXXXX) | |
73 | local actual_stderr=$(mktemp -t test_cli_exit_status_stderr_actual.XXXXXX) | |
74 | ||
75 | bt_cli "$actual_stdout" "$actual_stderr" "${cli_args[@]}" | |
76 | ||
77 | is $? 0 "Successful graph exits with status 0" | |
78 | ||
79 | bt_diff /dev/null "$actual_stdout" | |
80 | ok $? "Successful graph gives no stdout" | |
81 | ||
82 | bt_diff /dev/null "$actual_stderr" | |
83 | ok $? "Successful graph gives no stderr" | |
84 | ||
85 | rm -f "${actual_stdout}" | |
86 | rm -f "${actual_stderr}" | |
87 | } | |
88 | ||
89 | plan_tests 9 | |
90 | ||
91 | test_interrupted_graph | |
92 | test_error_graph | |
93 | test_stop_graph |