| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2019 EfficiOS Inc. |
| 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 | plan_tests 3 |
| 18 | |
| 19 | data_dir="${BT_TESTS_DATADIR}/cli/list-plugins" |
| 20 | plugin_dir="${data_dir}" |
| 21 | |
| 22 | stdout_file=$(mktemp -t test_cli_list_plugins_stdout.XXXXXX) |
| 23 | stderr_file=$(mktemp -t test_cli_list_plugins_stderr.XXXXXX) |
| 24 | grep_stdout_file=$(mktemp -t test_cli_list_plugins_grep_stdout.XXXXXX) |
| 25 | py_plugin_expected_stdout_file=$(mktemp -t test_cli_list_plugins_expected_py_plugin_stdout.XXXXXX) |
| 26 | |
| 27 | # Run list-plugins. |
| 28 | bt_cli "$stdout_file" "$stderr_file" \ |
| 29 | --plugin-path "$plugin_dir" \ |
| 30 | list-plugins |
| 31 | ok "$?" "exit code is 0" |
| 32 | |
| 33 | # Extract the section about our custom this-is-a-plugin Python plugin. |
| 34 | grep --after-context=11 '^this-is-a-plugin:$' "${stdout_file}" > "${grep_stdout_file}" |
| 35 | ok "$?" "entry for this-is-a-plugin is present" |
| 36 | |
| 37 | if [ "$BT_OS_TYPE" = "mingw" ]; then |
| 38 | platform_plugin_dir=$(cygpath -m "${plugin_dir}") |
| 39 | else |
| 40 | platform_plugin_dir="${plugin_dir}" |
| 41 | fi |
| 42 | |
| 43 | # Generate the expected output file for that plugin. |
| 44 | cat <<- EOF > "${py_plugin_expected_stdout_file}" |
| 45 | this-is-a-plugin: |
| 46 | Path: ${platform_plugin_dir}/bt_plugin_list_plugins.py |
| 47 | Version: 1.2.3bob |
| 48 | Description: A plugin |
| 49 | Author: Jorge Mario Bergoglio |
| 50 | License: The license |
| 51 | Source component classes: |
| 52 | 'source.this-is-a-plugin.ThisIsASource' |
| 53 | Filter component classes: |
| 54 | 'filter.this-is-a-plugin.ThisIsAFilter' |
| 55 | Sink component classes: |
| 56 | 'sink.this-is-a-plugin.ThisIsASink' |
| 57 | EOF |
| 58 | |
| 59 | # Compare the entry for this-is-a-plugin with the expected version. |
| 60 | bt_diff "${py_plugin_expected_stdout_file}" "${grep_stdout_file}" |
| 61 | ok "$?" "entry for this-is-a-plugin is as expected" |
| 62 | |
| 63 | rm -f "${stdout_file}" |
| 64 | rm -f "${stderr_file}" |
| 65 | rm -f "${grep_stdout_file}" |
| 66 | rm -f "${py_plugin_expected_stdout_file}" |