Test `add` with multi-word comment.

This commit is contained in:
William Melody 2018-05-14 18:53:06 -07:00
parent 661fa3b114
commit d8f86743f4
1 changed files with 6 additions and 5 deletions

View File

@ -87,7 +87,7 @@ load test_helper
# `hosts add <ip> <hostname> [comment]` ####################################### # `hosts add <ip> <hostname> [comment]` #######################################
@test "\`add <ip> <hostname> [comment]\` exits with status 0." { @test "\`add <ip> <hostname> [comment]\` exits with status 0." {
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' run "${_HOSTS}" add 0.0.0.0 example.com 'Example multi-word comment.'
printf "\${status}: %s\\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
@ -96,19 +96,20 @@ load test_helper
@test "\`add <ip> <hostname> [comment]\` adds the entry to the hosts file." { @test "\`add <ip> <hostname> [comment]\` adds the entry to the hosts file." {
_original="$(cat "${HOSTS_PATH}")" _original="$(cat "${HOSTS_PATH}")"
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' run "${_HOSTS}" add 0.0.0.0 example.com 'Example multi-word comment.'
printf "\${status}: %s\\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]] [[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com # Comment." ]] [[ "$(sed -n '11p' "${HOSTS_PATH}")" == \
"0.0.0.0 example.com # Example multi-word comment." ]]
} }
@test "\`add <ip> <hostname> [comment]\` prints feedback." { @test "\`add <ip> <hostname> [comment]\` prints feedback." {
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.' run "${_HOSTS}" add 0.0.0.0 example.com 'Example multi-word comment.'
printf "\${status}: %s\\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" == "Added:" ]] [[ "${lines[0]}" == "Added:" ]]
[[ "${lines[1]}" == "0.0.0.0 example.com # Comment." ]] [[ "${lines[1]}" == "0.0.0.0 example.com # Example multi-word comment." ]]
} }
# help ######################################################################## # help ########################################################################