From ab9ebb9d0ddb440e5546e2eb1d1bf3e483f8b017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 8 Apr 2013 23:00:15 +0200 Subject: [PATCH] add tests for `help` and `rbenv --version` --- test/--version.bats | 46 ++++++++++++++++++ test/help.bats | 115 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 test/--version.bats create mode 100644 test/help.bats diff --git a/test/--version.bats b/test/--version.bats new file mode 100644 index 00000000..e99a3a95 --- /dev/null +++ b/test/--version.bats @@ -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."* ]] +} diff --git a/test/help.bats b/test/help.bats new file mode 100644 index 00000000..9862d630 --- /dev/null +++ b/test/help.bats @@ -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 []" + 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" < +# 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 < + +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" < +# Summary: Says "hello" to you, from rbenv +echo hello +SH + + run rbenv-help hello + assert_success + assert_output < + +Says "hello" to you, from rbenv +SH +} + +@test "extracts only usage" { + mkdir -p "${RBENV_TEST_DIR}/bin" + cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < +# 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 " +} + +@test "multiline usage section" { + mkdir -p "${RBENV_TEST_DIR}/bin" + cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < +# 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 < + 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" < +# 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 < + +This is extended help text. +It can contain multiple lines. + +And paragraphs. +SH +}