1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-11-24 05:37:38 +00:00

Use explicit escaping for "\\n" newlines.

Backslash is literal, so explicitly escape it rather than rely on
fallback behavior.

ShellCheck SC1117
https://github.com/koalaman/shellcheck/wiki/SC1117
This commit is contained in:
William Melody 2018-04-15 14:55:26 -07:00
parent b242081ef1
commit 80edd464b6
15 changed files with 265 additions and 265 deletions

120
hosts
View File

@ -63,7 +63,7 @@ export _TAB_SPACE_CC_="[${_TAB_SPACE_}]"
# _debug() # _debug()
# #
# Usage: # Usage:
# _debug printf "Debug info. Variable: %s\n" "$0" # _debug printf "Debug info. Variable: %s\\n" "$0"
# #
# A simple function for executing a specified command if the `$_USE_DEBUG` # A simple function for executing a specified command if the `$_USE_DEBUG`
# variable has been set. The command is expected to print a message and # variable has been set. The command is expected to print a message and
@ -74,7 +74,7 @@ _debug() {
# Prefix debug message with "bug (U+1F41B)" # Prefix debug message with "bug (U+1F41B)"
printf "🐛 " printf "🐛 "
"${@}" "${@}"
printf "――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n" printf "――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\\n"
fi fi
} }
# debug() # debug()
@ -96,7 +96,7 @@ debug() {
# _die() # _die()
# #
# Usage: # Usage:
# _die printf "Error message. Variable: %s\n" "$0" # _die printf "Error message. Variable: %s\\n" "$0"
# #
# A simple function for exiting with an error after executing the specified # A simple function for exiting with an error after executing the specified
# command. The command is expected to print a message and should typically # command. The command is expected to print a message and should typically
@ -264,16 +264,16 @@ _COMMAND_PARAMETERS=(${_COMMAND_ARGV[*]})
unset "_COMMAND_PARAMETERS[0]" unset "_COMMAND_PARAMETERS[0]"
_debug printf \ _debug printf \
"\${_CMD}: %s\n" \ "\${_CMD}: %s\\n" \
"${_CMD}" "${_CMD}"
_debug printf \ _debug printf \
"\${_RAW_OPTIONS} (one per line):\n%s\n" \ "\${_RAW_OPTIONS} (one per line):\\n%s\\n" \
"${_RAW_OPTIONS}" "${_RAW_OPTIONS}"
_debug printf \ _debug printf \
"\${_COMMAND_ARGV[*]}: %s\n" \ "\${_COMMAND_ARGV[*]}: %s\\n" \
"${_COMMAND_ARGV[*]}" "${_COMMAND_ARGV[*]}"
_debug printf \ _debug printf \
"\${_COMMAND_PARAMETERS[*]:-}: %s\n" \ "\${_COMMAND_PARAMETERS[*]:-}: %s\\n" \
"${_COMMAND_PARAMETERS[*]:-}" "${_COMMAND_PARAMETERS[*]:-}"
############################################################################### ###############################################################################
@ -285,7 +285,7 @@ _debug printf \
# Set to the program's basename. # Set to the program's basename.
_ME=$(basename "${0}") _ME=$(basename "${0}")
_debug printf "\${_ME}: %s\n" "${_ME}" _debug printf "\${_ME}: %s\\n" "${_ME}"
############################################################################### ###############################################################################
# Load Commands # Load Commands
@ -302,8 +302,8 @@ _DEFINED_COMMANDS=()
# Loads all of the commands sourced in the environment. # Loads all of the commands sourced in the environment.
_load_commands() { _load_commands() {
_debug printf "_load_commands(): entering...\n" _debug printf "_load_commands(): entering...\\n"
_debug printf "_load_commands() declare -F:\n%s\n" "$(declare -F)" _debug printf "_load_commands() declare -F:\\n%s\\n" "$(declare -F)"
# declare is a bash built-in shell function that, when called with the '-F' # declare is a bash built-in shell function that, when called with the '-F'
# option, displays all of the functions with the format # option, displays all of the functions with the format
@ -318,7 +318,7 @@ _load_commands() {
local function_name local function_name
function_name=$(printf "%s" "${c}" | awk '{ print $3 }') function_name=$(printf "%s" "${c}" | awk '{ print $3 }')
_debug printf "_load_commands() \${function_name}: %s\n" "${function_name}" _debug printf "_load_commands() \${function_name}: %s\\n" "${function_name}"
# Add the function name to the $_DEFINED_COMMANDS array unless it starts # Add the function name to the $_DEFINED_COMMANDS array unless it starts
# with an underscore or is one of the desc(), debug(), or die() functions, # with an underscore or is one of the desc(), debug(), or die() functions,
@ -334,7 +334,7 @@ _load_commands() {
done done
_debug printf \ _debug printf \
"commands() \${_DEFINED_COMMANDS[*]:-}:\n%s\n" \ "commands() \${_DEFINED_COMMANDS[*]:-}:\\n%s\\n" \
"${_DEFINED_COMMANDS[*]:-}" "${_DEFINED_COMMANDS[*]:-}"
} }
@ -351,8 +351,8 @@ _load_commands() {
# #
# NOTE: must be called at end of program after all commands have been defined. # NOTE: must be called at end of program after all commands have been defined.
_main() { _main() {
_debug printf "main(): entering...\n" _debug printf "main(): entering...\\n"
_debug printf "main() \${_CMD} (upon entering): %s\n" "${_CMD}" _debug printf "main() \${_CMD} (upon entering): %s\\n" "${_CMD}"
# If $_CMD is blank, then set to `$HOSTS_DEFAULT_COMMAND` # If $_CMD is blank, then set to `$HOSTS_DEFAULT_COMMAND`
if [[ -z ${_CMD} ]] if [[ -z ${_CMD} ]]
@ -416,10 +416,10 @@ _contains() {
local test_list=(${*:2}) local test_list=(${*:2})
for _test_element in "${test_list[@]:-}" for _test_element in "${test_list[@]:-}"
do do
_debug printf "_contains() \${_test_element}: %s\n" "${_test_element}" _debug printf "_contains() \${_test_element}: %s\\n" "${_test_element}"
if [[ "${_test_element}" == "${1}" ]] if [[ "${_test_element}" == "${1}" ]]
then then
_debug printf "_contains() match: %s\n" "${1}" _debug printf "_contains() match: %s\\n" "${1}"
return 0 return 0
fi fi
done done
@ -495,7 +495,7 @@ _verify_write_permissions() {
else else
_die printf \ _die printf \
"You don't have permission to perform this operation. Try again with: "You don't have permission to perform this operation. Try again with:
sudo !!\n" sudo !!\\n"
fi fi
fi fi
} }
@ -531,16 +531,16 @@ sudo !!\n"
# escaping backslashes, which is more common. # escaping backslashes, which is more common.
desc() { desc() {
set +e set +e
[[ -z ${1} ]] && _die printf "desc: No command name specified.\n" [[ -z ${1} ]] && _die printf "desc: No command name specified.\\n"
if [[ -n ${2:-} ]] if [[ -n ${2:-} ]]
then then
read -r -d '' "_desc_${1}" <<HEREDOC read -r -d '' "_desc_${1}" <<HEREDOC
${2} ${2}
HEREDOC HEREDOC
_debug printf "desc() set with argument: _desc_%s\n" "${1}" _debug printf "desc() set with argument: _desc_%s\\n" "${1}"
else else
read -r -d '' "_desc_${1}" read -r -d '' "_desc_${1}"
_debug printf "desc() set with pipe: _desc_%s\n" "${1}" _debug printf "desc() set with pipe: _desc_%s\\n" "${1}"
fi fi
set -e set -e
} }
@ -556,9 +556,9 @@ _print_desc() {
local var="_desc_${1}" local var="_desc_${1}"
if [[ -n ${!var:-} ]] if [[ -n ${!var:-} ]]
then then
printf "%s\n" "${!var}" printf "%s\\n" "${!var}"
else else
printf "No additional information for \`%s\`\n" "${1}" printf "No additional information for \`%s\`\\n" "${1}"
fi fi
} }
@ -578,7 +578,7 @@ Description:
To save you the trouble, the current version is ${_VERSION} To save you the trouble, the current version is ${_VERSION}
HEREDOC HEREDOC
version() { version() {
printf "%s\n" "${_VERSION}" printf "%s\\n" "${_VERSION}"
} }
# Help ######################################################################## # Help ########################################################################
@ -653,10 +653,10 @@ HEREDOC
commands() { commands() {
if _command_argv_includes "--raw" if _command_argv_includes "--raw"
then then
printf "%s\n" "${_DEFINED_COMMANDS[@]}" printf "%s\\n" "${_DEFINED_COMMANDS[@]}"
else else
printf "Available commands:\n" printf "Available commands:\\n"
printf " %s\n" "${_DEFINED_COMMANDS[@]}" printf " %s\\n" "${_DEFINED_COMMANDS[@]}"
fi fi
} }
@ -682,7 +682,7 @@ commands() {
# - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html # - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
# HEREDOC # HEREDOC
# example() { # example() {
# printf "Hello, World!\n" # printf "Hello, World!\\n"
# } # }
# #
############################################################################### ###############################################################################
@ -697,9 +697,9 @@ Description:
Add a given IP address and hostname pair, along with an optional comment. Add a given IP address and hostname pair, along with an optional comment.
HEREDOC HEREDOC
add() { add() {
_debug printf "add() \${1}: %s\n" "${1:-}" _debug printf "add() \${1}: %s\\n" "${1:-}"
_debug printf "add() \${2}: %s\n" "${2:-}" _debug printf "add() \${2}: %s\\n" "${2:-}"
_debug printf "add() \${3}: %s\n" "${3:-}" _debug printf "add() \${3}: %s\\n" "${3:-}"
_verify_write_permissions "$@" _verify_write_permissions "$@"
local ip=${1:-} local ip=${1:-}
@ -711,7 +711,7 @@ add() {
exit 1 exit 1
elif [[ -z ${hostname} ]] elif [[ -z ${hostname} ]]
then then
printf "Please include a hostname\n" printf "Please include a hostname\\n"
${_ME} help add ${_ME} help add
exit 1 exit 1
elif grep \ elif grep \
@ -719,26 +719,26 @@ add() {
-e "^${ip}\t${hostname}\t.*$" "${HOSTS_PATH}" -e "^${ip}\t${hostname}\t.*$" "${HOSTS_PATH}"
then then
_die printf \ _die printf \
"Duplicate address/host combination, %s unchanged.\n" \ "Duplicate address/host combination, %s unchanged.\\n" \
"${HOSTS_PATH}" "${HOSTS_PATH}"
else else
if [[ -n ${comment} ]] if [[ -n ${comment} ]]
then then
local formatted_comment local formatted_comment
formatted_comment=$(_join " " "${comment[@]}") formatted_comment=$(_join " " "${comment[@]}")
printf "%s\t%s\t# %s\n" \ printf "%s\t%s\t# %s\\n" \
"${ip}" \ "${ip}" \
"${hostname}" \ "${hostname}" \
"${formatted_comment}" >> "${HOSTS_PATH}" "${formatted_comment}" >> "${HOSTS_PATH}"
printf "Added:\n%s\t%s\t# %s\n" \ printf "Added:\\n%s\t%s\t# %s\\n" \
"${ip}" \ "${ip}" \
"${hostname}" \ "${hostname}" \
"${formatted_comment}" "${formatted_comment}"
else else
printf "%s\t%s\n" \ printf "%s\t%s\\n" \
"${ip}" \ "${ip}" \
"${hostname}" >> "${HOSTS_PATH}" "${hostname}" >> "${HOSTS_PATH}"
printf "Added:\n%s\t%s\n" \ printf "Added:\\n%s\t%s\\n" \
"${ip}" \ "${ip}" \
"${hostname}" "${hostname}"
fi fi
@ -787,7 +787,7 @@ disable() {
${_ME} help disable ${_ME} help disable
exit 1 exit 1
else else
_debug printf "disable() \${search_string}: %s\n" "${search_string}" _debug printf "disable() \${search_string}: %s\\n" "${search_string}"
target_regex_ip="^\(${search_string}[${_TAB_SPACE_}]..*\)$" target_regex_ip="^\(${search_string}[${_TAB_SPACE_}]..*\)$"
target_regex_commented_hostname="^\([^#]..*[${_TAB_SPACE_}]${search_string}[${_TAB_SPACE_}]..*\)$" target_regex_commented_hostname="^\([^#]..*[${_TAB_SPACE_}]${search_string}[${_TAB_SPACE_}]..*\)$"
@ -805,13 +805,13 @@ disable() {
-e "s/${target_regex_hostname}/\1/p" \ -e "s/${target_regex_hostname}/\1/p" \
"${HOSTS_PATH}" "${HOSTS_PATH}"
) )
_debug printf "disable() \${targets}: %s\n" "${targets}" _debug printf "disable() \${targets}: %s\\n" "${targets}"
if [[ -z "${targets}" ]] if [[ -z "${targets}" ]]
then then
_die printf "Not found: %s\n" "${search_string}" _die printf "Not found: %s\\n" "${search_string}"
fi fi
printf "Disabling:\n%s\n" "${targets}" printf "Disabling:\\n%s\\n" "${targets}"
# -i '' - in place edit. BSD sed requires extension argument, for GNU # -i '' - in place edit. BSD sed requires extension argument, for GNU
# it's optional. More info: http://stackoverflow.com/a/16746032 # it's optional. More info: http://stackoverflow.com/a/16746032
@ -849,7 +849,7 @@ edit() {
_verify_write_permissions "$@" _verify_write_permissions "$@"
if [[ -z "${EDITOR}" ]] if [[ -z "${EDITOR}" ]]
then then
_die printf "\$EDITOR not set.\n" _die printf "\$EDITOR not set.\\n"
else else
"${EDITOR}" "${HOSTS_PATH}" "${EDITOR}" "${HOSTS_PATH}"
fi fi
@ -873,7 +873,7 @@ enable() {
${_ME} help enable ${_ME} help enable
exit 1 exit 1
else else
_debug printf "enable() \${search_string}: %s\n" "${search_string}" _debug printf "enable() \${search_string}: %s\\n" "${search_string}"
target_regex_ip="^\#disabled: \(${search_string}[${_TAB_SPACE_}]..*\)$" target_regex_ip="^\#disabled: \(${search_string}[${_TAB_SPACE_}]..*\)$"
target_regex_commented_hostname="^\#disabled: \(..*[${_TAB_SPACE_}]${search_string}[${_TAB_SPACE_}]..*\)$" target_regex_commented_hostname="^\#disabled: \(..*[${_TAB_SPACE_}]${search_string}[${_TAB_SPACE_}]..*\)$"
@ -891,13 +891,13 @@ enable() {
-e "s/${target_regex_hostname}/\1/p" \ -e "s/${target_regex_hostname}/\1/p" \
"${HOSTS_PATH}" "${HOSTS_PATH}"
) )
_debug printf "enable() \${targets}: %s\n" "${targets}" _debug printf "enable() \${targets}: %s\\n" "${targets}"
if [[ -z "${targets}" ]] if [[ -z "${targets}" ]]
then then
_die printf "Not found: %s\n" "${search_string}" _die printf "Not found: %s\\n" "${search_string}"
fi fi
printf "Enabling:\n%s\n" "${targets}" printf "Enabling:\\n%s\\n" "${targets}"
# -i '' - in place edit. BSD sed requires extension argument, for GNU # -i '' - in place edit. BSD sed requires extension argument, for GNU
# it's optional. More info: http://stackoverflow.com/a/16746032 # it's optional. More info: http://stackoverflow.com/a/16746032
@ -957,7 +957,7 @@ list() {
then then
if [[ "${1}" == "disabled" ]] if [[ "${1}" == "disabled" ]]
then then
printf "%s\n" "${disabled_records}" printf "%s\\n" "${disabled_records}"
elif [[ "${1}" == "enabled" ]] elif [[ "${1}" == "enabled" ]]
then then
grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}" grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}"
@ -970,7 +970,7 @@ list() {
grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}" grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}"
if [[ -n "${disabled_records}" ]] if [[ -n "${disabled_records}" ]]
then then
printf "\nDisabled:\n%s\n" "${disabled_records}" printf "\\nDisabled:\\n%s\\n" "${disabled_records}"
fi fi
fi fi
} }
@ -999,8 +999,8 @@ remove() {
local search_hostname="" local search_hostname=""
local search_string="" local search_string=""
_debug printf "remove() \${1}: %s\n" "${1:-}" _debug printf "remove() \${1}: %s\\n" "${1:-}"
_debug printf "remove() \${2}: %s\n" "${2:-}" _debug printf "remove() \${2}: %s\\n" "${2:-}"
for arg in "${_COMMAND_ARGV[@]:-}" for arg in "${_COMMAND_ARGV[@]:-}"
do do
@ -1014,9 +1014,9 @@ remove() {
esac esac
done done
_debug printf "remove() \${arguments[0]}: %s\n" "${arguments[0]:-}" _debug printf "remove() \${arguments[0]}: %s\\n" "${arguments[0]:-}"
_debug printf "remove() \${arguments[1]}: %s\n" "${arguments[1]:-}" _debug printf "remove() \${arguments[1]}: %s\\n" "${arguments[1]:-}"
_debug printf "remove() \${arguments[2]}: %s\n" "${arguments[2]:-}" _debug printf "remove() \${arguments[2]}: %s\\n" "${arguments[2]:-}"
if [[ -z "${arguments[1]:-}" ]] if [[ -z "${arguments[1]:-}" ]]
then then
@ -1027,10 +1027,10 @@ remove() {
search_ip="${arguments[1]}" search_ip="${arguments[1]}"
search_hostname="${arguments[2]}" search_hostname="${arguments[2]}"
is_search_pair=1 is_search_pair=1
_debug printf "remove() \${is_search_pair}: %s\n" "${is_search_pair}" _debug printf "remove() \${is_search_pair}: %s\\n" "${is_search_pair}"
else else
search_string="${arguments[1]:-}" search_string="${arguments[1]:-}"
_debug printf "remove() \${search_string}: %s\n" "${search_string}" _debug printf "remove() \${search_string}: %s\\n" "${search_string}"
fi fi
# Regular Expression Notes # Regular Expression Notes
@ -1068,13 +1068,13 @@ remove() {
if [[ -z ${target_records:-} ]] if [[ -z ${target_records:-} ]]
then then
printf "No matching records found.\n" printf "No matching records found.\\n"
exit 1 exit 1
fi fi
if ! ((force_skip_prompt)) if ! ((force_skip_prompt))
then then
printf "Removing the following records:\n%s\n" "${target_records}" printf "Removing the following records:\\n%s\\n" "${target_records}"
while true while true
do do
read -r -p "Are you sure you want to proceed? [y/N] " yn read -r -p "Are you sure you want to proceed? [y/N] " yn
@ -1083,7 +1083,7 @@ remove() {
break break
;; ;;
* ) * )
printf "Exiting...\n" printf "Exiting...\\n"
exit 0 exit 0
;; ;;
esac esac
@ -1107,7 +1107,7 @@ remove() {
-e "/${target_regex_hostname}/d" \ -e "/${target_regex_hostname}/d" \
"${HOSTS_PATH}" "${HOSTS_PATH}"
fi fi
printf "Removed:\n%s\n" "${target_records}" printf "Removed:\\n%s\\n" "${target_records}"
} }
# ---------------------------------------------------------------------- search # ---------------------------------------------------------------------- search
@ -1152,11 +1152,11 @@ show() {
# Output disabled records secondly for better organization. # Output disabled records secondly for better organization.
if [[ -n "${enabled_records}" ]] if [[ -n "${enabled_records}" ]]
then then
printf "%s\n" "${enabled_records}" printf "%s\\n" "${enabled_records}"
fi fi
if [[ -n "${disabled_records}" ]] if [[ -n "${disabled_records}" ]]
then then
printf "%s\n" "${disabled_records}" printf "%s\\n" "${disabled_records}"
fi fi
else else
${_ME} help show ${_ME} help show

View File

@ -6,8 +6,8 @@ load test_helper
@test "\`add\` with no arguments exits with status 1." { @test "\`add\` with no arguments exits with status 1." {
run "${_HOSTS}" add run "${_HOSTS}" add
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -15,15 +15,15 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" add run "${_HOSTS}" add
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
} }
@test "\`add\` with no arguments prints help information." { @test "\`add\` with no arguments prints help information." {
run "${_HOSTS}" add run "${_HOSTS}" add
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts add <ip> <hostname> [<comment>]" ]] [[ "${lines[1]}" == " hosts add <ip> <hostname> [<comment>]" ]]
} }
@ -32,8 +32,8 @@ load test_helper
@test "\`add <ip>\` exits with status 1." { @test "\`add <ip>\` exits with status 1." {
run "${_HOSTS}" add 0.0.0.0 run "${_HOSTS}" add 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -41,15 +41,15 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" add 0.0.0.0 run "${_HOSTS}" add 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
} }
@test "\`add <ip>\` prints help information." { @test "\`add <ip>\` prints help information." {
run "${_HOSTS}" add 0.0.0.0 run "${_HOSTS}" add 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Please include a hostname" ]] [[ "${lines[0]}" == "Please include a hostname" ]]
[[ "${lines[1]}" == "Usage:" ]] [[ "${lines[1]}" == "Usage:" ]]
[[ "${lines[2]}" == " hosts add <ip> <hostname> [<comment>]" ]] [[ "${lines[2]}" == " hosts add <ip> <hostname> [<comment>]" ]]
@ -59,8 +59,8 @@ load test_helper
@test "\`add <ip> <hostname>\` exits with status 0." { @test "\`add <ip> <hostname>\` exits with status 0." {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -68,8 +68,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
_compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" _compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")"
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
@ -78,8 +78,8 @@ load test_helper
@test "\`add <ip> <hostname>\` prints feedback." { @test "\`add <ip> <hostname>\` prints feedback." {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Added:" ]] [[ "${lines[0]}" == "Added:" ]]
[[ "${lines[1]}" == "0.0.0.0 example.com" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]]
} }
@ -88,8 +88,8 @@ load test_helper
@test "\`add <ip> <hostname> [comment]\` exits with status 0." { @test "\`add <ip> <hostname> [comment]\` exits with status 0." {
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.'
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -97,16 +97,16 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.'
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com # Comment." ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com # Comment." ]]
} }
@test "\`add <ip> <hostname> [comment]\` prints feedback." { @test "\`add <ip> <hostname> [comment]\` prints feedback." {
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.'
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Added:" ]] [[ "${lines[0]}" == "Added:" ]]
[[ "${lines[1]}" == "0.0.0.0 example.com # Comment." ]] [[ "${lines[1]}" == "0.0.0.0 example.com # Comment." ]]
} }
@ -120,8 +120,8 @@ load test_helper
@test "\`help add\` prints help information." { @test "\`help add\` prints help information." {
run "${_HOSTS}" help add run "${_HOSTS}" help add
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts add <ip> <hostname> [<comment>]" ]] [[ "${lines[1]}" == " hosts add <ip> <hostname> [<comment>]" ]]
} }

View File

@ -6,8 +6,8 @@ load test_helper
@test "\`block\` with no arguments exits with status 1." { @test "\`block\` with no arguments exits with status 1." {
run "${_HOSTS}" block run "${_HOSTS}" block
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -15,15 +15,15 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" block run "${_HOSTS}" block
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
} }
@test "\`block\` with no arguments prints help information." { @test "\`block\` with no arguments prints help information." {
run "${_HOSTS}" block run "${_HOSTS}" block
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts block <hostname>" ]] [[ "${lines[1]}" == " hosts block <hostname>" ]]
} }
@ -32,8 +32,8 @@ load test_helper
@test "\`block <hostname>\` exits with status 0." { @test "\`block <hostname>\` exits with status 0." {
run "${_HOSTS}" block example.com run "${_HOSTS}" block example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -41,8 +41,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" block example.com run "${_HOSTS}" block example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
_compare '127.0.0.1 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" _compare '127.0.0.1 example.com' "$(sed -n '11p' "${HOSTS_PATH}")"
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
@ -51,8 +51,8 @@ load test_helper
@test "\`block <hostname>\` prints feedback." { @test "\`block <hostname>\` prints feedback." {
run "${_HOSTS}" block example.com run "${_HOSTS}" block example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Added:" ]] [[ "${lines[0]}" == "Added:" ]]
[[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]]
[[ "${lines[2]}" == "Added:" ]] [[ "${lines[2]}" == "Added:" ]]
@ -70,8 +70,8 @@ load test_helper
@test "\`help block\` prints help information." { @test "\`help block\` prints help information." {
run "${_HOSTS}" help block run "${_HOSTS}" help block
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts block <hostname>" ]] [[ "${lines[1]}" == " hosts block <hostname>" ]]
} }

View File

@ -6,8 +6,8 @@ load test_helper
@test "\`disable\` with no arguments exits with status 1." { @test "\`disable\` with no arguments exits with status 1." {
run "${_HOSTS}" disable run "${_HOSTS}" disable
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -15,15 +15,15 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" disable run "${_HOSTS}" disable
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
} }
@test "\`disable\` with no arguments prints help information." { @test "\`disable\` with no arguments prints help information." {
run "${_HOSTS}" disable run "${_HOSTS}" disable
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts disable (<ip> | <hostname> | <search string>)" ]] [[ "${lines[1]}" == " hosts disable (<ip> | <hostname> | <search string>)" ]]
} }
@ -37,8 +37,8 @@ load test_helper
} }
run "${_HOSTS}" disable 0.0.0.0 run "${_HOSTS}" disable 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -50,8 +50,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" disable 0.0.0.0 run "${_HOSTS}" disable 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]]
@ -65,8 +65,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" disable 0.0.0.0 run "${_HOSTS}" disable 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.net" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.net" ]]
@ -79,8 +79,8 @@ load test_helper
} }
run "${_HOSTS}" disable 0.0.0.0 run "${_HOSTS}" disable 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Disabling:" ]] [[ "${lines[0]}" == "Disabling:" ]]
[[ "${lines[1]}" == "0.0.0.0 example.com" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]]
} }
@ -94,8 +94,8 @@ load test_helper
} }
run "${_HOSTS}" disable example.com run "${_HOSTS}" disable example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -107,8 +107,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" disable example.com run "${_HOSTS}" disable example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]]
@ -122,8 +122,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" disable example.com run "${_HOSTS}" disable example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 127.0.0.1 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 127.0.0.1 example.com" ]]
@ -136,8 +136,8 @@ load test_helper
} }
run "${_HOSTS}" disable example.com run "${_HOSTS}" disable example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Disabling:" ]] [[ "${lines[0]}" == "Disabling:" ]]
[[ "${lines[1]}" == "0.0.0.0 example.com" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]]
} }
@ -151,8 +151,8 @@ load test_helper
@test "\`help disable\` prints help information." { @test "\`help disable\` prints help information." {
run "${_HOSTS}" help disable run "${_HOSTS}" help disable
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts disable (<ip> | <hostname> | <search string>)" ]] [[ "${lines[1]}" == " hosts disable (<ip> | <hostname> | <search string>)" ]]
} }

View File

@ -13,8 +13,8 @@ load test_helper
} }
run "${_HOSTS}" disabled run "${_HOSTS}" disabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -27,8 +27,8 @@ load test_helper
} }
run "${_HOSTS}" disabled run "${_HOSTS}" disabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[0]}" == "0.0.0.0 example.com" ]]
[[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]]
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
@ -43,8 +43,8 @@ load test_helper
@test "\`help disabled\` prints help information." { @test "\`help disabled\` prints help information." {
run "${_HOSTS}" help disabled run "${_HOSTS}" help disabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts disabled" ]] [[ "${lines[1]}" == " hosts disabled" ]]
} }

View File

@ -6,8 +6,8 @@ load test_helper
@test "\`enable\` with no arguments exits with status 1." { @test "\`enable\` with no arguments exits with status 1." {
run "${_HOSTS}" enable run "${_HOSTS}" enable
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -15,15 +15,15 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" enable run "${_HOSTS}" enable
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
} }
@test "\`enable\` with no arguments prints help information." { @test "\`enable\` with no arguments prints help information." {
run "${_HOSTS}" enable run "${_HOSTS}" enable
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts enable (<ip> | <hostname> | <search string>)" ]] [[ "${lines[1]}" == " hosts enable (<ip> | <hostname> | <search string>)" ]]
} }
@ -39,8 +39,8 @@ load test_helper
} }
run "${_HOSTS}" enable 127.0.0.2 run "${_HOSTS}" enable 127.0.0.2
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -55,8 +55,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" enable 127.0.0.2 run "${_HOSTS}" enable 127.0.0.2
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.net" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.net" ]]
@ -74,8 +74,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" enable 0.0.0.0 run "${_HOSTS}" enable 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare \ _compare \
"${_original}" \ "${_original}" \
"$(cat "${HOSTS_PATH}")" "$(cat "${HOSTS_PATH}")"
@ -103,8 +103,8 @@ load test_helper
} }
run "${_HOSTS}" enable 127.0.0.2 run "${_HOSTS}" enable 127.0.0.2
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Enabling:" ]] [[ "${lines[0]}" == "Enabling:" ]]
[[ "${lines[1]}" == "127.0.0.2 example.com" ]] [[ "${lines[1]}" == "127.0.0.2 example.com" ]]
} }
@ -120,8 +120,8 @@ load test_helper
} }
run "${_HOSTS}" enable example.net run "${_HOSTS}" enable example.net
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -135,8 +135,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" enable example.net run "${_HOSTS}" enable example.net
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]]
@ -154,8 +154,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" enable example.com run "${_HOSTS}" enable example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare \ _compare \
"${_original}" \ "${_original}" \
"$(cat "${HOSTS_PATH}")" "$(cat "${HOSTS_PATH}")"
@ -183,8 +183,8 @@ load test_helper
} }
run "${_HOSTS}" enable example.net run "${_HOSTS}" enable example.net
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Enabling:" ]] [[ "${lines[0]}" == "Enabling:" ]]
[[ "${lines[1]}" == "0.0.0.0 example.net" ]] [[ "${lines[1]}" == "0.0.0.0 example.net" ]]
} }
@ -198,8 +198,8 @@ load test_helper
@test "\`help enable\` prints help information." { @test "\`help enable\` prints help information." {
run "${_HOSTS}" help enable run "${_HOSTS}" help enable
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts enable (<ip> | <hostname> | <search string>)" ]] [[ "${lines[1]}" == " hosts enable (<ip> | <hostname> | <search string>)" ]]
} }

View File

@ -13,8 +13,8 @@ load test_helper
} }
run "${_HOSTS}" enabled run "${_HOSTS}" enabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -27,8 +27,8 @@ load test_helper
} }
run "${_HOSTS}" enabled run "${_HOSTS}" enabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "127.0.0.1 localhost" ]] [[ "${lines[0]}" == "127.0.0.1 localhost" ]]
[[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]] [[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]]
[[ "${lines[2]}" == "::1 localhost" ]] [[ "${lines[2]}" == "::1 localhost" ]]
@ -45,8 +45,8 @@ load test_helper
@test "\`help enabled\` prints help information." { @test "\`help enabled\` prints help information." {
run "${_HOSTS}" help enabled run "${_HOSTS}" help enabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts enabled" ]] [[ "${lines[1]}" == " hosts enabled" ]]
} }

View File

@ -21,8 +21,8 @@ load test_helper
@test "\`help file\` prints help information." { @test "\`help file\` prints help information." {
run "${_HOSTS}" help file run "${_HOSTS}" help file
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts file" ]] [[ "${lines[1]}" == " hosts file" ]]
} }

View File

@ -13,8 +13,8 @@ load test_helper
} }
run "${_HOSTS}" list run "${_HOSTS}" list
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -27,8 +27,8 @@ load test_helper
} }
run "${_HOSTS}" list run "${_HOSTS}" list
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_expected="\ _expected="\
127.0.0.1 localhost 127.0.0.1 localhost
255.255.255.255 broadcasthost 255.255.255.255 broadcasthost
@ -54,8 +54,8 @@ Disabled:
} }
run "${_HOSTS}" list enabled run "${_HOSTS}" list enabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -68,8 +68,8 @@ Disabled:
} }
run "${_HOSTS}" list enabled run "${_HOSTS}" list enabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "127.0.0.1 localhost" ]] [[ "${lines[0]}" == "127.0.0.1 localhost" ]]
[[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]] [[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]]
[[ "${lines[2]}" == "::1 localhost" ]] [[ "${lines[2]}" == "::1 localhost" ]]
@ -88,8 +88,8 @@ Disabled:
} }
run "${_HOSTS}" list disabled run "${_HOSTS}" list disabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -102,8 +102,8 @@ Disabled:
} }
run "${_HOSTS}" list disabled run "${_HOSTS}" list disabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[0]}" == "0.0.0.0 example.com" ]]
[[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]]
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
@ -119,8 +119,8 @@ Disabled:
} }
run "${_HOSTS}" list example.com run "${_HOSTS}" list example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -132,8 +132,8 @@ Disabled:
} }
run "${_HOSTS}" list example.com run "${_HOSTS}" list example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[0]}" == "0.0.0.0 example.com" ]]
[[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]]
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
@ -148,8 +148,8 @@ Disabled:
@test "\`help list\` prints help information." { @test "\`help list\` prints help information." {
run "${_HOSTS}" help list run "${_HOSTS}" help list
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts list [enabled | disabled | <search string>]" ]] [[ "${lines[1]}" == " hosts list [enabled | disabled | <search string>]" ]]
} }

View File

@ -6,8 +6,8 @@ load test_helper
@test "\`remove\` with no arguments exits with status 1." { @test "\`remove\` with no arguments exits with status 1." {
run "${_HOSTS}" remove run "${_HOSTS}" remove
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -15,15 +15,15 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" remove run "${_HOSTS}" remove
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
} }
@test "\`remove\` with no arguments prints help information." { @test "\`remove\` with no arguments prints help information." {
run "${_HOSTS}" remove run "${_HOSTS}" remove
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts remove (<ip> | <hostname> | <search string>) [--force]" ]] [[ "${lines[1]}" == " hosts remove (<ip> | <hostname> | <search string>) [--force]" ]]
} }
@ -38,8 +38,8 @@ load test_helper
} }
run "${_HOSTS}" remove 127.0.0.3 --force run "${_HOSTS}" remove 127.0.0.3 --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -51,8 +51,8 @@ load test_helper
} }
run "${_HOSTS}" remove 127.0.0.3 --force run "${_HOSTS}" remove 127.0.0.3 --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${output} == "No matching records found." ]] [[ ${output} == "No matching records found." ]]
} }
@ -66,8 +66,8 @@ load test_helper
} }
run "${_HOSTS}" remove 127.0.0.2 --force run "${_HOSTS}" remove 127.0.0.2 --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -80,8 +80,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" remove 127.0.0.2 --force run "${_HOSTS}" remove 127.0.0.2 --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]]
@ -99,8 +99,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" remove 0.0.0.0 --force run "${_HOSTS}" remove 0.0.0.0 --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_expected="\ _expected="\
## ##
# Host Database # Host Database
@ -126,8 +126,8 @@ fe80::1%lo0 localhost
} }
run "${_HOSTS}" remove 127.0.0.2 --force run "${_HOSTS}" remove 127.0.0.2 --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Removed:" ]] [[ "${lines[0]}" == "Removed:" ]]
[[ "${lines[1]}" == "127.0.0.2 example.com" ]] [[ "${lines[1]}" == "127.0.0.2 example.com" ]]
} }
@ -142,8 +142,8 @@ fe80::1%lo0 localhost
} }
run "${_HOSTS}" remove example.com --force run "${_HOSTS}" remove example.com --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -156,8 +156,8 @@ fe80::1%lo0 localhost
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" remove example.com --force run "${_HOSTS}" remove example.com --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "" ]]
@ -174,8 +174,8 @@ fe80::1%lo0 localhost
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" remove example.com --force run "${_HOSTS}" remove example.com --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_expected="\ _expected="\
## ##
# Host Database # Host Database
@ -202,8 +202,8 @@ fe80::1%lo0 localhost
} }
run "${_HOSTS}" remove example.com --force run "${_HOSTS}" remove example.com --force
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_expected="\ _expected="\
Removed: Removed:
0.0.0.0 example.com 0.0.0.0 example.com
@ -220,8 +220,8 @@ Removed:
@test "\`help remove\` prints help information." { @test "\`help remove\` prints help information." {
run "${_HOSTS}" help remove run "${_HOSTS}" help remove
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts remove (<ip> | <hostname> | <search string>) [--force]" ]] [[ "${lines[1]}" == " hosts remove (<ip> | <hostname> | <search string>) [--force]" ]]
} }

View File

@ -13,8 +13,8 @@ load test_helper
} }
run "${_HOSTS}" search run "${_HOSTS}" search
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -27,8 +27,8 @@ load test_helper
} }
run "${_HOSTS}" search run "${_HOSTS}" search
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_expected="\ _expected="\
Usage: Usage:
hosts search <search string> hosts search <search string>
@ -50,8 +50,8 @@ Description:
} }
run "${_HOSTS}" search enabled run "${_HOSTS}" search enabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -64,8 +64,8 @@ Description:
} }
run "${_HOSTS}" search enabled run "${_HOSTS}" search enabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "127.0.0.1 localhost" ]] [[ "${lines[0]}" == "127.0.0.1 localhost" ]]
[[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]] [[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]]
[[ "${lines[2]}" == "::1 localhost" ]] [[ "${lines[2]}" == "::1 localhost" ]]
@ -84,8 +84,8 @@ Description:
} }
run "${_HOSTS}" search disabled run "${_HOSTS}" search disabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -98,8 +98,8 @@ Description:
} }
run "${_HOSTS}" search disabled run "${_HOSTS}" search disabled
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[0]}" == "0.0.0.0 example.com" ]]
[[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]]
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
@ -115,8 +115,8 @@ Description:
} }
run "${_HOSTS}" search example.com run "${_HOSTS}" search example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -128,8 +128,8 @@ Description:
} }
run "${_HOSTS}" search example.com run "${_HOSTS}" search example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[0]}" == "0.0.0.0 example.com" ]]
[[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]]
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
@ -144,8 +144,8 @@ Description:
@test "\`help search\` prints help information." { @test "\`help search\` prints help information." {
run "${_HOSTS}" help search run "${_HOSTS}" help search
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts search <search string>" ]] [[ "${lines[1]}" == " hosts search <search string>" ]]
} }

View File

@ -6,15 +6,15 @@ load test_helper
@test "\`show\` with no arguments exits with status 1." { @test "\`show\` with no arguments exits with status 1." {
run "${_HOSTS}" show run "${_HOSTS}" show
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@test "\`show\` with no arguments prints help information." { @test "\`show\` with no arguments prints help information." {
run "${_HOSTS}" show run "${_HOSTS}" show
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]] [[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]]
} }
@ -30,8 +30,8 @@ load test_helper
} }
run "${_HOSTS}" show 0.0.0.0 run "${_HOSTS}" show 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -44,8 +44,8 @@ load test_helper
} }
run "${_HOSTS}" show 0.0.0.0 run "${_HOSTS}" show 0.0.0.0
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "0.0.0.0 example.net" ]] [[ "${lines[0]}" == "0.0.0.0 example.net" ]]
[[ "${lines[1]}" == "disabled: 0.0.0.0 example.com" ]] [[ "${lines[1]}" == "disabled: 0.0.0.0 example.com" ]]
@ -62,8 +62,8 @@ load test_helper
} }
run "${_HOSTS}" show example.com run "${_HOSTS}" show example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -76,8 +76,8 @@ load test_helper
} }
run "${_HOSTS}" show example.com run "${_HOSTS}" show example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "127.0.0.2 example.com" ]] [[ "${lines[0]}" == "127.0.0.2 example.com" ]]
[[ "${lines[1]}" == "disabled: 0.0.0.0 example.com" ]] [[ "${lines[1]}" == "disabled: 0.0.0.0 example.com" ]]
@ -92,8 +92,8 @@ load test_helper
@test "\`help show\` prints help information." { @test "\`help show\` prints help information." {
run "${_HOSTS}" help show run "${_HOSTS}" help show
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]] [[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]]
} }

View File

@ -40,6 +40,6 @@ teardown() {
_compare() { _compare() {
local _expected="${1:-}" local _expected="${1:-}"
local _actual="${2:-}" local _actual="${2:-}"
printf "expected:\n%s\n" "${_expected}" printf "expected:\\n%s\\n" "${_expected}"
printf "actual:\n%s\n" "${_actual}" printf "actual:\\n%s\\n" "${_actual}"
} }

View File

@ -6,8 +6,8 @@ load test_helper
@test "\`unblock\` with no arguments exits with status 1." { @test "\`unblock\` with no arguments exits with status 1." {
run "${_HOSTS}" unblock run "${_HOSTS}" unblock
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -15,15 +15,15 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" unblock run "${_HOSTS}" unblock
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
} }
@test "\`unblock\` with no arguments prints help information." { @test "\`unblock\` with no arguments prints help information." {
run "${_HOSTS}" unblock run "${_HOSTS}" unblock
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts unblock <hostname>" ]] [[ "${lines[1]}" == " hosts unblock <hostname>" ]]
} }
@ -36,8 +36,8 @@ load test_helper
} }
run "${_HOSTS}" unblock example.net run "${_HOSTS}" unblock example.net
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]] [[ ${status} -eq 1 ]]
} }
@ -47,8 +47,8 @@ load test_helper
} }
run "${_HOSTS}" unblock example.net run "${_HOSTS}" unblock example.net
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${output} == "No matching records found." ]] [[ ${output} == "No matching records found." ]]
} }
@ -62,8 +62,8 @@ load test_helper
} }
run "${_HOSTS}" unblock example.com run "${_HOSTS}" unblock example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@ -76,8 +76,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" unblock example.com run "${_HOSTS}" unblock example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare "${_original}" "$(cat "${HOSTS_PATH}")"
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]]
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]]
@ -93,8 +93,8 @@ load test_helper
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" unblock example.com run "${_HOSTS}" unblock example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_expected="\ _expected="\
## ##
# Host Database # Host Database
@ -121,8 +121,8 @@ fe80::1%lo0 localhost
} }
run "${_HOSTS}" unblock example.com run "${_HOSTS}" unblock example.com
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
_expected="\ _expected="\
Removed: Removed:
127.0.0.1 example.com 127.0.0.1 example.com
@ -142,8 +142,8 @@ Removed:
@test "\`help unblock\` prints help information." { @test "\`help unblock\` prints help information." {
run "${_HOSTS}" help unblock run "${_HOSTS}" help unblock
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts unblock <hostname>" ]] [[ "${lines[1]}" == " hosts unblock <hostname>" ]]
} }

View File

@ -33,8 +33,8 @@ load test_helper
@test "\`help version\` prints help information." { @test "\`help version\` prints help information." {
run "${_HOSTS}" help version run "${_HOSTS}" help version
printf "\${status}: %s\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]] [[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts (version | --version)" ]] [[ "${lines[1]}" == " hosts (version | --version)" ]]
} }