Skip to content

Commit c045303

Browse files
Sladyn Nunesljharb
Sladyn Nunes
authored andcommitted
Add check to nvm profile for nvm path
1 parent 5fcec57 commit c045303

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
setup () {
4+
HOME="."
5+
NVM_ENV=testing \. ../../install.sh
6+
touch ".bashrc"
7+
touch ".zshrc"
8+
touch ".profile"
9+
}
10+
11+
cleanup () {
12+
unset HOME
13+
unset NVM_ENV
14+
unset NVM_DETECT_PROFILE
15+
unset BASH_VERSION
16+
unset ZSH_VERSION
17+
unset -f setup cleanup die
18+
rm -f ".bashrc" ".bash_profile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&1
19+
}
20+
21+
die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }
22+
23+
setup
24+
25+
# check if nvm_path already exists in bashrc
26+
NVM_DETECT_PROFILE="$(BASH_VERSION="1"; unset PROFILE; nvm_detect_profile)"
27+
echo "export NVM_DIR="$HOME/.nvm"" > $HOME/.bashrc
28+
OUTPUT = "$(nvm_do_install)"
29+
EXPECTED_OUTPUT='nvm source string already in ${NVM_PROFILE}'
30+
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
31+
die "Path already exists in the profile, so should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
32+
fi
33+
34+
# .zshrc should be detected for zsh
35+
NVM_DETECT_PROFILE="$(ZSH_VERSION="1"; unset PROFILE; unset BASH_VERSION; nvm_detect_profile)"
36+
echo "export NVM_DIR="$HOME/.nvm"" > $HOME/.zshrc
37+
OUTPUT = "$(nvm_do_install)"
38+
EXPECTED_OUTPUT='nvm source string already in ${NVM_PROFILE}'
39+
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
40+
die "Path already exists in the profile, so should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
41+
fi

0 commit comments

Comments
 (0)