mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
add tests for help
and rbenv --version
This commit is contained in:
parent
ab197ef51e
commit
ab9ebb9d0d
2 changed files with 161 additions and 0 deletions
46
test/--version.bats
Normal file
46
test/--version.bats
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "$HOME"
|
||||
git config --global user.name "Tester"
|
||||
git config --global user.email "tester@test.local"
|
||||
}
|
||||
|
||||
git_commit() {
|
||||
git commit --quiet --allow-empty -m "" --allow-empty-message
|
||||
}
|
||||
|
||||
@test "default version" {
|
||||
assert [ ! -e "$RBENV_ROOT" ]
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv 0."* ]]
|
||||
}
|
||||
|
||||
@test "reads version from git repo" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
cd "$RBENV_ROOT"
|
||||
git init
|
||||
git_commit
|
||||
git tag v0.4.1
|
||||
git_commit
|
||||
git_commit
|
||||
|
||||
cd "$RBENV_TEST_DIR"
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv 0.4.1-2-g"* ]]
|
||||
}
|
||||
|
||||
@test "prints default version if no tags in git repo" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
cd "$RBENV_ROOT"
|
||||
git init
|
||||
git_commit
|
||||
|
||||
cd "$RBENV_TEST_DIR"
|
||||
run rbenv---version
|
||||
[[ $output == "rbenv 0."* ]]
|
||||
}
|
115
test/help.bats
Normal file
115
test/help.bats
Normal file
|
@ -0,0 +1,115 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "without args shows summary of common commands" {
|
||||
run rbenv-help
|
||||
assert_success
|
||||
assert_line "Usage: rbenv <command> [<args>]"
|
||||
assert_line "Some useful rbenv commands are:"
|
||||
}
|
||||
|
||||
@test "invalid command" {
|
||||
run rbenv-help hello
|
||||
assert_failure "rbenv: no such command \`hello'"
|
||||
}
|
||||
|
||||
@test "shows help for a specific command" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This command is useful for saying hello.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
This command is useful for saying hello.
|
||||
SH
|
||||
}
|
||||
|
||||
@test "replaces missing extended help with summary text" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
Says "hello" to you, from rbenv
|
||||
SH
|
||||
}
|
||||
|
||||
@test "extracts only usage" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This extended help won't be shown.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help --usage hello
|
||||
assert_success "Usage: rbenv hello <world>"
|
||||
}
|
||||
|
||||
@test "multiline usage section" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# rbenv hi [everybody]
|
||||
# rbenv hola --translate
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# Help text.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
rbenv hi [everybody]
|
||||
rbenv hola --translate
|
||||
|
||||
Help text.
|
||||
SH
|
||||
}
|
||||
|
||||
@test "multiline extended help section" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This is extended help text.
|
||||
# It can contain multiple lines.
|
||||
#
|
||||
# And paragraphs.
|
||||
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
This is extended help text.
|
||||
It can contain multiple lines.
|
||||
|
||||
And paragraphs.
|
||||
SH
|
||||
}
|
Loading…
Reference in a new issue