From 80edd464b6725b39abb2de0d68aff056e99fb204 Mon Sep 17 00:00:00 2001 From: William Melody Date: Sun, 15 Apr 2018 14:55:26 -0700 Subject: [PATCH] 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 --- hosts | 122 +++++++++++++++++++++--------------------- test/add.bats | 52 +++++++++--------- test/block.bats | 28 +++++----- test/disable.bats | 48 ++++++++--------- test/disabled.bats | 12 ++--- test/enable.bats | 48 ++++++++--------- test/enabled.bats | 12 ++--- test/file.bats | 4 +- test/list.bats | 36 ++++++------- test/remove.bats | 56 +++++++++---------- test/search.bats | 36 ++++++------- test/show.bats | 28 +++++----- test/test_helper.bash | 4 +- test/unblock.bats | 40 +++++++------- test/version.bats | 4 +- 15 files changed, 265 insertions(+), 265 deletions(-) diff --git a/hosts b/hosts index c82cf85..f6adea5 100755 --- a/hosts +++ b/hosts @@ -63,18 +63,18 @@ export _TAB_SPACE_CC_="[${_TAB_SPACE_}]" # _debug() # # 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` # variable has been set. The command is expected to print a message and # should typically be either `echo`, `printf`, or `cat`. _debug() { if [[ "${_USE_DEBUG:-"0"}" -eq 1 ]] - then + then # Prefix debug message with "bug (U+1F41B)" printf "🐛 " "${@}" - printf "――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n" + printf "――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\\n" fi } # debug() @@ -96,7 +96,7 @@ debug() { # _die() # # 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 # command. The command is expected to print a message and should typically @@ -264,16 +264,16 @@ _COMMAND_PARAMETERS=(${_COMMAND_ARGV[*]}) unset "_COMMAND_PARAMETERS[0]" _debug printf \ - "\${_CMD}: %s\n" \ + "\${_CMD}: %s\\n" \ "${_CMD}" _debug printf \ - "\${_RAW_OPTIONS} (one per line):\n%s\n" \ + "\${_RAW_OPTIONS} (one per line):\\n%s\\n" \ "${_RAW_OPTIONS}" _debug printf \ - "\${_COMMAND_ARGV[*]}: %s\n" \ + "\${_COMMAND_ARGV[*]}: %s\\n" \ "${_COMMAND_ARGV[*]}" _debug printf \ - "\${_COMMAND_PARAMETERS[*]:-}: %s\n" \ + "\${_COMMAND_PARAMETERS[*]:-}: %s\\n" \ "${_COMMAND_PARAMETERS[*]:-}" ############################################################################### @@ -285,7 +285,7 @@ _debug printf \ # Set to the program's basename. _ME=$(basename "${0}") -_debug printf "\${_ME}: %s\n" "${_ME}" +_debug printf "\${_ME}: %s\\n" "${_ME}" ############################################################################### # Load Commands @@ -302,8 +302,8 @@ _DEFINED_COMMANDS=() # Loads all of the commands sourced in the environment. _load_commands() { - _debug printf "_load_commands(): entering...\n" - _debug printf "_load_commands() declare -F:\n%s\n" "$(declare -F)" + _debug printf "_load_commands(): entering...\\n" + _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' # option, displays all of the functions with the format @@ -318,7 +318,7 @@ _load_commands() { local function_name 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 # with an underscore or is one of the desc(), debug(), or die() functions, @@ -334,7 +334,7 @@ _load_commands() { done _debug printf \ - "commands() \${_DEFINED_COMMANDS[*]:-}:\n%s\n" \ + "commands() \${_DEFINED_COMMANDS[*]:-}:\\n%s\\n" \ "${_DEFINED_COMMANDS[*]:-}" } @@ -351,8 +351,8 @@ _load_commands() { # # NOTE: must be called at end of program after all commands have been defined. _main() { - _debug printf "main(): entering...\n" - _debug printf "main() \${_CMD} (upon entering): %s\n" "${_CMD}" + _debug printf "main(): entering...\\n" + _debug printf "main() \${_CMD} (upon entering): %s\\n" "${_CMD}" # If $_CMD is blank, then set to `$HOSTS_DEFAULT_COMMAND` if [[ -z ${_CMD} ]] @@ -416,10 +416,10 @@ _contains() { local test_list=(${*:2}) for _test_element in "${test_list[@]:-}" do - _debug printf "_contains() \${_test_element}: %s\n" "${_test_element}" + _debug printf "_contains() \${_test_element}: %s\\n" "${_test_element}" if [[ "${_test_element}" == "${1}" ]] then - _debug printf "_contains() match: %s\n" "${1}" + _debug printf "_contains() match: %s\\n" "${1}" return 0 fi done @@ -495,7 +495,7 @@ _verify_write_permissions() { else _die printf \ "You don't have permission to perform this operation. Try again with: -sudo !!\n" +sudo !!\\n" fi fi } @@ -531,16 +531,16 @@ sudo !!\n" # escaping backslashes, which is more common. desc() { 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:-} ]] then read -r -d '' "_desc_${1}" <> "${HOSTS_PATH}" - printf "Added:\n%s\t%s\t# %s\n" \ + printf "Added:\\n%s\t%s\t# %s\\n" \ "${ip}" \ "${hostname}" \ "${formatted_comment}" else - printf "%s\t%s\n" \ + printf "%s\t%s\\n" \ "${ip}" \ "${hostname}" >> "${HOSTS_PATH}" - printf "Added:\n%s\t%s\n" \ + printf "Added:\\n%s\t%s\\n" \ "${ip}" \ "${hostname}" fi @@ -787,7 +787,7 @@ disable() { ${_ME} help disable exit 1 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_commented_hostname="^\([^#]..*[${_TAB_SPACE_}]${search_string}[${_TAB_SPACE_}]..*\)$" @@ -805,13 +805,13 @@ disable() { -e "s/${target_regex_hostname}/\1/p" \ "${HOSTS_PATH}" ) - _debug printf "disable() \${targets}: %s\n" "${targets}" + _debug printf "disable() \${targets}: %s\\n" "${targets}" if [[ -z "${targets}" ]] then - _die printf "Not found: %s\n" "${search_string}" + _die printf "Not found: %s\\n" "${search_string}" fi - printf "Disabling:\n%s\n" "${targets}" + printf "Disabling:\\n%s\\n" "${targets}" # -i '' - in place edit. BSD sed requires extension argument, for GNU # it's optional. More info: http://stackoverflow.com/a/16746032 @@ -849,7 +849,7 @@ edit() { _verify_write_permissions "$@" if [[ -z "${EDITOR}" ]] then - _die printf "\$EDITOR not set.\n" + _die printf "\$EDITOR not set.\\n" else "${EDITOR}" "${HOSTS_PATH}" fi @@ -873,7 +873,7 @@ enable() { ${_ME} help enable exit 1 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_commented_hostname="^\#disabled: \(..*[${_TAB_SPACE_}]${search_string}[${_TAB_SPACE_}]..*\)$" @@ -891,13 +891,13 @@ enable() { -e "s/${target_regex_hostname}/\1/p" \ "${HOSTS_PATH}" ) - _debug printf "enable() \${targets}: %s\n" "${targets}" + _debug printf "enable() \${targets}: %s\\n" "${targets}" if [[ -z "${targets}" ]] then - _die printf "Not found: %s\n" "${search_string}" + _die printf "Not found: %s\\n" "${search_string}" fi - printf "Enabling:\n%s\n" "${targets}" + printf "Enabling:\\n%s\\n" "${targets}" # -i '' - in place edit. BSD sed requires extension argument, for GNU # it's optional. More info: http://stackoverflow.com/a/16746032 @@ -957,7 +957,7 @@ list() { then if [[ "${1}" == "disabled" ]] then - printf "%s\n" "${disabled_records}" + printf "%s\\n" "${disabled_records}" elif [[ "${1}" == "enabled" ]] then grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}" @@ -970,7 +970,7 @@ list() { grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}" if [[ -n "${disabled_records}" ]] then - printf "\nDisabled:\n%s\n" "${disabled_records}" + printf "\\nDisabled:\\n%s\\n" "${disabled_records}" fi fi } @@ -999,8 +999,8 @@ remove() { local search_hostname="" local search_string="" - _debug printf "remove() \${1}: %s\n" "${1:-}" - _debug printf "remove() \${2}: %s\n" "${2:-}" + _debug printf "remove() \${1}: %s\\n" "${1:-}" + _debug printf "remove() \${2}: %s\\n" "${2:-}" for arg in "${_COMMAND_ARGV[@]:-}" do @@ -1014,9 +1014,9 @@ remove() { esac done - _debug printf "remove() \${arguments[0]}: %s\n" "${arguments[0]:-}" - _debug printf "remove() \${arguments[1]}: %s\n" "${arguments[1]:-}" - _debug printf "remove() \${arguments[2]}: %s\n" "${arguments[2]:-}" + _debug printf "remove() \${arguments[0]}: %s\\n" "${arguments[0]:-}" + _debug printf "remove() \${arguments[1]}: %s\\n" "${arguments[1]:-}" + _debug printf "remove() \${arguments[2]}: %s\\n" "${arguments[2]:-}" if [[ -z "${arguments[1]:-}" ]] then @@ -1027,10 +1027,10 @@ remove() { search_ip="${arguments[1]}" search_hostname="${arguments[2]}" 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 search_string="${arguments[1]:-}" - _debug printf "remove() \${search_string}: %s\n" "${search_string}" + _debug printf "remove() \${search_string}: %s\\n" "${search_string}" fi # Regular Expression Notes @@ -1068,13 +1068,13 @@ remove() { if [[ -z ${target_records:-} ]] then - printf "No matching records found.\n" + printf "No matching records found.\\n" exit 1 fi if ! ((force_skip_prompt)) then - printf "Removing the following records:\n%s\n" "${target_records}" + printf "Removing the following records:\\n%s\\n" "${target_records}" while true do read -r -p "Are you sure you want to proceed? [y/N] " yn @@ -1083,7 +1083,7 @@ remove() { break ;; * ) - printf "Exiting...\n" + printf "Exiting...\\n" exit 0 ;; esac @@ -1107,7 +1107,7 @@ remove() { -e "/${target_regex_hostname}/d" \ "${HOSTS_PATH}" fi - printf "Removed:\n%s\n" "${target_records}" + printf "Removed:\\n%s\\n" "${target_records}" } # ---------------------------------------------------------------------- search @@ -1152,11 +1152,11 @@ show() { # Output disabled records secondly for better organization. if [[ -n "${enabled_records}" ]] then - printf "%s\n" "${enabled_records}" + printf "%s\\n" "${enabled_records}" fi if [[ -n "${disabled_records}" ]] then - printf "%s\n" "${disabled_records}" + printf "%s\\n" "${disabled_records}" fi else ${_ME} help show diff --git a/test/add.bats b/test/add.bats index c9bb457..d7b8a40 100644 --- a/test/add.bats +++ b/test/add.bats @@ -6,8 +6,8 @@ load test_helper @test "\`add\` with no arguments exits with status 1." { run "${_HOSTS}" add - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -15,15 +15,15 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" add - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] } @test "\`add\` with no arguments prints help information." { run "${_HOSTS}" add - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts add []" ]] } @@ -32,8 +32,8 @@ load test_helper @test "\`add \` exits with status 1." { run "${_HOSTS}" add 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -41,15 +41,15 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" add 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] } @test "\`add \` prints help information." { run "${_HOSTS}" add 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Please include a hostname" ]] [[ "${lines[1]}" == "Usage:" ]] [[ "${lines[2]}" == " hosts add []" ]] @@ -59,8 +59,8 @@ load test_helper @test "\`add \` exits with status 0." { run "${_HOSTS}" add 0.0.0.0 example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -68,8 +68,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" add 0.0.0.0 example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] @@ -78,8 +78,8 @@ load test_helper @test "\`add \` prints feedback." { run "${_HOSTS}" add 0.0.0.0 example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Added:" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]] } @@ -88,8 +88,8 @@ load test_helper @test "\`add [comment]\` exits with status 0." { run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -97,16 +97,16 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com # Comment." ]] } @test "\`add [comment]\` prints feedback." { run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Added:" ]] [[ "${lines[1]}" == "0.0.0.0 example.com # Comment." ]] } @@ -120,8 +120,8 @@ load test_helper @test "\`help add\` prints help information." { run "${_HOSTS}" help add - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts add []" ]] } diff --git a/test/block.bats b/test/block.bats index 2d69132..c181911 100644 --- a/test/block.bats +++ b/test/block.bats @@ -6,8 +6,8 @@ load test_helper @test "\`block\` with no arguments exits with status 1." { run "${_HOSTS}" block - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -15,15 +15,15 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" block - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] } @test "\`block\` with no arguments prints help information." { run "${_HOSTS}" block - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts block " ]] } @@ -32,8 +32,8 @@ load test_helper @test "\`block \` exits with status 0." { run "${_HOSTS}" block example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -41,8 +41,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" block example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare '127.0.0.1 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] @@ -51,8 +51,8 @@ load test_helper @test "\`block \` prints feedback." { run "${_HOSTS}" block example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Added:" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[2]}" == "Added:" ]] @@ -70,8 +70,8 @@ load test_helper @test "\`help block\` prints help information." { run "${_HOSTS}" help block - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts block " ]] } diff --git a/test/disable.bats b/test/disable.bats index f496e0a..2eabf30 100644 --- a/test/disable.bats +++ b/test/disable.bats @@ -6,8 +6,8 @@ load test_helper @test "\`disable\` with no arguments exits with status 1." { run "${_HOSTS}" disable - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -15,15 +15,15 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" disable - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] } @test "\`disable\` with no arguments prints help information." { run "${_HOSTS}" disable - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts disable ( | | )" ]] } @@ -37,8 +37,8 @@ load test_helper } run "${_HOSTS}" disable 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -50,8 +50,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" disable 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]] @@ -65,8 +65,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" disable 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(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 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Disabling:" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]] } @@ -94,8 +94,8 @@ load test_helper } run "${_HOSTS}" disable example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -107,8 +107,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" disable example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]] @@ -122,8 +122,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" disable example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 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 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Disabling:" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]] } @@ -151,8 +151,8 @@ load test_helper @test "\`help disable\` prints help information." { run "${_HOSTS}" help disable - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts disable ( | | )" ]] } diff --git a/test/disabled.bats b/test/disabled.bats index 8147d1a..5831cf9 100644 --- a/test/disabled.bats +++ b/test/disabled.bats @@ -13,8 +13,8 @@ load test_helper } run "${_HOSTS}" disabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -27,8 +27,8 @@ load test_helper } run "${_HOSTS}" disabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[2]}" == "" ]] @@ -43,8 +43,8 @@ load test_helper @test "\`help disabled\` prints help information." { run "${_HOSTS}" help disabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts disabled" ]] } diff --git a/test/enable.bats b/test/enable.bats index 157546b..c7ea6ba 100644 --- a/test/enable.bats +++ b/test/enable.bats @@ -6,8 +6,8 @@ load test_helper @test "\`enable\` with no arguments exits with status 1." { run "${_HOSTS}" enable - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -15,15 +15,15 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" enable - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] } @test "\`enable\` with no arguments prints help information." { run "${_HOSTS}" enable - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts enable ( | | )" ]] } @@ -39,8 +39,8 @@ load test_helper } run "${_HOSTS}" enable 127.0.0.2 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -55,8 +55,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" enable 127.0.0.2 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.net" ]] @@ -74,8 +74,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" enable 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare \ "${_original}" \ "$(cat "${HOSTS_PATH}")" @@ -103,8 +103,8 @@ load test_helper } run "${_HOSTS}" enable 127.0.0.2 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Enabling:" ]] [[ "${lines[1]}" == "127.0.0.2 example.com" ]] } @@ -120,8 +120,8 @@ load test_helper } run "${_HOSTS}" enable example.net - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -135,8 +135,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" enable example.net - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]] @@ -154,8 +154,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" enable example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare \ "${_original}" \ "$(cat "${HOSTS_PATH}")" @@ -183,8 +183,8 @@ load test_helper } run "${_HOSTS}" enable example.net - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Enabling:" ]] [[ "${lines[1]}" == "0.0.0.0 example.net" ]] } @@ -198,8 +198,8 @@ load test_helper @test "\`help enable\` prints help information." { run "${_HOSTS}" help enable - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts enable ( | | )" ]] } diff --git a/test/enabled.bats b/test/enabled.bats index 2a0f039..21cfcd6 100644 --- a/test/enabled.bats +++ b/test/enabled.bats @@ -13,8 +13,8 @@ load test_helper } run "${_HOSTS}" enabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -27,8 +27,8 @@ load test_helper } run "${_HOSTS}" enabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "127.0.0.1 localhost" ]] [[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]] [[ "${lines[2]}" == "::1 localhost" ]] @@ -45,8 +45,8 @@ load test_helper @test "\`help enabled\` prints help information." { run "${_HOSTS}" help enabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts enabled" ]] } diff --git a/test/file.bats b/test/file.bats index e08a3fd..2511153 100644 --- a/test/file.bats +++ b/test/file.bats @@ -21,8 +21,8 @@ load test_helper @test "\`help file\` prints help information." { run "${_HOSTS}" help file - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts file" ]] } diff --git a/test/list.bats b/test/list.bats index 63c4f23..1785051 100644 --- a/test/list.bats +++ b/test/list.bats @@ -13,8 +13,8 @@ load test_helper } run "${_HOSTS}" list - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -27,8 +27,8 @@ load test_helper } run "${_HOSTS}" list - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _expected="\ 127.0.0.1 localhost 255.255.255.255 broadcasthost @@ -54,8 +54,8 @@ Disabled: } run "${_HOSTS}" list enabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -68,8 +68,8 @@ Disabled: } run "${_HOSTS}" list enabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "127.0.0.1 localhost" ]] [[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]] [[ "${lines[2]}" == "::1 localhost" ]] @@ -88,8 +88,8 @@ Disabled: } run "${_HOSTS}" list disabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -102,8 +102,8 @@ Disabled: } run "${_HOSTS}" list disabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[2]}" == "" ]] @@ -119,8 +119,8 @@ Disabled: } run "${_HOSTS}" list example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -132,8 +132,8 @@ Disabled: } run "${_HOSTS}" list example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[2]}" == "" ]] @@ -148,8 +148,8 @@ Disabled: @test "\`help list\` prints help information." { run "${_HOSTS}" help list - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts list [enabled | disabled | ]" ]] } diff --git a/test/remove.bats b/test/remove.bats index 8d380b8..0290b8f 100644 --- a/test/remove.bats +++ b/test/remove.bats @@ -6,8 +6,8 @@ load test_helper @test "\`remove\` with no arguments exits with status 1." { run "${_HOSTS}" remove - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -15,15 +15,15 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" remove - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] } @test "\`remove\` with no arguments prints help information." { run "${_HOSTS}" remove - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts remove ( | | ) [--force]" ]] } @@ -38,8 +38,8 @@ load test_helper } run "${_HOSTS}" remove 127.0.0.3 --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -51,8 +51,8 @@ load test_helper } run "${_HOSTS}" remove 127.0.0.3 --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${output} == "No matching records found." ]] } @@ -66,8 +66,8 @@ load test_helper } run "${_HOSTS}" remove 127.0.0.2 --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -80,8 +80,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" remove 127.0.0.2 --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]] @@ -99,8 +99,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" remove 0.0.0.0 --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _expected="\ ## # Host Database @@ -126,8 +126,8 @@ fe80::1%lo0 localhost } run "${_HOSTS}" remove 127.0.0.2 --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Removed:" ]] [[ "${lines[1]}" == "127.0.0.2 example.com" ]] } @@ -142,8 +142,8 @@ fe80::1%lo0 localhost } run "${_HOSTS}" remove example.com --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -156,8 +156,8 @@ fe80::1%lo0 localhost _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" remove example.com --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "" ]] @@ -174,8 +174,8 @@ fe80::1%lo0 localhost _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" remove example.com --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _expected="\ ## # Host Database @@ -202,8 +202,8 @@ fe80::1%lo0 localhost } run "${_HOSTS}" remove example.com --force - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _expected="\ Removed: 0.0.0.0 example.com @@ -220,8 +220,8 @@ Removed: @test "\`help remove\` prints help information." { run "${_HOSTS}" help remove - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts remove ( | | ) [--force]" ]] } diff --git a/test/search.bats b/test/search.bats index af71247..d320cb8 100644 --- a/test/search.bats +++ b/test/search.bats @@ -13,8 +13,8 @@ load test_helper } run "${_HOSTS}" search - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -27,8 +27,8 @@ load test_helper } run "${_HOSTS}" search - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _expected="\ Usage: hosts search @@ -50,8 +50,8 @@ Description: } run "${_HOSTS}" search enabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -64,8 +64,8 @@ Description: } run "${_HOSTS}" search enabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "127.0.0.1 localhost" ]] [[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]] [[ "${lines[2]}" == "::1 localhost" ]] @@ -84,8 +84,8 @@ Description: } run "${_HOSTS}" search disabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -98,8 +98,8 @@ Description: } run "${_HOSTS}" search disabled - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[2]}" == "" ]] @@ -115,8 +115,8 @@ Description: } run "${_HOSTS}" search example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -128,8 +128,8 @@ Description: } run "${_HOSTS}" search example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "0.0.0.0 example.com" ]] [[ "${lines[1]}" == "127.0.0.1 example.com" ]] [[ "${lines[2]}" == "" ]] @@ -144,8 +144,8 @@ Description: @test "\`help search\` prints help information." { run "${_HOSTS}" help search - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts search " ]] } diff --git a/test/show.bats b/test/show.bats index 0936912..15bc2bd 100644 --- a/test/show.bats +++ b/test/show.bats @@ -6,15 +6,15 @@ load test_helper @test "\`show\` with no arguments exits with status 1." { run "${_HOSTS}" show - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @test "\`show\` with no arguments prints help information." { run "${_HOSTS}" show - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts show ( | | )" ]] } @@ -30,8 +30,8 @@ load test_helper } run "${_HOSTS}" show 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -44,8 +44,8 @@ load test_helper } run "${_HOSTS}" show 0.0.0.0 - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "0.0.0.0 example.net" ]] [[ "${lines[1]}" == "disabled: 0.0.0.0 example.com" ]] @@ -62,8 +62,8 @@ load test_helper } run "${_HOSTS}" show example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -76,8 +76,8 @@ load test_helper } run "${_HOSTS}" show example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "127.0.0.2 example.com" ]] [[ "${lines[1]}" == "disabled: 0.0.0.0 example.com" ]] @@ -92,8 +92,8 @@ load test_helper @test "\`help show\` prints help information." { run "${_HOSTS}" help show - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts show ( | | )" ]] } diff --git a/test/test_helper.bash b/test/test_helper.bash index ab09246..d69154e 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -40,6 +40,6 @@ teardown() { _compare() { local _expected="${1:-}" local _actual="${2:-}" - printf "expected:\n%s\n" "${_expected}" - printf "actual:\n%s\n" "${_actual}" + printf "expected:\\n%s\\n" "${_expected}" + printf "actual:\\n%s\\n" "${_actual}" } diff --git a/test/unblock.bats b/test/unblock.bats index a179ef9..00cbb85 100644 --- a/test/unblock.bats +++ b/test/unblock.bats @@ -6,8 +6,8 @@ load test_helper @test "\`unblock\` with no arguments exits with status 1." { run "${_HOSTS}" unblock - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -15,15 +15,15 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" unblock - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]] } @test "\`unblock\` with no arguments prints help information." { run "${_HOSTS}" unblock - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts unblock " ]] } @@ -36,8 +36,8 @@ load test_helper } run "${_HOSTS}" unblock example.net - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 1 ]] } @@ -47,8 +47,8 @@ load test_helper } run "${_HOSTS}" unblock example.net - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${output} == "No matching records found." ]] } @@ -62,8 +62,8 @@ load test_helper } run "${_HOSTS}" unblock example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ ${status} -eq 0 ]] } @@ -76,8 +76,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" unblock example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _compare "${_original}" "$(cat "${HOSTS_PATH}")" [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]] @@ -93,8 +93,8 @@ load test_helper _original="$(cat "${HOSTS_PATH}")" run "${_HOSTS}" unblock example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _expected="\ ## # Host Database @@ -121,8 +121,8 @@ fe80::1%lo0 localhost } run "${_HOSTS}" unblock example.com - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" _expected="\ Removed: 127.0.0.1 example.com @@ -142,8 +142,8 @@ Removed: @test "\`help unblock\` prints help information." { run "${_HOSTS}" help unblock - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts unblock " ]] } diff --git a/test/version.bats b/test/version.bats index 1b838bc..e44d434 100644 --- a/test/version.bats +++ b/test/version.bats @@ -33,8 +33,8 @@ load test_helper @test "\`help version\` prints help information." { run "${_HOSTS}" help version - printf "\${status}: %s\n" "${status}" - printf "\${output}: '%s'\n" "${output}" + printf "\${status}: %s\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts (version | --version)" ]] }