Merge pull request #556 from xcambar/install_function_for_testing
Add install_script test suite; wrap installation in a function, for testing.master
commit
21534ec0c9
|
@ -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
|
||||||
|
|
||||||
|
|
127
install.sh
127
install.sh
|
@ -66,66 +66,79 @@ install_nvm_as_script() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -z "$METHOD" ]; then
|
nvm_do_install() {
|
||||||
# Autodetect install method
|
if [ -z "$METHOD" ]; then
|
||||||
if nvm_has "git"; then
|
# Autodetect install method
|
||||||
|
if nvm_has "git"; then
|
||||||
|
install_nvm_from_git
|
||||||
|
elif nvm_has "nvm_download"; then
|
||||||
|
install_nvm_as_script
|
||||||
|
else
|
||||||
|
echo >&2 "You need git, curl, or wget to install nvm"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
elif [ "~$METHOD" = "~git" ]; then
|
||||||
|
if ! nvm_has "git"; then
|
||||||
|
echo >&2 "You need git to install nvm"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
install_nvm_from_git
|
install_nvm_from_git
|
||||||
elif nvm_has "nvm_download"; then
|
elif [ "~$METHOD" = "~script" ]; then
|
||||||
|
if ! nvm_has "nvm_download"; then
|
||||||
|
echo >&2 "You need curl or wget to install nvm"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
install_nvm_as_script
|
install_nvm_as_script
|
||||||
else
|
|
||||||
echo >&2 "You need git, curl, or wget to install nvm"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
elif [ "~$METHOD" = "~git" ]; then
|
|
||||||
if ! nvm_has "git"; then
|
|
||||||
echo >&2 "You need git to install nvm"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
install_nvm_from_git
|
|
||||||
elif [ "~$METHOD" = "~script" ]; then
|
|
||||||
if ! nvm_has "nvm_download"; then
|
|
||||||
echo >&2 "You need curl or wget to install nvm"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
install_nvm_as_script
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
|
|
||||||
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
|
|
||||||
if [ -z "$PROFILE" ]; then
|
|
||||||
if [ -f "$HOME/.bashrc" ]; then
|
|
||||||
PROFILE="$HOME/.bashrc"
|
|
||||||
elif [ -f "$HOME/.bash_profile" ]; then
|
|
||||||
PROFILE="$HOME/.bash_profile"
|
|
||||||
elif [ -f "$HOME/.zshrc" ]; then
|
|
||||||
PROFILE="$HOME/.zshrc"
|
|
||||||
elif [ -f "$HOME/.profile" ]; then
|
|
||||||
PROFILE="$HOME/.profile"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
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" ]; then
|
|
||||||
echo "=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
|
|
||||||
echo "=> Create one of them and run this script again"
|
|
||||||
else
|
|
||||||
echo "=> Profile $PROFILE not found"
|
|
||||||
echo "=> Create it (touch $PROFILE) and run this script again"
|
|
||||||
fi
|
|
||||||
echo " OR"
|
|
||||||
echo "=> Append the following lines to the correct file yourself:"
|
|
||||||
printf "$SOURCE_STR"
|
|
||||||
echo
|
echo
|
||||||
else
|
|
||||||
if ! grep -qc 'nvm.sh' "$PROFILE"; then
|
|
||||||
echo "=> Appending source string to $PROFILE"
|
|
||||||
printf "$SOURCE_STR\n" >> "$PROFILE"
|
|
||||||
else
|
|
||||||
echo "=> Source string already in $PROFILE"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "=> Close and reopen your terminal to start using nvm"
|
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
|
||||||
|
if [ -z "$PROFILE" ]; then
|
||||||
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
|
PROFILE="$HOME/.bashrc"
|
||||||
|
elif [ -f "$HOME/.bash_profile" ]; then
|
||||||
|
PROFILE="$HOME/.bash_profile"
|
||||||
|
elif [ -f "$HOME/.zshrc" ]; then
|
||||||
|
PROFILE="$HOME/.zshrc"
|
||||||
|
elif [ -f "$HOME/.profile" ]; then
|
||||||
|
PROFILE="$HOME/.profile"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
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" ]; then
|
||||||
|
echo "=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
|
||||||
|
echo "=> Create one of them and run this script again"
|
||||||
|
else
|
||||||
|
echo "=> Profile $PROFILE not found"
|
||||||
|
echo "=> Create it (touch $PROFILE) and run this script again"
|
||||||
|
fi
|
||||||
|
echo " OR"
|
||||||
|
echo "=> Append the following lines to the correct file yourself:"
|
||||||
|
printf "$SOURCE_STR"
|
||||||
|
echo
|
||||||
|
else
|
||||||
|
if ! grep -qc 'nvm.sh' "$PROFILE"; then
|
||||||
|
echo "=> Appending source string to $PROFILE"
|
||||||
|
printf "$SOURCE_STR\n" >> "$PROFILE"
|
||||||
|
else
|
||||||
|
echo "=> Source string already in $PROFILE"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
NVM_ENV=testing . ../../install.sh
|
||||||
|
|
||||||
|
#nvm_do_install is available
|
||||||
|
type nvm_do_install > /dev/null 2>&1
|
|
@ -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
|
Loading…
Reference in New Issue