Skip to content

Commit

Permalink
Rename example function to 'yo'.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwmx committed Jul 6, 2020
1 parent e50d212 commit 82b7b06
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
22 changes: 11 additions & 11 deletions functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ HEREDOC
# This example also shows how to do option parsing with values in a function.
###############################################################################

sup() {
yo() {
# Usage: __get_option_value <option> <value>
__get_option_value() {
local __arg="${1:-}"
Expand Down Expand Up @@ -189,27 +189,27 @@ sup() {
then
cat <<HEREDOC
Usage:
sup
sup --all
sup -h | --help
sup (-t | --to) <name>
yo
yo --all
yo -h | --help
yo (-t | --to) <name>
Options:
--all Say 'sup' to everyone.
--all Say 'yo' to everyone.
-h --help Display this usage information.
-t <name> --to <name> Say 'sup' to <name>.
-t <name> --to <name> Say 'yo' to <name>.
Description:
Say 'sup'.
Say 'yo'.
HEREDOC
elif ((_all))
then
printf "Sup, everyone!\\n"
printf "Yo, everyone!\\n"
elif [[ -n "${_to:-}" ]]
then
printf "Sup, %s!\\n" "${_to:-}"
printf "Yo, %s!\\n" "${_to:-}"
else
printf "Sup!\\n"
printf "Yo!\\n"
fi
}

Expand Down
96 changes: 48 additions & 48 deletions test/functions.bats
Original file line number Diff line number Diff line change
Expand Up @@ -182,99 +182,99 @@ HEREDOC
}

###############################################################################
# sup()
# yo()
###############################################################################

_SUP_HELP="$(
_YO_HELP="$(
cat <<HEREDOC
Usage:
sup
sup --all
sup -h | --help
sup (-t | --to) <name>
yo
yo --all
yo -h | --help
yo (-t | --to) <name>
Options:
--all Say 'sup' to everyone.
--all Say 'yo' to everyone.
-h --help Display this usage information.
-t <name> --to <name> Say 'sup' to <name>.
-t <name> --to <name> Say 'yo' to <name>.
Description:
Say 'sup'.
Say 'yo'.
HEREDOC
)"

@test "\`sup\` with no arguments returns status 0." {
run sup
@test "\`yo\` with no arguments returns status 0." {
run yo
[[ "${status}" -eq 0 ]]
}

@test "\`sup\` with no arguments prints a string." {
run sup
[[ "${output}" == "Sup!" ]]
@test "\`yo\` with no arguments prints a string." {
run yo
[[ "${output}" == "Yo!" ]]
}

@test "\`sup -h\` returns status 0." {
run sup -h
@test "\`yo -h\` returns status 0." {
run yo -h
[[ "${status}" -eq 0 ]]
}

@test "\`sup -h\` prints help." {
run sup -h
_compare "${_SUP_HELP}" "${output}"
[[ "${output}" == "${_SUP_HELP}" ]]
@test "\`yo -h\` prints help." {
run yo -h
_compare "${_YO_HELP}" "${output}"
[[ "${output}" == "${_YO_HELP}" ]]
}

@test "\`sup --help\` returns status 0." {
run sup --help
@test "\`yo --help\` returns status 0." {
run yo --help
[[ "${status}" -eq 0 ]]
}

@test "\`sup --help\` prints help." {
run sup --help
_compare "${_SUP_HELP}" "${output}"
[[ "${output}" == "${_SUP_HELP}" ]]
@test "\`yo --help\` prints help." {
run yo --help
_compare "${_YO_HELP}" "${output}"
[[ "${output}" == "${_YO_HELP}" ]]
}

@test "\`sup --all\` returns status 0." {
run sup --all
@test "\`yo --all\` returns status 0." {
run yo --all
[[ "${status}" -eq 0 ]]
}

@test "\`sup --all\` prints a string." {
run sup --all
_compare "Sup, everyone!" "${output}"
[[ "${output}" == "Sup, everyone!" ]]
@test "\`yo --all\` prints a string." {
run yo --all
_compare "Yo, everyone!" "${output}"
[[ "${output}" == "Yo, everyone!" ]]
}

@test "\`sup --to Jack\` returns status 0." {
run sup --to Jack
@test "\`yo --to Jack\` returns status 0." {
run yo --to Jack
[[ "${status}" -eq 0 ]]
}

@test "\`sup --to Jack\` prints a string." {
run sup --to Jack
_compare "Sup, Jack!" "${output}"
[[ "${output}" == "Sup, Jack!" ]]
@test "\`yo --to Jack\` prints a string." {
run yo --to Jack
_compare "Yo, Jack!" "${output}"
[[ "${output}" == "Yo, Jack!" ]]
}

@test "\`sup --to\` without value returns status 1." {
run sup --to
@test "\`yo --to\` without value returns status 1." {
run yo --to
[[ "${status}" -eq 1 ]]
}

@test "\`sup --to\` without value prints an error message." {
run sup --to
@test "\`yo --to\` without value prints an error message." {
run yo --to
printf "\${output}: %s" "${output}"
[[ "${output}" =~ requires\ a\ valid\ argument ]]
}

@test "\`sup -t Jack\` returns status 0." {
run sup -t Jack
@test "\`yo -t Jack\` returns status 0." {
run yo -t Jack
[[ "${status}" -eq 0 ]]
}

@test "\`sup -t Jack\` prints a string." {
run sup -t Jack
_compare "Sup, Jack!" "${output}"
[[ "${output}" == "Sup, Jack!" ]]
@test "\`yo -t Jack\` prints a string." {
run yo -t Jack
_compare "Yo, Jack!" "${output}"
[[ "${output}" == "Yo, Jack!" ]]
}

0 comments on commit 82b7b06

Please sign in to comment.