From 5d9f876b132c2bd94493c4f9bbb41aef9fbc7bcc Mon Sep 17 00:00:00 2001 From: William Melody Date: Wed, 8 Apr 2020 17:27:11 -0700 Subject: [PATCH] Improve `add` formatting. --- hosts | 22 ++++++++++++++++------ test/add.bats | 20 ++++++++++---------- test/backups.bats | 2 +- test/block.bats | 24 ++++++++++++------------ test/disable.bats | 20 ++++++++++---------- test/enable.bats | 28 ++++++++++++++-------------- test/remove.bats | 14 +++++++------- test/unblock.bats | 14 +++++++------- 8 files changed, 77 insertions(+), 67 deletions(-) diff --git a/hosts b/hosts index d4aa807..13a29ae 100755 --- a/hosts +++ b/hosts @@ -775,6 +775,7 @@ add() { local _ip="${1:-}" local _hostname="${2:-}" local _comment="${*:3}" + local _tabs=$'\t' if [[ -z "${_ip:-}" ]] then @@ -786,32 +787,41 @@ add() { help add exit 1 elif grep \ - -e "^${_ip}\\t${_hostname}$" \ - -e "^${_ip}\\t${_hostname}\\t.*$" "${HOSTS_PATH}" + -e "^${_ip}[[:space:]]\+${_hostname}$" \ + -e "^${_ip}[[:space:]]\+${_hostname}\\t.*$" "${HOSTS_PATH}" then _die printf \ "Duplicate address/host combination, %s unchanged.\\n" \ "${HOSTS_PATH}" else + if [[ "${#_ip}" -lt 8 ]] + then + _tabs=$'\t\t' + fi + if [[ -n "${_comment:-}" ]] then local _formatted_comment _formatted_comment=$(_join " " "${_comment[@]}") - printf "%s\\t%s\\t# %s\\n" \ + printf "%s%s%s\\t# %s\\n" \ "${_ip}" \ + "${_tabs}" \ "${_hostname}" \ "${_formatted_comment}" >> "${HOSTS_PATH}" - printf "Added:\\n%s\\t%s\\t# %s\\n" \ + printf "Added:\\n%s%s%s\\t# %s\\n" \ "${_ip}" \ + "${_tabs}" \ "${_hostname}" \ "${_formatted_comment}" else - printf "%s\\t%s\\n" \ + printf "%s%s%s\\n" \ "${_ip}" \ + "${_tabs}" \ "${_hostname}" >> "${HOSTS_PATH}" - printf "Added:\\n%s\\t%s\\n" \ + printf "Added:\\n%s%s%s\\n" \ "${_ip}" \ + "${_tabs}" \ "${_hostname}" fi fi diff --git a/test/add.bats b/test/add.bats index 506a8e9..e929a9e 100644 --- a/test/add.bats +++ b/test/add.bats @@ -73,7 +73,7 @@ load test_helper _compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] - [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] } @test "\`add \` prints feedback." { @@ -81,7 +81,7 @@ load test_helper printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Added:" ]] - [[ "${lines[1]}" == "0.0.0.0 example.com" ]] + [[ "${lines[1]}" == "0.0.0.0 example.com" ]] } @test "\`add \` doesn't add duplicate entry." { @@ -95,10 +95,10 @@ load test_helper 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}")" + _compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_modified}" ]] - [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] } # `hosts add [comment]` ####################################### @@ -118,7 +118,7 @@ load test_helper printf "\${output}: '%s'\\n" "${output}" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == \ - "0.0.0.0 example.com # Example multi-word comment." ]] + "0.0.0.0 example.com # Example multi-word comment." ]] } @test "\`add [comment]\` doesn't add duplicate entry." { @@ -135,9 +135,9 @@ load test_helper _compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_modified}" ]] - [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" != \ - "0.0.0.0 example.com # Example multi-word comment." ]] + "0.0.0.0 example.com # Example multi-word comment." ]] } @test "\`add [comment]\` doesn't add duplicate commented entry." { @@ -151,11 +151,11 @@ load test_helper 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}")" + _compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" == "${_modified}" ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == \ - "0.0.0.0 example.com # Example multi-word comment." ]] + "0.0.0.0 example.com # Example multi-word comment." ]] } @test "\`add [comment]\` prints feedback." { @@ -163,7 +163,7 @@ load test_helper printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Added:" ]] - [[ "${lines[1]}" == "0.0.0.0 example.com # Example multi-word comment." ]] + [[ "${lines[1]}" == "0.0.0.0 example.com # Example multi-word comment." ]] } # help ######################################################################## diff --git a/test/backups.bats b/test/backups.bats index d4430ac..9e9dff5 100755 --- a/test/backups.bats +++ b/test/backups.bats @@ -87,7 +87,7 @@ No backups found. Create a new backup: printf "\${output}: '%s'\\n" "${output}" printf "\${lines[1]}: '%s'\\n" "${lines[1]}" [[ ${status} -eq 1 ]] - [[ "${lines[1]}" == '< 0.0.0.0 example.com' ]] + [[ "${lines[1]}" =~ \<\ 0.0.0.0[[:space:]]+example.com ]] } @test "\`backups compare\` with missing backup exits with status 1" { diff --git a/test/block.bats b/test/block.bats index 9627ca5..20a2041 100644 --- a/test/block.bats +++ b/test/block.bats @@ -46,7 +46,7 @@ load test_helper _compare "${_original}" "$(cat "${HOSTS_PATH}")" _compare '127.0.0.1 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] - [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "127.0.0.1 example.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example.com ]] } @test "\`block \` prints feedback." { @@ -54,11 +54,11 @@ load test_helper printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Added:" ]] - [[ "${lines[1]}" == "127.0.0.1 example.com" ]] + [[ "${lines[1]}" =~ 127.0.0.1[[:space:]]+example.com ]] [[ "${lines[2]}" == "Added:" ]] - [[ "${lines[3]}" == "fe80::1%lo0 example.com" ]] + [[ "${lines[3]}" =~ fe80\:\:1\%lo0[[:space:]]example.com ]] [[ "${lines[4]}" == "Added:" ]] - [[ "${lines[5]}" == "::1 example.com" ]] + [[ "${lines[5]}" =~ \:\:1[[:space:]]+example.com ]] } # `hosts block ` ######################################## @@ -80,8 +80,8 @@ load test_helper _compare '127.0.0.1 example.com' "$(sed -n '11p' "${HOSTS_PATH}")" _compare '127.0.0.1 example2.com' "$(sed -n '11p' "${HOSTS_PATH}")" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] - [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "127.0.0.1 example.com" ]] - [[ "$(sed -n '14p' "${HOSTS_PATH}")" == "127.0.0.1 example2.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example.com ]] + [[ "$(sed -n '14p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example2.com ]] } @test "\`block \` prints feedback." { @@ -89,17 +89,17 @@ load test_helper printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Added:" ]] - [[ "${lines[1]}" == "127.0.0.1 example.com" ]] + [[ "${lines[1]}" =~ 127.0.0.1[[:space:]]+example.com ]] [[ "${lines[2]}" == "Added:" ]] - [[ "${lines[3]}" == "fe80::1%lo0 example.com" ]] + [[ "${lines[3]}" =~ fe80\:\:1\%lo0[[:space:]]+example.com ]] [[ "${lines[4]}" == "Added:" ]] - [[ "${lines[5]}" == "::1 example.com" ]] + [[ "${lines[5]}" =~ \:\:1[[:space:]]+example.com ]] [[ "${lines[6]}" == "Added:" ]] - [[ "${lines[7]}" == "127.0.0.1 example2.com" ]] + [[ "${lines[7]}" =~ 127.0.0.1[[:space:]]+example2.com ]] [[ "${lines[8]}" == "Added:" ]] - [[ "${lines[9]}" == "fe80::1%lo0 example2.com" ]] + [[ "${lines[9]}" =~ fe80\:\:1\%lo0[[:space:]]+example2.com ]] [[ "${lines[10]}" == "Added:" ]] - [[ "${lines[11]}" == "::1 example2.com" ]] + [[ "${lines[11]}" =~ \:\:1[[:space:]]+example2.com ]] } # help ######################################################################## diff --git a/test/disable.bats b/test/disable.bats index 2eabf30..bbefe72 100644 --- a/test/disable.bats +++ b/test/disable.bats @@ -53,8 +53,8 @@ load test_helper 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" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example.net ]] } @test "\`disable \` disables all matches." { @@ -68,8 +68,8 @@ load test_helper 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" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.net ]] } @test "\`disable \` prints feedback." { @@ -82,7 +82,7 @@ load test_helper printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Disabling:" ]] - [[ "${lines[1]}" == "0.0.0.0 example.com" ]] + [[ "${lines[1]}" =~ 0.0.0.0[[:space:]]+example.com ]] } # `hosts disable ` ################################################## @@ -110,8 +110,8 @@ load test_helper 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" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example.net ]] } @test "\`disable \` disables all matches." { @@ -125,8 +125,8 @@ load test_helper 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" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example.com ]] } @test "\`disable \` prints feedback." { @@ -139,7 +139,7 @@ load test_helper printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Disabling:" ]] - [[ "${lines[1]}" == "0.0.0.0 example.com" ]] + [[ "${lines[1]}" =~ 0.0.0.0[[:space:]]+example.com ]] } # help ######################################################################## diff --git a/test/enable.bats b/test/enable.bats index 5b6b3a2..3670c74 100644 --- a/test/enable.bats +++ b/test/enable.bats @@ -58,9 +58,9 @@ load test_helper 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" ]] - [[ "$(sed -n '13p' "${HOSTS_PATH}")" == "127.0.0.2 example.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled:\ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ \#disabled:\ 0.0.0.0[[:space:]]+example.net ]] + [[ "$(sed -n '13p' "${HOSTS_PATH}")" =~ 127.0.0.2[[:space:]]+example.com ]] } @test "\`enable \` enables all matches." { @@ -89,9 +89,9 @@ load test_helper "'#disabled: 127.0.0.2 example.com'" \ "'$(sed -n '13p' "${HOSTS_PATH}")'" - [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] - [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "0.0.0.0 example.net" ]] - [[ "$(sed -n '13p' "${HOSTS_PATH}")" == "#disabled: 127.0.0.2 example.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.net ]] + [[ "$(sed -n '13p' "${HOSTS_PATH}")" =~ \#disabled:\ 127.0.0.2[[:space:]]+example.com ]] } @test "\`enable \` prints feedback." { @@ -106,7 +106,7 @@ load test_helper printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Enabling:" ]] - [[ "${lines[1]}" == "127.0.0.2 example.com" ]] + [[ "${lines[1]}" =~ 127.0.0.2[[:space:]]+example.com ]] } # `hosts enable ` ################################################### @@ -138,9 +138,9 @@ load test_helper 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" ]] - [[ "$(sed -n '13p' "${HOSTS_PATH}")" == "127.0.0.2 example.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled:\ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.net ]] + [[ "$(sed -n '13p' "${HOSTS_PATH}")" =~ 127.0.0.2[[:space:]]+example.com ]] } @test "\`enable \` enables all matches." { @@ -169,9 +169,9 @@ load test_helper "'127.0.0.2 example.com'" \ "'$(sed -n '13p' "${HOSTS_PATH}")'" - [[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] - [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.net" ]] - [[ "$(sed -n '13p' "${HOSTS_PATH}")" == "127.0.0.2 example.com" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ \#disabled:\ 0.0.0.0[[:space:]]+example.net ]] + [[ "$(sed -n '13p' "${HOSTS_PATH}")" =~ 127.0.0.2[[:space:]]+example.com ]] } @test "\`enable \` prints feedback." { @@ -186,7 +186,7 @@ load test_helper printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Enabling:" ]] - [[ "${lines[1]}" == "0.0.0.0 example.net" ]] + [[ "${lines[1]}" =~ 0.0.0.0[[:space:]]+example.net ]] } # help ######################################################################## diff --git a/test/remove.bats b/test/remove.bats index 0290b8f..0af4f4b 100644 --- a/test/remove.bats +++ b/test/remove.bats @@ -83,8 +83,8 @@ load test_helper 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" ]] + [[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.com ]] + [[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.net ]] [[ "$(sed -n '13p' "${HOSTS_PATH}")" == "" ]] } @@ -129,7 +129,7 @@ fe80::1%lo0 localhost printf "\${status}: %s\\n" "${status}" printf "\${output}: '%s'\\n" "${output}" [[ "${lines[0]}" == "Removed:" ]] - [[ "${lines[1]}" == "127.0.0.2 example.com" ]] + [[ "${lines[1]}" =~ 127.0.0.2[[:space:]]+example.com ]] } # `hosts remove --force` ########################################### @@ -159,7 +159,7 @@ fe80::1%lo0 localhost 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 '11p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.net ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "" ]] } @@ -187,8 +187,8 @@ fe80::1%lo0 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost -0.0.0.0 example.net -#disabled: 0.0.0.0 example.dev" +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}" ]] @@ -206,7 +206,7 @@ fe80::1%lo0 localhost printf "\${output}: '%s'\\n" "${output}" _expected="\ Removed: -0.0.0.0 example.com +0.0.0.0 example.com 127.0.0.2 example.com" [[ "${output}" == "${_expected}" ]] } diff --git a/test/unblock.bats b/test/unblock.bats index 92d3b08..e829289 100644 --- a/test/unblock.bats +++ b/test/unblock.bats @@ -79,7 +79,7 @@ load test_helper 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 '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]] [[ "$(sed -n '13p' "${HOSTS_PATH}")" == "" ]] } @@ -106,7 +106,7 @@ load test_helper 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost -0.0.0.0 example.com +0.0.0.0 example.com 127.0.0.1 example.net" _compare "'${_expected}'" "'$(cat "${HOSTS_PATH}")'" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] @@ -129,7 +129,7 @@ Removed: Removed: fe80::1%lo0 example.com Removed: -::1 example.com" +::1 example.com" [[ "${output}" == "${_expected}" ]] } @@ -162,7 +162,7 @@ Removed: 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 '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]] [[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]] [[ "$(sed -n '13p' "${HOSTS_PATH}")" == "" ]] } @@ -190,7 +190,7 @@ Removed: 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost -0.0.0.0 example.com +0.0.0.0 example.com 127.0.0.1 example.net" _compare "'${_expected}'" "'$(cat "${HOSTS_PATH}")'" [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] @@ -214,13 +214,13 @@ Removed: Removed: fe80::1%lo0 example.com Removed: -::1 example.com +::1 example.com Removed: 127.0.0.1 example2.com Removed: fe80::1%lo0 example2.com Removed: -::1 example2.com" +::1 example2.com" _compare "'${output}'" "'${_expected}'" diff <(echo "${output}" ) <(echo "${_expected}") [[ "${output}" == "${_expected}" ]]