diff --git a/hosts b/hosts index 80f4c87..b98f89e 100755 --- a/hosts +++ b/hosts @@ -77,7 +77,7 @@ _debug() { then # Prefix debug message with "bug (U+1F41B)" printf "🐛 " - "$@" + "${@}" printf "――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\n" fi } @@ -90,7 +90,7 @@ _debug() { # # This is a shortcut for the _debug() function that simply echos the message. debug() { - _debug echo "$@" + _debug echo "${@}" } ############################################################################### @@ -108,7 +108,7 @@ debug() { _die() { # Prefix die message with "cross mark (U+274C)", often displayed as a red x. printf "❌ " - "$@" 1>&2 + "${@}" 1>&2 exit 1 } # die() @@ -120,7 +120,7 @@ _die() { # # This is a shortcut for the _die() function that simply echos the message. die() { - _die echo "$@" + _die echo "${@}" } ############################################################################### @@ -128,7 +128,7 @@ die() { ############################################################################### # Get raw options for any commands that expect them. -_RAW_OPTIONS="$*" +_RAW_OPTIONS="${*}" # Steps: # @@ -166,9 +166,9 @@ optstring=h # argument to the option, such as wget -qO-) unset options # while the number of arguments is greater than 0 -while (($#)) +while ((${#})) do - case $1 in + case ${1} in # if option is of type -ab -[!-]?*) # loop over each character starting with the second @@ -177,11 +177,11 @@ do # extract 1 character from position 'i' c=${1:i:1} # add current char to options - options+=("-$c") + options+=("-${c}") # if option takes a required argument, and it's not the last char # make the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]] + if [[ ${optstring} = *"${c}:"* && ${1:i+1} ]] then options+=("${1:i+1}") break @@ -196,12 +196,12 @@ do --) options+=(--endopts) shift - options+=("$@") + options+=("${@}") break ;; # otherwise, nothing special *) - options+=("$1") + options+=("${1}") ;; esac @@ -219,17 +219,17 @@ unset options # command. This is essentially the same as the program arguments, minus those # that have been filtered out in the program option parsing loop. This array # is initialized with $0, which is the program's name. -_COMMAND_ARGV=("$0") +_COMMAND_ARGV=("${0}") # Initialize $_CMD and `$_USE_DEBUG`, which can continue to be blank depending # on what the program needs. _CMD="" _USE_DEBUG=0 -while [ $# -gt 0 ] +while [ ${#} -gt 0 ] do - opt="$1" + opt="${1}" shift - case "$opt" in + case "${opt}" in -h|--help) _CMD="help" ;; @@ -242,11 +242,11 @@ do *) # The first non-option argument is assumed to be the command name. # All subsequent arguments are added to $_COMMAND_ARGV. - if [[ -n $_CMD ]] + if [[ -n ${_CMD} ]] then - _COMMAND_ARGV+=("$opt") + _COMMAND_ARGV+=("${opt}") else - _CMD="$opt" + _CMD="${opt}" fi ;; esac @@ -263,10 +263,18 @@ done _COMMAND_PARAMETERS=(${_COMMAND_ARGV[*]}) unset _COMMAND_PARAMETERS[0] -_debug printf "\$_CMD: %s\n" "$_CMD" -_debug printf "\$_RAW_OPTIONS (one per line):\n%s\n" "$_RAW_OPTIONS" -_debug printf "\$_COMMAND_ARGV: %s\n" "${_COMMAND_ARGV[*]}" -_debug printf "\$_COMMAND_PARAMETERS: %s\n" "${_COMMAND_PARAMETERS[*]:-}" +_debug printf \ + "\${_CMD}: %s\n" \ + "${_CMD}" +_debug printf \ + "\${_RAW_OPTIONS} (one per line):\n%s\n" \ + "${_RAW_OPTIONS}" +_debug printf \ + "\${_COMMAND_ARGV[*]}: %s\n" \ + "${_COMMAND_ARGV[*]}" +_debug printf \ + "\${_COMMAND_PARAMETERS[*]:-}: %s\n" \ + "${_COMMAND_PARAMETERS[*]:-}" ############################################################################### # Environment @@ -275,9 +283,9 @@ _debug printf "\$_COMMAND_PARAMETERS: %s\n" "${_COMMAND_PARAMETERS[*]:-}" # $_ME # # 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 @@ -308,25 +316,25 @@ _load_commands() { # Each element has the format `declare -f function_name`, so set the name # to only the 'function_name' part of the string. 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 # with an underscore or is one of the desc(), debug(), or die() functions, # since these are treated as having 'private' visibility. - if ! ( [[ "$function_name" =~ ^_(.*) ]] || \ - [[ "$function_name" == "desc" ]] || \ - [[ "$function_name" == "debug" ]] || \ - [[ "$function_name" == "die" ]] + if ! ( [[ "${function_name}" =~ ^_(.*) ]] || \ + [[ "${function_name}" == "desc" ]] || \ + [[ "${function_name}" == "debug" ]] || \ + [[ "${function_name}" == "die" ]] ) then - _DEFINED_COMMANDS+=("$function_name") + _DEFINED_COMMANDS+=("${function_name}") fi done _debug printf \ - "commands() \$_DEFINED_COMMANDS:\n%s\n" \ + "commands() \${_DEFINED_COMMANDS[*]:-}:\n%s\n" \ "${_DEFINED_COMMANDS[*]:-}" } @@ -344,24 +352,24 @@ _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() \${_CMD} (upon entering): %s\n" "${_CMD}" # If $_CMD is blank, then set to `$DEFAULT_COMMAND` - if [[ -z $_CMD ]] + if [[ -z ${_CMD} ]] then - _CMD="$DEFAULT_COMMAND" + _CMD="${DEFAULT_COMMAND}" fi # Load all of the commands. _load_commands # If the command is defined, run it, otherwise return an error. - if _contains "$_CMD" "${_DEFINED_COMMANDS[*]:-}" + if _contains "${_CMD}" "${_DEFINED_COMMANDS[*]:-}" then # Pass all comment arguments to the program except for the first ($0). - $_CMD "${_COMMAND_PARAMETERS[@]:-}" + ${_CMD} "${_COMMAND_PARAMETERS[@]:-}" else - _die printf "Unknown command: %s\n" "$_CMD" + _die printf "Unknown command: %s\n" "${_CMD}" fi } @@ -377,7 +385,7 @@ _main() { # Takes a potential function name as an argument and returns whether a function # exists with that name. _function_exists() { - [ "$(type -t "$1")" == 'function' ] + [ "$(type -t "${1}")" == 'function' ] } # _command_exists() @@ -391,7 +399,7 @@ _function_exists() { # For information on why `hash` is used here, see: # http://stackoverflow.com/a/677212 _command_exists() { - hash "$1" 2>/dev/null + hash "${1}" 2>/dev/null } # _contains() @@ -404,10 +412,10 @@ _contains() { local test_list=(${*:2}) for _test_element in "${test_list[@]:-}" do - _debug printf "_contains() \$_test_element: %s\n" "$_test_element" - if [[ "$_test_element" == "$1" ]] + _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 @@ -427,7 +435,7 @@ _join() { local target_array local dirty local clean - separator="$1" + separator="${1}" target_array=(${@:2}) dirty="$(printf "${separator}%s" "${target_array[@]}")" clean="${dirty:${#separator}}" @@ -445,7 +453,7 @@ _join() { # This is a shortcut for simple cases where a command wants to check for the # presence of options quickly without parsing the options again. _command_argv_includes() { - _contains "$1" "${_COMMAND_ARGV[*]}" + _contains "${1}" "${_COMMAND_ARGV[*]}" } # _blank() @@ -512,16 +520,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 -d '' "_desc_$1" <] + ${_ME} help [] Description: - Display help information for $_ME or a specified command. + Display help information for ${_ME} or a specified command. EOM help() { if [[ ${#_COMMAND_ARGV[@]} = 1 ]] @@ -583,34 +591,34 @@ help() { A program for managing host file entries. -Version: $_VERSION +Version: ${_VERSION} Usage: - $_ME - $_ME add [] - $_ME disable ( | | ) - $_ME disabled - $_ME edit - $_ME enable ( | | ) - $_ME enabled - $_ME file - $_ME list [enabled | disabled | ] - $_ME show ( | | ) - $_ME remove ( | | ) [--force] - $_ME -h | --help - $_ME --version + ${_ME} + ${_ME} add [] + ${_ME} disable ( | | ) + ${_ME} disabled + ${_ME} edit + ${_ME} enable ( | | ) + ${_ME} enabled + ${_ME} file + ${_ME} list [enabled | disabled | ] + ${_ME} show ( | | ) + ${_ME} remove ( | | ) [--force] + ${_ME} -h | --help + ${_ME} --version Options: -h --help Display this help information. --version Display version information. Help: - $_ME help [] + ${_ME} help [] $(commands) EOM else - _print_desc "$1" + _print_desc "${1}" fi } @@ -618,7 +626,7 @@ EOM desc "commands" < [] + ${_ME} add [] Description: Add a given IP address and hostname pair, along with an optional comment. EOM add() { - _debug printf "add() \$1: %s\n" "${1:-}" - _debug printf "add() \$2: %s\n" "${2:-}" - _debug printf "add() \$3: %s\n" "${3:-}" + _debug printf "add() \${1}: %s\n" "${1:-}" + _debug printf "add() \${2}: %s\n" "${2:-}" + _debug printf "add() \${3}: %s\n" "${3:-}" _verify_write_permissions local ip=${1:-} @@ -683,12 +691,12 @@ add() { local comment=${*:3} if [[ -z ${ip} ]] then - $_ME help add + ${_ME} help add exit 1 elif [[ -z ${hostname} ]] then printf "Please include a hostname\n" - $_ME help add + ${_ME} help add exit 1 elif grep \ -e "^${ip}\t${hostname}$" \ @@ -725,7 +733,7 @@ add() { desc "disable" < | | ) + ${_ME} disable ( | | ) Description: Disable one or more records based on a given ip address, hostname, or @@ -733,13 +741,13 @@ Description: EOM disable() { _verify_write_permissions - local search_string=$1 + local search_string="${1}" if [[ -z "${search_string}" ]] then - $_ME help 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_}]..*\)$" @@ -757,7 +765,7 @@ 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}" @@ -779,31 +787,31 @@ disable() { desc "disabled" < | | ) + ${_ME} enable ( | | ) Description: Enable one or more disabled records based on a given ip address, hostname, @@ -819,13 +827,13 @@ Description: EOM enable() { _verify_write_permissions - local search_string=$1 + local search_string="${1}" if [[ -z "${search_string}" ]] then - $_ME help 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_}]..*\)$" @@ -843,7 +851,7 @@ 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}" @@ -865,20 +873,20 @@ enable() { desc "enabled" <] + ${_ME} list [enabled | disabled | ] Description: List the existing IP / hostname pairs, optionally limited to a specified @@ -905,16 +913,16 @@ list() { sed -n "s/^\#disabled: \(.*\)$/\1/p" "${HOSTS_PATH}" ) - if [[ -n "$1" ]] + if [[ -n "${1}" ]] then - if [[ "$1" == "disabled" ]] + if [[ "${1}" == "disabled" ]] then printf "%s\n" "${disabled_records}" - elif [[ "$1" == "enabled" ]] + elif [[ "${1}" == "enabled" ]] then grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}" else - $_ME show "$1" + ${_ME} show "${1}" fi else # NOTE: use separate expressions since using a | for the or results in @@ -931,8 +939,8 @@ list() { desc "remove" < | | ) [--force] - $_ME remove + ${_ME} remove ( | | ) [--force] + ${_ME} remove Options: --force Skip the confirmation prompt. @@ -951,17 +959,17 @@ 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 - case $arg in + case ${arg} in --force) force_skip_prompt=1 ;; *) - arguments+=($arg) + arguments+=(${arg}) ;; esac done @@ -972,17 +980,17 @@ remove() { if [[ -z "${arguments[1]:-}" ]] then - $_ME help remove + ${_ME} help remove exit 1 elif [[ -n "${arguments[2]:-}" ]] then 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 @@ -1026,11 +1034,11 @@ remove() { 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 -p "Are you sure you want to proceed? [y/N] " yn - case $yn in + case ${yn} in [Yy]* ) break ;; @@ -1066,34 +1074,34 @@ remove() { desc "show" < | | ) + ${_ME} show ( | | ) Description: Print entries matching a given IP address, hostname, or search string. EOM show() { - if [[ -n "$1" ]] + if [[ -n "${1}" ]] then # Run `sed` before `grep` to avoid conflict that supress `sed` output. local disabled_records disabled_records=$( - sed -n "s/^\#\(disabled: .*$1.*\)$/\1/p" "${HOSTS_PATH}" + sed -n "s/^\#\(disabled: .*${1}.*\)$/\1/p" "${HOSTS_PATH}" ) local enabled_records enabled_records=$( - grep "^[^#]*$1" "${HOSTS_PATH}" + grep "^[^#]*${1}" "${HOSTS_PATH}" ) # Output disabled records secondly for better organization. - if [[ -n "$enabled_records" ]] + if [[ -n "${enabled_records}" ]] then - printf "%s\n" "$enabled_records" + printf "%s\n" "${enabled_records}" fi - if [[ -n "$disabled_records" ]] + if [[ -n "${disabled_records}" ]] then - printf "%s\n" "$disabled_records" + printf "%s\n" "${disabled_records}" fi else - $_ME help show + ${_ME} help show exit 1 fi } diff --git a/test/add.bats b/test/add.bats index 71732d0..c9bb457 100644 --- a/test/add.bats +++ b/test/add.bats @@ -5,25 +5,25 @@ load test_helper # `hosts add` ################################################################# @test "\`add\` with no arguments exits with status 1." { - run "$_HOSTS" add - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 1 ]] + run "${_HOSTS}" add + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 1 ]] } @test "\`add\` with no argument does not change the hosts file." { _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" add - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" add + 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" + run "${_HOSTS}" add + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts add []" ]] } @@ -31,25 +31,25 @@ load test_helper # `hosts add ` ############################################################ @test "\`add \` exits with status 1." { - run "$_HOSTS" add 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 1 ]] + run "${_HOSTS}" add 0.0.0.0 + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 1 ]] } @test "\`add \` does not change the hosts file." { _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" add 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" add 0.0.0.0 + 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" + run "${_HOSTS}" add 0.0.0.0 + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Please include a hostname" ]] [[ "${lines[1]}" == "Usage:" ]] [[ "${lines[2]}" == " hosts add []" ]] @@ -58,18 +58,18 @@ load test_helper # `hosts add ` ################################################# @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" - [[ $status -eq 0 ]] + run "${_HOSTS}" add 0.0.0.0 example.com + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`add \` adds the entry to the hosts file." { _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" add 0.0.0.0 example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" add 0.0.0.0 example.com + 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}" ]] @@ -77,9 +77,9 @@ 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" + run "${_HOSTS}" add 0.0.0.0 example.com + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Added:" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]] } @@ -87,26 +87,26 @@ load test_helper # `hosts add [comment]` ####################################### @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" - [[ $status -eq 0 ]] + run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`add [comment]\` adds the entry to the hosts file." { _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" add 0.0.0.0 example.com 'Comment.' - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' + 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" + run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Added:" ]] [[ "${lines[1]}" == "0.0.0.0 example.com # Comment." ]] } @@ -114,14 +114,14 @@ load test_helper # help ######################################################################## @test "\`help add\` exits with status 0." { - run "$_HOSTS" help add - [[ $status -eq 0 ]] + run "${_HOSTS}" help add + [[ ${status} -eq 0 ]] } @test "\`help add\` prints help information." { - run "$_HOSTS" help add - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help add + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts add []" ]] } diff --git a/test/disable.bats b/test/disable.bats index 6216f71..f496e0a 100644 --- a/test/disable.bats +++ b/test/disable.bats @@ -5,25 +5,25 @@ load test_helper # `hosts disable` ############################################################# @test "\`disable\` with no arguments exits with status 1." { - run "$_HOSTS" disable - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 1 ]] + run "${_HOSTS}" disable + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 1 ]] } @test "\`disable\` with no argument does not change the hosts file." { _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" disable - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" disable + 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" + run "${_HOSTS}" disable + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts disable ( | | )" ]] } @@ -32,26 +32,26 @@ load test_helper @test "\`disable \` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 127.0.0.1 example.net + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 127.0.0.1 example.net } - run "$_HOSTS" disable 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" disable 0.0.0.0 + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`disable \` updates the hosts file." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 127.0.0.1 example.net + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 127.0.0.1 example.net } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" disable 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" disable 0.0.0.0 + 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" ]] @@ -59,14 +59,14 @@ load test_helper @test "\`disable \` disables all matches." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" disable 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" disable 0.0.0.0 + 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,13 +74,13 @@ load test_helper @test "\`disable \` prints feedback." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 127.0.0.1 example.net + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 127.0.0.1 example.net } - run "$_HOSTS" disable 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" disable 0.0.0.0 + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Disabling:" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]] } @@ -89,26 +89,26 @@ load test_helper @test "\`disable \` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 127.0.0.1 example.net + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 127.0.0.1 example.net } - run "$_HOSTS" disable example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" disable example.com + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`disable \` updates the hosts file." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 127.0.0.1 example.net + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 127.0.0.1 example.net } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" disable example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" disable example.com + 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" ]] @@ -116,14 +116,14 @@ load test_helper @test "\`disable \` disables all matches." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 127.0.0.1 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 127.0.0.1 example.com } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" disable example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" disable example.com + 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" ]] @@ -131,13 +131,13 @@ load test_helper @test "\`disable \` prints feedback." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 127.0.0.1 example.net + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 127.0.0.1 example.net } - run "$_HOSTS" disable example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" disable example.com + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Disabling:" ]] [[ "${lines[1]}" == "0.0.0.0 example.com" ]] } @@ -145,14 +145,14 @@ load test_helper # help ######################################################################## @test "\`help disable\` exits with status 0." { - run "$_HOSTS" help disable - [[ $status -eq 0 ]] + run "${_HOSTS}" help disable + [[ ${status} -eq 0 ]] } @test "\`help disable\` prints help information." { - run "$_HOSTS" help disable - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help disable + 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 54a0e5f..8147d1a 100644 --- a/test/disabled.bats +++ b/test/disabled.bats @@ -6,29 +6,29 @@ load test_helper @test "\`disabled\` with no arguments exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.1 example.com - run "$_HOSTS" disable example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.1 example.com + run "${_HOSTS}" disable example.com } - run "$_HOSTS" disabled - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" disabled + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`disabled\` with no arguments prints list of disabled records." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.1 example.com - run "$_HOSTS" disable example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.1 example.com + run "${_HOSTS}" disable example.com } - run "$_HOSTS" disabled - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" disabled + 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]}" == "" ]] @@ -37,14 +37,14 @@ load test_helper # help ######################################################################## @test "\`help disabled\` exits with status 0." { - run "$_HOSTS" help disabled - [[ $status -eq 0 ]] + run "${_HOSTS}" help disabled + [[ ${status} -eq 0 ]] } @test "\`help disabled\` prints help information." { - run "$_HOSTS" help disabled - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help disabled + 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 77c76b5..157546b 100644 --- a/test/enable.bats +++ b/test/enable.bats @@ -5,25 +5,25 @@ load test_helper # `hosts enable` ############################################################## @test "\`enable\` with no arguments exits with status 1." { - run "$_HOSTS" enable - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 1 ]] + run "${_HOSTS}" enable + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 1 ]] } @test "\`enable\` with no argument does not change the hosts file." { _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" enable - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" enable + 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" + run "${_HOSTS}" enable + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts enable ( | | )" ]] } @@ -32,31 +32,31 @@ load test_helper @test "\`enable \` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 127.0.0.2 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 127.0.0.2 } - run "$_HOSTS" enable 127.0.0.2 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" enable 127.0.0.2 + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`enable \` updates the hosts file." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 - run "$_HOSTS" disable 127.0.0.2 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 + run "${_HOSTS}" disable 127.0.0.2 } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" enable 127.0.0.2 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" enable 127.0.0.2 + 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" ]] @@ -65,17 +65,17 @@ load test_helper @test "\`enable \` enables all matches." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 - run "$_HOSTS" disable 127.0.0.2 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 + run "${_HOSTS}" disable 127.0.0.2 } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" enable 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" enable 0.0.0.0 + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" _compare \ "${_original}" \ "$(cat "${HOSTS_PATH}")" @@ -96,15 +96,15 @@ load test_helper @test "\`disable \` prints feedback." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 127.0.0.2 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 127.0.0.2 } - run "$_HOSTS" enable 127.0.0.2 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" enable 127.0.0.2 + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Enabling:" ]] [[ "${lines[1]}" == "127.0.0.2 example.com" ]] } @@ -113,30 +113,30 @@ load test_helper @test "\`enable \` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 } - run "$_HOSTS" enable example.net - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" enable example.net + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`enable \` updates the hosts file." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" enable example.net - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" enable example.net + 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" ]] @@ -145,17 +145,17 @@ load test_helper @test "\`enable \` enables all matches." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 - run "$_HOSTS" disable 127.0.0.2 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 + run "${_HOSTS}" disable 127.0.0.2 } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" enable example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" enable example.com + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" _compare \ "${_original}" \ "$(cat "${HOSTS_PATH}")" @@ -176,15 +176,15 @@ load test_helper @test "\`disable \` prints feedback." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 } - run "$_HOSTS" enable example.net - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" enable example.net + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Enabling:" ]] [[ "${lines[1]}" == "0.0.0.0 example.net" ]] } @@ -192,14 +192,14 @@ load test_helper # help ######################################################################## @test "\`help enable\` exits with status 0." { - run "$_HOSTS" help enable - [[ $status -eq 0 ]] + run "${_HOSTS}" help enable + [[ ${status} -eq 0 ]] } @test "\`help enable\` prints help information." { - run "$_HOSTS" help enable - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help enable + 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 8d50741..2a0f039 100644 --- a/test/enabled.bats +++ b/test/enabled.bats @@ -6,29 +6,29 @@ load test_helper @test "\`enabled\` with no arguments exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 } - run "$_HOSTS" enabled - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" enabled + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`enabled\` with no arguments prints list of enabled records." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 } - run "$_HOSTS" enabled - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" enabled + 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" ]] @@ -39,14 +39,14 @@ load test_helper # help ######################################################################## @test "\`help enabled\` exits with status 0." { - run "$_HOSTS" help enabled - [[ $status -eq 0 ]] + run "${_HOSTS}" help enabled + [[ ${status} -eq 0 ]] } @test "\`help enabled\` prints help information." { - run "$_HOSTS" help enabled - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help enabled + 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 b907112..e08a3fd 100644 --- a/test/file.bats +++ b/test/file.bats @@ -3,26 +3,26 @@ load test_helper @test "\`file\` exits with status 0." { - run "$_HOSTS" file - [ "$status" -eq 0 ] + run "${_HOSTS}" file + [ "${status}" -eq 0 ] } @test "\`file\` prints \$HOSTS_PATH contents." { - run "$_HOSTS" file - [[ "$output" == "$(cat $HOSTS_PATH)" ]] + run "${_HOSTS}" file + [[ "${output}" == "$(cat ${HOSTS_PATH})" ]] } # help ######################################################################## @test "\`help file\` exits with status 0." { - run "$_HOSTS" help file - [[ $status -eq 0 ]] + run "${_HOSTS}" help file + [[ ${status} -eq 0 ]] } @test "\`help file\` prints help information." { - run "$_HOSTS" help file - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help file + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts file" ]] } diff --git a/test/help.bats b/test/help.bats index e12bcf4..bcf17da 100644 --- a/test/help.bats +++ b/test/help.bats @@ -14,27 +14,27 @@ HEREDOC export _HELP_HEADER @test "\`help\` with no arguments exits with status 0." { - run "$_HOSTS" help - [ "$status" -eq 0 ] + run "${_HOSTS}" help + [ "${status}" -eq 0 ] } @test "\`help\` with no arguments prints default help." { - run "$_HOSTS" help - [[ $(IFS=$'\n'; echo "${lines[*]:0:5}") == "$_HELP_HEADER" ]] + run "${_HOSTS}" help + [[ $(IFS=$'\n'; echo "${lines[*]:0:5}") == "${_HELP_HEADER}" ]] } @test "\`hosts -h\` prints default help." { - run "$_HOSTS" -h - [[ $(IFS=$'\n'; echo "${lines[*]:0:5}") == "$_HELP_HEADER" ]] + run "${_HOSTS}" -h + [[ $(IFS=$'\n'; echo "${lines[*]:0:5}") == "${_HELP_HEADER}" ]] } @test "\`hosts --help\` prints default help." { - run "$_HOSTS" --help - [[ $(IFS=$'\n'; echo "${lines[*]:0:5}") == "$_HELP_HEADER" ]] + run "${_HOSTS}" --help + [[ $(IFS=$'\n'; echo "${lines[*]:0:5}") == "${_HELP_HEADER}" ]] } @test "\`hosts help help\` prints \`help\` subcommand usage." { - run "$_HOSTS" help help + run "${_HOSTS}" help help _expected="$( cat <\` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.1 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.1 example.com } - run "$_HOSTS" list example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" list example.com + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`list \` prints list of matching records." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.1 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.1 example.com } - run "$_HOSTS" list example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" list example.com + 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]}" == "" ]] @@ -142,14 +142,14 @@ Disabled: # help ######################################################################## @test "\`help list\` exits with status 0." { - run "$_HOSTS" help list - [[ $status -eq 0 ]] + run "${_HOSTS}" help list + [[ ${status} -eq 0 ]] } @test "\`help list\` prints help information." { - run "$_HOSTS" help list - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help list + 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 d7f2488..8d380b8 100644 --- a/test/remove.bats +++ b/test/remove.bats @@ -5,25 +5,25 @@ load test_helper # `hosts remove` ################################################################# @test "\`remove\` with no arguments exits with status 1." { - run "$_HOSTS" remove - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 1 ]] + run "${_HOSTS}" remove + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 1 ]] } @test "\`remove\` with no argument does not change the hosts file." { _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" remove - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" remove + 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" + run "${_HOSTS}" remove + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts remove ( | | ) [--force]" ]] } @@ -32,56 +32,56 @@ load test_helper @test "\`remove --force\` exits with status 1." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com } - run "$_HOSTS" remove 127.0.0.3 --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 1 ]] + run "${_HOSTS}" remove 127.0.0.3 --force + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 1 ]] } @test "\`remove --force\` prints error message." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com } - run "$_HOSTS" remove 127.0.0.3 --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $output == "No matching records found." ]] + run "${_HOSTS}" remove 127.0.0.3 --force + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${output} == "No matching records found." ]] } # `hosts remove --force` ################################################# @test "\`remove --force\` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com } - run "$_HOSTS" remove 127.0.0.2 --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" remove 127.0.0.2 --force + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`remove --force\` updates the hosts file." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" remove 127.0.0.2 --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" remove 127.0.0.2 --force + 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" ]] @@ -90,17 +90,17 @@ load test_helper @test "\`remove \` removes all matches." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 0.0.0.0 example.dev - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable example.dev + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 0.0.0.0 example.dev + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable example.dev } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" remove 0.0.0.0 --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" remove 0.0.0.0 --force + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" _expected="\ ## # Host Database @@ -113,21 +113,21 @@ load test_helper ::1 localhost fe80::1%lo0 localhost 127.0.0.2 example.com" - _compare "'$_expected'" "'$(cat "${HOSTS_PATH}")'" - [[ "$(cat "${HOSTS_PATH}")" != "$_original" ]] - [[ "$(cat "${HOSTS_PATH}")" == "$_expected" ]] + _compare "'${_expected}'" "'$(cat "${HOSTS_PATH}")'" + [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] + [[ "$(cat "${HOSTS_PATH}")" == "${_expected}" ]] } @test "\`remove \` prints feedback." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com } - run "$_HOSTS" remove 127.0.0.2 --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" remove 127.0.0.2 --force + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Removed:" ]] [[ "${lines[1]}" == "127.0.0.2 example.com" ]] } @@ -136,28 +136,28 @@ fe80::1%lo0 localhost @test "\`remove --force\` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com } - run "$_HOSTS" remove example.com --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" remove example.com --force + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`remove --force\` updates the hosts file." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" remove example.com --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" remove example.com --force + 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}")" == "" ]] @@ -165,17 +165,17 @@ fe80::1%lo0 localhost @test "\`remove \` removes all matches." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 0.0.0.0 example.dev - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable example.dev + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 0.0.0.0 example.dev + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable example.dev } _original="$(cat "${HOSTS_PATH}")" - run "$_HOSTS" remove example.com --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" remove example.com --force + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" _expected="\ ## # Host Database @@ -189,39 +189,39 @@ fe80::1%lo0 localhost fe80::1%lo0 localhost 0.0.0.0 example.net #disabled: 0.0.0.0 example.dev" - _compare "'$_expected'" "'$(cat "${HOSTS_PATH}")'" - [[ "$(cat "${HOSTS_PATH}")" != "$_original" ]] - [[ "$(cat "${HOSTS_PATH}")" == "$_expected" ]] + _compare "'${_expected}'" "'$(cat "${HOSTS_PATH}")'" + [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] + [[ "$(cat "${HOSTS_PATH}")" == "${_expected}" ]] } @test "\`remove \` prints feedback." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com } - run "$_HOSTS" remove example.com --force - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" remove example.com --force + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" _expected="\ Removed: 0.0.0.0 example.com 127.0.0.2 example.com" - [[ "$output" == "$_expected" ]] + [[ "${output}" == "${_expected}" ]] } # help ######################################################################## @test "\`help remove\` exits with status 0." { - run "$_HOSTS" help remove - [[ $status -eq 0 ]] + run "${_HOSTS}" help remove + [[ ${status} -eq 0 ]] } @test "\`help remove\` prints help information." { - run "$_HOSTS" help remove - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help remove + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts remove ( | | ) [--force]" ]] } diff --git a/test/show.bats b/test/show.bats index 937e4c2..0936912 100644 --- a/test/show.bats +++ b/test/show.bats @@ -5,16 +5,16 @@ load test_helper # `hosts show` ############################################################## @test "\`show\` with no arguments exits with status 1." { - run "$_HOSTS" show - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 1 ]] + run "${_HOSTS}" show + 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" + run "${_HOSTS}" show + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts show ( | | )" ]] } @@ -23,29 +23,29 @@ load test_helper @test "\`show \` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable example.com } - run "$_HOSTS" show 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" show 0.0.0.0 + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`enable \` shows all matches." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable example.com + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable example.com } - run "$_HOSTS" show 0.0.0.0 - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" show 0.0.0.0 + 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" ]] @@ -55,29 +55,29 @@ load test_helper @test "\`show \` exits with status 0." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 } - run "$_HOSTS" show example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" - [[ $status -eq 0 ]] + run "${_HOSTS}" show example.com + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" + [[ ${status} -eq 0 ]] } @test "\`enable \` shows all matches." { { - run "$_HOSTS" add 0.0.0.0 example.com - run "$_HOSTS" add 0.0.0.0 example.net - run "$_HOSTS" add 127.0.0.2 example.com - run "$_HOSTS" disable 0.0.0.0 + run "${_HOSTS}" add 0.0.0.0 example.com + run "${_HOSTS}" add 0.0.0.0 example.net + run "${_HOSTS}" add 127.0.0.2 example.com + run "${_HOSTS}" disable 0.0.0.0 } - run "$_HOSTS" show example.com - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" show example.com + 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" ]] @@ -86,14 +86,14 @@ load test_helper # help ######################################################################## @test "\`help show\` exits with status 0." { - run "$_HOSTS" help show - [[ $status -eq 0 ]] + run "${_HOSTS}" help show + [[ ${status} -eq 0 ]] } @test "\`help show\` prints help information." { - run "$_HOSTS" help show - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help show + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts show ( | | )" ]] } diff --git a/test/version.bats b/test/version.bats index ad14e4f..1b838bc 100644 --- a/test/version.bats +++ b/test/version.bats @@ -3,38 +3,38 @@ load test_helper @test "\`hosts version\` returns with 0 status." { - run "$_HOSTS" version - [[ "$status" -eq 0 ]] + run "${_HOSTS}" version + [[ "${status}" -eq 0 ]] } @test "\`hosts version\` prints a version number." { - run "$_HOSTS" version - printf "'%s'" "$output" - echo "$output" | grep -q '\d\+\.\d\+\.\d\+' + run "${_HOSTS}" version + printf "'%s'" "${output}" + echo "${output}" | grep -q '\d\+\.\d\+\.\d\+' } @test "\`hosts --version\` returns with 0 status." { - run "$_HOSTS" --version - [[ "$status" -eq 0 ]] + run "${_HOSTS}" --version + [[ "${status}" -eq 0 ]] } @test "\`hosts --version\` prints a version number." { - run "$_HOSTS" --version - printf "'%s'" "$output" - echo "$output" | grep -q '\d\+\.\d\+\.\d\+' + run "${_HOSTS}" --version + printf "'%s'" "${output}" + echo "${output}" | grep -q '\d\+\.\d\+\.\d\+' } # help ######################################################################## @test "\`help version\` exits with status 0." { - run "$_HOSTS" help version - [[ $status -eq 0 ]] + run "${_HOSTS}" help version + [[ ${status} -eq 0 ]] } @test "\`help version\` prints help information." { - run "$_HOSTS" help version - printf "\$status: %s\n" "$status" - printf "\$output: '%s'\n" "$output" + run "${_HOSTS}" help version + printf "\${status}: %s\n" "${status}" + printf "\${output}: '%s'\n" "${output}" [[ "${lines[0]}" == "Usage:" ]] [[ "${lines[1]}" == " hosts (version | --version)" ]] }