Skip to content

Commit

Permalink
Functional tests: allow grep_fail to accept options (#6463)
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie authored Nov 8, 2024
1 parent f6e36fb commit 755675c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions tests/functional/cli/05-colour.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@
if [[ "$OSTYPE" != "linux-gnu"* ]]; then
skip_all "Tests not compatibile with $OSTYPE"
fi
set_test_number 8
set_test_number 7

ANSI='\e\['

# No redirection.
script -q -c "cylc scan -t rich" log > /dev/null 2>&1
grep_ok "$ANSI" log -P # color

script -q -c "cylc scan -t rich --color=never" log > /dev/null 2>&1
grep_fail "$ANSI" log -P # no color
# FIXME: this test doesn't work because the output includes a color reset char
# at the end for some reason: https://github.com/cylc/cylc-flow/issues/6467
# script -q -c "cylc scan -t rich --color=never" log > /dev/null 2>&1
# grep_fail "$ANSI" log -P # no color

# Redirected.
cylc scan -t rich > log
Expand Down
11 changes: 7 additions & 4 deletions tests/functional/lib/bash/test_header
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
# named_grep_ok NAME PATTERN FILE [$OPTS]
# Run grep_ok with a custom test name.
# OPTS: put grep options like '-E' (extended regex) at end of line.
# grep_fail PATTERN FILE
# Run "grep -q -e PATTERN FILE", expect no match.
# grep_fail PATTERN FILE [$OPTS]
# Run "grep [$OPTS] -q -e PATTERN FILE", expect no match.
# count_ok PATTERN FILE COUNT
# Test that PATTERN occurs in exactly COUNT lines of FILE.
# exists_ok FILE
Expand Down Expand Up @@ -459,7 +459,7 @@ named_grep_ok() {
local BRE="$2"
local FILE="$3"
shift 3
OPTS="$*"
local OPTS="$*"
local TEST_NAME
TEST_NAME="grep-ok: ${NAME}"
# shellcheck disable=SC2086
Expand All @@ -485,13 +485,16 @@ __ERR__
grep_fail() {
local BRE="$1"
local FILE="$2"
shift 2
local OPTS="$*"
local TEST_NAME
TEST_NAME="$(basename "${FILE}")-grep-fail"
if [[ ! -f "${FILE}" ]]; then
fail "${TEST_NAME}-file to be grepped does not exist."
return
fi
if grep -q -e "${BRE}" "${FILE}"; then
# shellcheck disable=SC2086
if grep ${OPTS} -q -e "${BRE}" "${FILE}"; then
mkdir -p "${TEST_LOG_DIR}"
echo "ERROR: Found ${BRE} in ${FILE}" \
>"${TEST_LOG_DIR}/${TEST_NAME}.stderr"
Expand Down

0 comments on commit 755675c

Please sign in to comment.