Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save XIIIVI/1806d2d20a388704c124713f1e6af9c1 to your computer and use it in GitHub Desktop.
Save XIIIVI/1806d2d20a388704c124713f1e6af9c1 to your computer and use it in GitHub Desktop.
#
# check_if_file_contains_string
# - param1: file containing the text
# - param2: string to find
# - param3: message for success
# - param4: message for failure
#
check_if_file_contains_string() {
local TARGET_FILE="${1}"
local STRING_TO_FIND="${2}"
local MESSAGE_FOR_SUCCESS="${3}"
local MESSAGE_FOR_FAILURE="${4}"
TEST_COUNT=$((TEST_COUNT + 1))
if grep -q "${STRING_TO_FIND}" "${TARGET_FILE}";
then
test_succeeded "${MESSAGE_FOR_SUCCESS}"
else
test_failed "${MESSAGE_FOR_FAILURE}"
display_file_content "${TARGET_FILE}"
fi
}
#
# check_if_file_does_not_contain_string
# - param1: file containing the text
# - param2: string to find
# - param3: message for success
# - param4: message for failure
#
check_if_file_does_not_contain_string() {
local TARGET_FILE="${1}"
local STRING_TO_FIND="${2}"
local MESSAGE_FOR_SUCCESS="${3}"
local MESSAGE_FOR_FAILURE="${4}"
TEST_COUNT=$((TEST_COUNT + 1))
if grep -q "${STRING_TO_FIND}" "${TARGET_FILE}";
then
test_failed "${MESSAGE_FOR_FAILURE}"
display_file_content "${TARGET_FILE}"
else
test_succeeded "${MESSAGE_FOR_SUCCESS}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment