| 1 |
#!/usr/bin/env bash |
| 2 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 3 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
. "$(dirname "$0")/test_header" |
| 19 |
set_test_number 6 |
| 20 |
|
| 21 |
# NOTE: The completion server is heavily unit-tested |
| 22 |
# Run a couple of quick functional tests to make sure the CLI interface / reading |
| 23 |
# from stdin is working correctly. |
| 24 |
|
| 25 |
# $ cylc t<tab><tab> |
| 26 |
# tui |
| 27 |
# trigger |
| 28 |
TEST_NAME="${TEST_NAME_BASE}-t" |
| 29 |
run_ok "${TEST_NAME}" cylc completion-server --once <<< 'cylc|t' |
| 30 |
grep_ok trigger "${TEST_NAME}.stdout" |
| 31 |
grep_ok tui "${TEST_NAME}.stdout" |
| 32 |
|
| 33 |
# $ cylc trigg<tab><tab> |
| 34 |
# trigger |
| 35 |
TEST_NAME="${TEST_NAME_BASE}-trigg" |
| 36 |
run_ok "${TEST_NAME}" cylc completion-server --once <<< 'cylc|trigg' |
| 37 |
cmp_ok "${TEST_NAME}.stdout" << __HERE__ |
| 38 |
trigger |
| 39 |
__HERE__ |
| 40 |
|
| 41 |
# Make sure the server exits timeout when trying to read from stdin |
| 42 |
# (Note the completion server exits 0 on timeout) |
| 43 |
TEST_NAME="${TEST_NAME_BASE}-timeout" |
| 44 |
# shellcheck disable=SC2162 |
| 45 |
if ! read -t 0 -N 0; then |
| 46 |
# If stdin is not a terminal or contains readable data this test will |
| 47 |
# fail. |
| 48 |
run_ok "${TEST_NAME}" timeout 5 cylc completion-server --timeout=1 |
| 49 |
else |
| 50 |
# This should happen in non-interactive environments e.g. CI |
| 51 |
skip 1 'Test requires an stdin stream (cannot be faked)' |
| 52 |
fi |
| 53 |
|
| 54 |
exit |