2014-01-02 11:48:22 -05:00
|
|
|
#!/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"
|
2015-10-25 11:54:38 -04:00
|
|
|
|
2015-11-20 23:13:52 -05:00
|
|
|
mkdir -p "${PYENV_TEST_DIR}/bin"
|
|
|
|
cat > "${PYENV_TEST_DIR}/bin/git" <<CMD
|
2015-10-25 11:54:38 -04:00
|
|
|
#!$BASH
|
2015-11-20 23:13:52 -05:00
|
|
|
if [[ \$1 == remote && \$PWD != "\$PYENV_TEST_DIR"/* ]]; then
|
2015-10-25 11:54:38 -04:00
|
|
|
echo "not allowed" >&2
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exec $(which git) "\$@"
|
|
|
|
fi
|
|
|
|
CMD
|
2015-11-20 23:13:52 -05:00
|
|
|
chmod +x "${PYENV_TEST_DIR}/bin/git"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
git_commit() {
|
|
|
|
git commit --quiet --allow-empty -m "empty"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "default version" {
|
|
|
|
assert [ ! -e "$PYENV_ROOT" ]
|
|
|
|
run pyenv---version
|
|
|
|
assert_success
|
2014-06-04 00:39:50 -04:00
|
|
|
[[ $output == "pyenv 20"* ]]
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
2015-11-20 23:13:52 -05:00
|
|
|
@test "doesn't read version from non-pyenv repo" {
|
|
|
|
mkdir -p "$PYENV_ROOT"
|
|
|
|
cd "$PYENV_ROOT"
|
2015-10-25 11:54:38 -04:00
|
|
|
git init
|
|
|
|
git remote add origin https://github.com/homebrew/homebrew.git
|
|
|
|
git_commit
|
|
|
|
git tag v1.0
|
|
|
|
|
2015-11-20 23:13:52 -05:00
|
|
|
cd "$PYENV_TEST_DIR"
|
|
|
|
run pyenv---version
|
2015-10-25 11:54:38 -04:00
|
|
|
assert_success
|
2015-11-20 23:13:52 -05:00
|
|
|
[[ $output == "pyenv 20"* ]]
|
2015-10-25 11:54:38 -04:00
|
|
|
}
|
|
|
|
|
2014-01-02 11:48:22 -05:00
|
|
|
@test "reads version from git repo" {
|
|
|
|
mkdir -p "$PYENV_ROOT"
|
|
|
|
cd "$PYENV_ROOT"
|
|
|
|
git init
|
2015-11-20 23:13:52 -05:00
|
|
|
git remote add origin https://github.com/yyuu/pyenv.git
|
2014-01-02 11:48:22 -05:00
|
|
|
git_commit
|
2014-06-04 00:39:50 -04:00
|
|
|
git tag v20380119
|
2014-01-02 11:48:22 -05:00
|
|
|
git_commit
|
|
|
|
git_commit
|
|
|
|
|
|
|
|
cd "$PYENV_TEST_DIR"
|
|
|
|
run pyenv---version
|
|
|
|
assert_success
|
2014-06-04 00:39:50 -04:00
|
|
|
[[ $output == "pyenv 20380119-2-g"* ]]
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "prints default version if no tags in git repo" {
|
|
|
|
mkdir -p "$PYENV_ROOT"
|
|
|
|
cd "$PYENV_ROOT"
|
|
|
|
git init
|
2015-11-20 23:13:52 -05:00
|
|
|
git remote add origin https://github.com/yyuu/pyenv.git
|
2014-01-02 11:48:22 -05:00
|
|
|
git_commit
|
|
|
|
|
|
|
|
cd "$PYENV_TEST_DIR"
|
|
|
|
run pyenv---version
|
2014-06-04 00:39:50 -04:00
|
|
|
[[ $output == "pyenv 20"* ]]
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|