Merge pull request #556 from xcambar/install_function_for_testing

Add install_script test suite; wrap installation in a function, for testing.
master
Jordan Harband 2014-10-28 13:42:59 -07:00
commit 21534ec0c9
5 changed files with 104 additions and 59 deletions

View File

@ -9,6 +9,11 @@ before_script:
script: script:
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin $SHELL - NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin $SHELL
env: env:
- SHELL=sh TEST_SUITE=install_script
- SHELL=dash TEST_SUITE=install_script
- SHELL=bash TEST_SUITE=install_script
- SHELL=zsh TEST_SUITE=install_script
- SHELL=ksh TEST_SUITE=install_script
- SHELL=sh TEST_SUITE=fast - SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast - SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast - SHELL=bash TEST_SUITE=fast
@ -34,4 +39,3 @@ env:
- SHELL=zsh TEST_SUITE=installation WITHOUT_CURL=1 - SHELL=zsh TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=ksh TEST_SUITE=installation - SHELL=ksh TEST_SUITE=installation
- SHELL=ksh TEST_SUITE=installation WITHOUT_CURL=1 - SHELL=ksh TEST_SUITE=installation WITHOUT_CURL=1

View File

@ -66,7 +66,8 @@ install_nvm_as_script() {
} }
} }
if [ -z "$METHOD" ]; then nvm_do_install() {
if [ -z "$METHOD" ]; then
# Autodetect install method # Autodetect install method
if nvm_has "git"; then if nvm_has "git"; then
install_nvm_from_git install_nvm_from_git
@ -76,24 +77,24 @@ if [ -z "$METHOD" ]; then
echo >&2 "You need git, curl, or wget to install nvm" echo >&2 "You need git, curl, or wget to install nvm"
exit 1 exit 1
fi fi
elif [ "~$METHOD" = "~git" ]; then elif [ "~$METHOD" = "~git" ]; then
if ! nvm_has "git"; then if ! nvm_has "git"; then
echo >&2 "You need git to install nvm" echo >&2 "You need git to install nvm"
exit 1 exit 1
fi fi
install_nvm_from_git install_nvm_from_git
elif [ "~$METHOD" = "~script" ]; then elif [ "~$METHOD" = "~script" ]; then
if ! nvm_has "nvm_download"; then if ! nvm_has "nvm_download"; then
echo >&2 "You need curl or wget to install nvm" echo >&2 "You need curl or wget to install nvm"
exit 1 exit 1
fi fi
install_nvm_as_script install_nvm_as_script
fi fi
echo echo
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile). # Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
if [ -z "$PROFILE" ]; then if [ -z "$PROFILE" ]; then
if [ -f "$HOME/.bashrc" ]; then if [ -f "$HOME/.bashrc" ]; then
PROFILE="$HOME/.bashrc" PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then elif [ -f "$HOME/.bash_profile" ]; then
@ -103,11 +104,11 @@ if [ -z "$PROFILE" ]; then
elif [ -f "$HOME/.profile" ]; then elif [ -f "$HOME/.profile" ]; then
PROFILE="$HOME/.profile" PROFILE="$HOME/.profile"
fi fi
fi fi
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm" SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
if [ -z "$PROFILE" ]; then if [ -z "$PROFILE" ]; then
echo "=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." echo "=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
echo "=> Create one of them and run this script again" echo "=> Create one of them and run this script again"
@ -119,13 +120,25 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
echo "=> Append the following lines to the correct file yourself:" echo "=> Append the following lines to the correct file yourself:"
printf "$SOURCE_STR" printf "$SOURCE_STR"
echo echo
else else
if ! grep -qc 'nvm.sh' "$PROFILE"; then if ! grep -qc 'nvm.sh' "$PROFILE"; then
echo "=> Appending source string to $PROFILE" echo "=> Appending source string to $PROFILE"
printf "$SOURCE_STR\n" >> "$PROFILE" printf "$SOURCE_STR\n" >> "$PROFILE"
else else
echo "=> Source string already in $PROFILE" echo "=> Source string already in $PROFILE"
fi fi
fi fi
echo "=> Close and reopen your terminal to start using nvm" echo "=> Close and reopen your terminal to start using nvm"
nvm_reset
}
#
# Unsets the various functions defined
# during the execution of the install script
#
nvm_reset() {
unset -f nvm_do_install nvm_has nvm_download install_nvm_as_script install_nvm_from_git nvm_reset
}
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install

View File

@ -10,7 +10,8 @@
"test/fast": "urchin -f test/fast", "test/fast": "urchin -f test/fast",
"test/slow": "urchin -f test/slow", "test/slow": "urchin -f test/slow",
"test/installation": "urchin -f test/installation", "test/installation": "urchin -f test/installation",
"test/sourcing": "urchin -f test/sourcing" "test/sourcing": "urchin -f test/sourcing",
"test/install_script": "urchin -f test/install_script"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -0,0 +1,6 @@
#!/bin/sh
NVM_ENV=testing . ../../install.sh
#nvm_do_install is available
type nvm_do_install > /dev/null 2>&1

View File

@ -0,0 +1,21 @@
#!/bin/sh
NVM_ENV=testing . ../../install.sh
safe_type() {
type "$1" > /dev/null 2>&1 && return 0 || return 1
}
# Check nvm_reset exists
type nvm_reset > /dev/null 2>&1
# Apply nvm_reset
nvm_reset
# The names should be unset
! safe_type nvm_do_install && \
! safe_type nvm_has && \
! safe_type nvm_download && \
! safe_type install_nvm_as_script && \
! safe_type install_nvm_from_git && \
! safe_type nvm_reset