| 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 |
| 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) |
| 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 | |
| 54 | test_error_graph() { |
| 55 | local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"ERROR\"") |
| 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) |
| 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 | |
| 76 | test_stop_graph() { |
| 77 | local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"STOP\"") |
| 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) |
| 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 | |
| 98 | plan_tests 9 |
| 99 | |
| 100 | test_interrupted_graph |
| 101 | test_error_graph |
| 102 | test_stop_graph |