| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2019 EfficiOS Inc. |
| 6 | # |
| 7 | |
| 8 | SH_TAP=1 |
| 9 | |
| 10 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
| 11 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
| 12 | else |
| 13 | UTILSSH="$(dirname "$0")/../utils/utils.sh" |
| 14 | fi |
| 15 | |
| 16 | # shellcheck source=../utils/utils.sh |
| 17 | source "$UTILSSH" |
| 18 | |
| 19 | plan_tests 21 |
| 20 | |
| 21 | stdout=$(mktemp -t test-help-stdout.XXXXXX) |
| 22 | stderr=$(mktemp -t test-help-stderr.XXXXXX) |
| 23 | |
| 24 | # Return 0 if file "$1" exists and is empty, non-0 otherwise. |
| 25 | |
| 26 | is_empty() |
| 27 | { |
| 28 | [[ -f "$1" && ! -s "$1" ]] |
| 29 | } |
| 30 | |
| 31 | # Test with a working plugin name. |
| 32 | bt_cli "${stdout}" "${stderr}" help ctf |
| 33 | ok $? "help ctf plugin exit status" |
| 34 | |
| 35 | bt_grep_ok \ |
| 36 | 'Description: CTF input and output' \ |
| 37 | "${stdout}" \ |
| 38 | "help ctf plugin expected output" |
| 39 | |
| 40 | is_empty "${stderr}" |
| 41 | ok $? "help ctf plugin produces no error" |
| 42 | |
| 43 | # Test with a working component class name. |
| 44 | bt_cli "${stdout}" "${stderr}" help src.ctf.fs |
| 45 | ok $? "help src.ctf.fs component class exit status" |
| 46 | |
| 47 | bt_grep_ok \ |
| 48 | 'Description: Read CTF traces from the file system.' \ |
| 49 | "${stdout}" \ |
| 50 | "help src.ctf.fs component class expected output" |
| 51 | |
| 52 | is_empty "${stderr}" |
| 53 | ok $? "help src.ctf.fs component class produces no error" |
| 54 | |
| 55 | # Test without parameter. |
| 56 | bt_cli "${stdout}" "${stderr}" help |
| 57 | isnt $? 0 "help without parameter exit status" |
| 58 | |
| 59 | bt_grep_ok \ |
| 60 | "Missing plugin name or component class descriptor." \ |
| 61 | "${stderr}" \ |
| 62 | "help without parameter produces expected error" |
| 63 | |
| 64 | is_empty "${stdout}" |
| 65 | ok $? "help without parameter produces no output" |
| 66 | |
| 67 | # Test with too many parameters. |
| 68 | bt_cli "${stdout}" "${stderr}" help ctf fs |
| 69 | isnt $? 0 "help with too many parameters exit status" |
| 70 | |
| 71 | bt_grep_ok \ |
| 72 | "Extraneous command-line argument specified to \`help\` command:" \ |
| 73 | "${stderr}" \ |
| 74 | "help with too many parameters produces expected error" |
| 75 | |
| 76 | is_empty "${stdout}" |
| 77 | ok $? "help with too many parameters produces no output" |
| 78 | |
| 79 | # Test with unknown plugin name. |
| 80 | bt_cli "${stdout}" "${stderr}" help zigotos |
| 81 | isnt $? 0 "help with unknown plugin name" |
| 82 | |
| 83 | bt_grep_ok \ |
| 84 | 'Cannot find plugin: plugin-name="zigotos"' \ |
| 85 | "${stderr}" \ |
| 86 | "help with unknown plugin name produces expected error" |
| 87 | |
| 88 | is_empty "${stdout}" |
| 89 | ok $? "help with unknown plugin name produces no output" |
| 90 | |
| 91 | # Test with unknown component class name (but known plugin). |
| 92 | bt_cli "${stdout}" "${stderr}" help src.ctf.bob |
| 93 | isnt $? 0 "help with unknown component class name" |
| 94 | |
| 95 | bt_grep_ok \ |
| 96 | 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=SOURCE' \ |
| 97 | "${stderr}" \ |
| 98 | "help with unknown component class name produces expected error" |
| 99 | |
| 100 | bt_grep_ok \ |
| 101 | 'Description: CTF input and output' \ |
| 102 | "${stdout}" \ |
| 103 | "help with unknown component class name prints plugin help" |
| 104 | |
| 105 | # Test with unknown component class plugin |
| 106 | bt_cli "${stdout}" "${stderr}" help src.bob.fs |
| 107 | isnt $? 0 "help with unknown component class plugin" |
| 108 | |
| 109 | bt_grep_ok \ |
| 110 | 'Cannot find plugin: plugin-name="bob"' \ |
| 111 | "${stderr}" \ |
| 112 | "help with unknown component class plugin produces expected error" |
| 113 | |
| 114 | is_empty "${stdout}" |
| 115 | ok $? "help with unknown component class plugin produces no output" |
| 116 | |
| 117 | rm -f "${stdout}" "${stderr}" |