Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tests: allow grep_fail to accept options #6463

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading