mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-12-11 15:44:19 +00:00
Compare commits
5 Commits
submods
...
block_iojs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
663c9968cb | ||
|
|
1fd0c8ca90 | ||
|
|
762f9ef9d1 | ||
|
|
e597bb208e | ||
|
|
aa427ad396 |
13
.travis.yml
13
.travis.yml
@@ -8,6 +8,12 @@ addons:
|
||||
# - gcc-4.8
|
||||
# - g++-4.8
|
||||
|
||||
# https://gist.github.com/iedemam/9830045
|
||||
git:
|
||||
submodules: false
|
||||
|
||||
group: previous
|
||||
|
||||
cache:
|
||||
ccache: true
|
||||
directories:
|
||||
@@ -16,6 +22,11 @@ cache:
|
||||
before_install:
|
||||
- sudo sed -i 's/mozilla\/DST_Root_CA_X3.crt/!mozilla\/DST_Root_CA_X3.crt/g' /etc/ca-certificates.conf
|
||||
- sudo update-ca-certificates -f
|
||||
|
||||
# https://gist.github.com/iedemam/9830045
|
||||
- sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules
|
||||
- git submodule update --init --recursive
|
||||
|
||||
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
|
||||
- curl --version
|
||||
- wget --version
|
||||
@@ -23,7 +34,7 @@ before_install:
|
||||
- zsh --version
|
||||
- dpkg -s dash | grep ^Version | awk '{print $2}'
|
||||
# install python
|
||||
- pyenv install 2.7.18
|
||||
- pyenv local 2.7.18 || pyenv install 2.7.18
|
||||
- pyenv local 2.7.18 || echo 'pyenv failed'
|
||||
- python -V
|
||||
install:
|
||||
|
||||
5
nvm.sh
5
nvm.sh
@@ -765,6 +765,11 @@ nvm_remote_versions() {
|
||||
NVM_FLAVOR="${NVM_NODE_PREFIX}"
|
||||
unset PATTERN
|
||||
;;
|
||||
*)
|
||||
if [ "${NVM_IOJS_ORG_MIRROR-x}" = '' ]; then
|
||||
NVM_FLAVOR="${NVM_NODE_PREFIX}"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if nvm_validate_implicit_alias "${PATTERN-}" 2>/dev/null; then
|
||||
|
||||
236
test/common.sh
236
test/common.sh
@@ -102,104 +102,146 @@ watch() {
|
||||
return $EXIT_CODE
|
||||
}
|
||||
|
||||
parse_json() {
|
||||
local json
|
||||
json="$1"
|
||||
local key
|
||||
key=""
|
||||
local value
|
||||
value=""
|
||||
local output
|
||||
output=""
|
||||
local in_key
|
||||
in_key=0
|
||||
local in_value
|
||||
in_value=0
|
||||
local in_string
|
||||
in_string=0
|
||||
local escaped
|
||||
escaped=0
|
||||
local buffer
|
||||
buffer=""
|
||||
local char
|
||||
local len
|
||||
len=${#json}
|
||||
local arr_index
|
||||
arr_index=0
|
||||
local in_array
|
||||
in_array=0
|
||||
|
||||
for ((i = 0; i < len; i++)); do
|
||||
char="${json:i:1}"
|
||||
|
||||
if [ "$in_string" -eq 1 ]; then
|
||||
if [ "$escaped" -eq 1 ]; then
|
||||
buffer="$buffer$char"
|
||||
escaped=0
|
||||
elif [ "$char" = "\\" ]; then
|
||||
escaped=1
|
||||
elif [ "$char" = "\"" ]; then
|
||||
in_string=0
|
||||
if [ "$in_key" -eq 1 ]; then
|
||||
key="$buffer"
|
||||
buffer=""
|
||||
in_key=0
|
||||
elif [ "$in_value" -eq 1 ]; then
|
||||
value="$buffer"
|
||||
buffer=""
|
||||
output="$output$key=\"$value\"\n"
|
||||
in_value=0
|
||||
elif [ "$in_array" -eq 1 ]; then
|
||||
value="$buffer"
|
||||
buffer=""
|
||||
output="$output$arr_index=\"$value\"\n"
|
||||
arr_index=$((arr_index + 1))
|
||||
fi
|
||||
else
|
||||
buffer="$buffer$char"
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
|
||||
case "$char" in
|
||||
"\"")
|
||||
in_string=1
|
||||
buffer=""
|
||||
if [ "$in_value" -eq 0 ] && [ "$in_array" -eq 0 ]; then
|
||||
in_key=1
|
||||
fi
|
||||
;;
|
||||
":")
|
||||
in_value=1
|
||||
;;
|
||||
",")
|
||||
if [ "$in_value" -eq 1 ]; then
|
||||
in_value=0
|
||||
fi
|
||||
;;
|
||||
"[")
|
||||
in_array=1
|
||||
;;
|
||||
"]")
|
||||
in_array=0
|
||||
;;
|
||||
"{" | "}")
|
||||
;;
|
||||
*)
|
||||
if [ "$in_value" -eq 1 ] && [ "$char" != " " ] && [ "$char" != "\n" ] && [ "$char" != "\t" ]; then
|
||||
buffer="$buffer$char"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
printf "%b" "$output"
|
||||
# JSON parsing from https://gist.github.com/assaf/ee377a186371e2e269a7
|
||||
nvm_json_throw() {
|
||||
nvm_err "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
extract_value() {
|
||||
local key
|
||||
key="$1"
|
||||
local parsed
|
||||
parsed="$2"
|
||||
echo "$parsed" | grep "^$key=" | cut -d'=' -f2 | tr -d '"'
|
||||
nvm_json_awk_egrep() {
|
||||
local pattern_string
|
||||
pattern_string="${1}"
|
||||
|
||||
awk '{
|
||||
while ($0) {
|
||||
start=match($0, pattern);
|
||||
token=substr($0, start, RLENGTH);
|
||||
print token;
|
||||
$0=substr($0, start+RLENGTH);
|
||||
}
|
||||
}' "pattern=${pattern_string}"
|
||||
}
|
||||
|
||||
nvm_json_tokenize() {
|
||||
local GREP
|
||||
GREP='grep -Eao'
|
||||
|
||||
local ESCAPE
|
||||
local CHAR
|
||||
|
||||
# if echo "test string" | grep -Eo "test" > /dev/null 2>&1; then
|
||||
# ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
|
||||
# CHAR='[^[:cntrl:]"\\]'
|
||||
# else
|
||||
GREP=nvm_json_awk_egrep
|
||||
ESCAPE='(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
|
||||
CHAR='[^[:cntrl:]"\\\\]'
|
||||
# fi
|
||||
|
||||
local STRING
|
||||
STRING="\"${CHAR}*(${ESCAPE}${CHAR}*)*\""
|
||||
local NUMBER
|
||||
NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
|
||||
local KEYWORD
|
||||
KEYWORD='null|false|true'
|
||||
local SPACE
|
||||
SPACE='[[:space:]]+'
|
||||
|
||||
$GREP "${STRING}|${NUMBER}|${KEYWORD}|${SPACE}|." | TERM=dumb grep -Ev "^${SPACE}$"
|
||||
}
|
||||
|
||||
_json_parse_array() {
|
||||
local index=0
|
||||
local ary=''
|
||||
read -r token
|
||||
case "$token" in
|
||||
']') ;;
|
||||
*)
|
||||
while :; do
|
||||
_json_parse_value "${1}" "${index}"
|
||||
index=$((index+1))
|
||||
ary="${ary}${value}"
|
||||
read -r token
|
||||
case "${token}" in
|
||||
']') break ;;
|
||||
',') ary="${ary}," ;;
|
||||
*) nvm_json_throw "EXPECTED , or ] GOT ${token:-EOF}" ;;
|
||||
esac
|
||||
read -r token
|
||||
done
|
||||
;;
|
||||
esac
|
||||
:
|
||||
}
|
||||
|
||||
_json_parse_object() {
|
||||
local key
|
||||
local obj=''
|
||||
read -r token
|
||||
case "$token" in
|
||||
'}') ;;
|
||||
*)
|
||||
while :; do
|
||||
case "${token}" in
|
||||
'"'*'"') key="${token}" ;;
|
||||
*) nvm_json_throw "EXPECTED string GOT ${token:-EOF}" ;;
|
||||
esac
|
||||
read -r token
|
||||
case "${token}" in
|
||||
':') ;;
|
||||
*) nvm_json_throw "EXPECTED : GOT ${token:-EOF}" ;;
|
||||
esac
|
||||
read -r token
|
||||
_json_parse_value "${1}" "${key}"
|
||||
obj="${obj}${key}:${value}"
|
||||
read -r token
|
||||
case "${token}" in
|
||||
'}') break ;;
|
||||
',') obj="${obj}," ;;
|
||||
*) nvm_json_throw "EXPECTED , or } GOT ${token:-EOF}" ;;
|
||||
esac
|
||||
read -r token
|
||||
done
|
||||
;;
|
||||
esac
|
||||
:
|
||||
}
|
||||
|
||||
_json_parse_value() {
|
||||
local jpath="${1:+$1,}$2"
|
||||
local isleaf=0
|
||||
local isempty=0
|
||||
local print=0
|
||||
|
||||
case "$token" in
|
||||
'{') _json_parse_object "${jpath}" ;;
|
||||
'[') _json_parse_array "${jpath}" ;;
|
||||
# At this point, the only valid single-character tokens are digits.
|
||||
''|[!0-9]) nvm_json_throw "EXPECTED value GOT >${token:-EOF}<" ;;
|
||||
*)
|
||||
value=$token
|
||||
isleaf=1
|
||||
[ "${value}" = '""' ] && isempty=1
|
||||
;;
|
||||
esac
|
||||
|
||||
[ "${value}" = '' ] && return
|
||||
[ "${isleaf}" -eq 1 ] && [ $isempty -eq 0 ] && print=1
|
||||
[ "${print}" -eq 1 ] && printf "[%s]\t%s\n" "${jpath}" "${value}"
|
||||
:
|
||||
}
|
||||
|
||||
_json_parse() {
|
||||
read -r token
|
||||
_json_parse_value
|
||||
read -r token
|
||||
case "${token}" in
|
||||
'') ;;
|
||||
*) nvm_json_throw "EXPECTED EOF GOT >${token}<" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
nvm_json_extract() {
|
||||
nvm_json_tokenize | _json_parse | grep -e "${1}" | awk '{print $2 $3}'
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ for f in ../../../test/fixtures/nvmrc/test/fixtures/valid/*; do
|
||||
STDOUT="$(nvm_process_nvmrc $f/.nvmrc 2>/dev/null)"
|
||||
EXIT_CODE="$(nvm_process_nvmrc $f/.nvmrc >/dev/null 2>/dev/null; echo $?)"
|
||||
|
||||
EXPECTED="$(extract_value node "$(parse_json "$(cat "$f/expected.json")")")"
|
||||
EXPECTED="$(nvm_json_extract node < "${f}/expected.json" | tr -d '"')"
|
||||
|
||||
[ "${EXIT_CODE}" = "0" ] || die "$(basename "${f}"): expected exit code of 0 but got ${EXIT_CODE}"
|
||||
|
||||
@@ -26,7 +26,7 @@ for f in ../../../test/fixtures/nvmrc/test/fixtures/invalid/*; do
|
||||
STDERR="$(nvm_process_nvmrc $f/.nvmrc 2>&1 >/dev/null | awk '{if(NR > 8) print $0}' | strip_colors)"
|
||||
EXIT_CODE="$(nvm_process_nvmrc $f/.nvmrc >/dev/null 2>/dev/null; echo $?)"
|
||||
|
||||
EXPECTED="$(parse_json "$(cat "$f/expected.json")" | sed 's/^[0-9]*="//;s/"$//')"
|
||||
EXPECTED="$(nvm_json_extract < "${f}/expected.json" | tr -d '"')"
|
||||
|
||||
[ "${EXIT_CODE}" != "0" ] || die "$(basename "${f}"): expected exit code of 'not 0' but got ${EXIT_CODE}"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
cleanup() {
|
||||
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||
unset -f nvm_ls_remote nvm_ls_remote_iojs nvm_ls_remote_node NVM_IOJS_ORG_MIRROR
|
||||
}
|
||||
|
||||
\. ../../../nvm.sh
|
||||
@@ -11,67 +11,72 @@ cleanup() {
|
||||
OUTPUT="$(nvm_remote_versions stable 2>&1)"
|
||||
EXPECTED_OUTPUT="Implicit aliases are not supported in nvm_remote_versions."
|
||||
EXIT_CODE="$(nvm_remote_versions stable >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "implicit alias 'stable' did not error out with correct message, got $OUTPUT"
|
||||
[ "_$EXIT_CODE" = "_1" ] || die "implicit alias 'stable' did not exit with code 1, got $EXIT_CODE"
|
||||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "implicit alias 'stable' did not error out with correct message, got ${OUTPUT}"
|
||||
[ "_${EXIT_CODE}" = '_1' ] || die "implicit alias 'stable' did not exit with code 1, got ${EXIT_CODE}"
|
||||
|
||||
OUTPUT="$(nvm_remote_versions unstable 2>&1)"
|
||||
EXPECTED_OUTPUT="Implicit aliases are not supported in nvm_remote_versions."
|
||||
EXIT_CODE="$(nvm_remote_versions unstable >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "implicit alias 'unstable' did not error out with correct message, got $OUTPUT"
|
||||
[ "_$EXIT_CODE" = "_1" ] || die "implicit alias 'unstable' did not exit with code 1, got $EXIT_CODE"
|
||||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "implicit alias 'unstable' did not error out with correct message, got ${OUTPUT}"
|
||||
[ "_${EXIT_CODE}" = '_1' ] || die "implicit alias 'unstable' did not exit with code 1, got ${EXIT_CODE}"
|
||||
|
||||
nvm_ls_remote() {
|
||||
echo "N/A"
|
||||
}
|
||||
OUTPUT="$(nvm_remote_versions foo)"
|
||||
EXIT_CODE="$(nvm_remote_versions foo >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"
|
||||
[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"
|
||||
[ "_${OUTPUT}" = "_N/A" ] || die "nonexistent version did not report N/A"
|
||||
[ "_${EXIT_CODE}" = '_3' ] || die "nonexistent version did not exit with code 3, got ${EXIT_CODE}"
|
||||
|
||||
nvm_ls_remote_iojs() {
|
||||
echo "N/A"
|
||||
}
|
||||
OUTPUT="$(nvm_remote_versions iojs-foo)"
|
||||
EXIT_CODE="$(nvm_remote_versions iojs-foo >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"
|
||||
[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"
|
||||
[ "_${OUTPUT}" = "_N/A" ] || die "nonexistent version did not report N/A"
|
||||
[ "_${EXIT_CODE}" = '_3' ] || die "nonexistent version did not exit with code 3, got ${EXIT_CODE}"
|
||||
|
||||
|
||||
nvm_ls_remote() {
|
||||
nvm_ls_remote_node() {
|
||||
echo "test output"
|
||||
echo "more test output"
|
||||
echo "pattern received: _$1_"
|
||||
echo "pattern received: _${1}_"
|
||||
}
|
||||
nvm_ls_remote_iojs() {
|
||||
echo "test iojs output"
|
||||
echo "more iojs test output"
|
||||
echo "iojs pattern received: _$1_"
|
||||
echo "iojs pattern received: _${1}_"
|
||||
}
|
||||
|
||||
OUTPUT="$(nvm_remote_versions foo)"
|
||||
EXIT_CODE="$(nvm_remote_versions foo >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_$(nvm_ls_remote foo)
|
||||
[ "_${OUTPUT}" = "_$(nvm_ls_remote foo)
|
||||
$(nvm_ls_remote_iojs foo)" ] \
|
||||
|| die "nvm_remote_versions foo did not return contents of nvm_ls_remote foo combined with nvm_ls_remote_iojs foo; got $OUTPUT"
|
||||
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_versions foo did not exit with 0, got $EXIT_CODE"
|
||||
|| die "nvm_remote_versions foo did not return contents of nvm_ls_remote foo combined with nvm_ls_remote_iojs foo; got ${OUTPUT}"
|
||||
[ "_${EXIT_CODE}" = '_0' ] || die "nvm_remote_versions foo did not exit with 0, got ${EXIT_CODE}"
|
||||
|
||||
OUTPUT="$(nvm_remote_versions node)"
|
||||
EXIT_CODE="$(nvm_remote_versions node >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_$(nvm_ls_remote)" ] \
|
||||
|| die "nvm_remote_versions node did not return contents of nvm_ls_remote; got $OUTPUT"
|
||||
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_versions node did not exit with 0, got $EXIT_CODE"
|
||||
[ "_${OUTPUT}" = "_$(nvm_ls_remote)" ] \
|
||||
|| die "nvm_remote_versions node did not return contents of nvm_ls_remote; got ${OUTPUT}"
|
||||
[ "_${EXIT_CODE}" = '_0' ] || die "nvm_remote_versions node did not exit with 0, got ${EXIT_CODE}"
|
||||
|
||||
OUTPUT="$(nvm_remote_versions iojs-foo)"
|
||||
EXIT_CODE="$(nvm_remote_versions iojs-foo >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_$(nvm_ls_remote iojs-foo)
|
||||
[ "_${OUTPUT}" = "_$(nvm_ls_remote iojs-foo)
|
||||
$(nvm_ls_remote_iojs iojs-foo)" ] \
|
||||
|| die "nvm_remote_versions iojs-foo did not return contents of nvm_ls_remote iojs-foo combined with nvm_ls_remote_iojs iojs-foo; got $OUTPUT"
|
||||
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_versions iojs-foo did not exit with 0, got $EXIT_CODE"
|
||||
|| die "nvm_remote_versions iojs-foo did not return contents of nvm_ls_remote iojs-foo combined with nvm_ls_remote_iojs iojs-foo; got ${OUTPUT}"
|
||||
[ "_${EXIT_CODE}" = '_0' ] || die "nvm_remote_versions iojs-foo did not exit with 0, got ${EXIT_CODE}"
|
||||
|
||||
OUTPUT="$(nvm_remote_versions iojs)"
|
||||
EXIT_CODE="$(nvm_remote_versions iojs >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_$(nvm_ls_remote_iojs)" ] \
|
||||
|| die "nvm_remote_versions iojs did not return contents of nvm_ls_remote_iojs; got $OUTPUT"
|
||||
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_versions iojs did not exit with 0, got $EXIT_CODE"
|
||||
[ "_${OUTPUT}" = "_$(nvm_ls_remote_iojs)" ] \
|
||||
|| die "nvm_remote_versions iojs did not return contents of nvm_ls_remote_iojs; got ${OUTPUT}"
|
||||
[ "_${EXIT_CODE}" = '_0' ] || die "nvm_remote_versions iojs did not exit with 0, got ${EXIT_CODE}"
|
||||
|
||||
OUTPUT="$(NVM_IOJS_ORG_MIRROR= nvm_remote_versions)"
|
||||
EXIT_CODE="$(nvm_remote_versions iojs >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_${OUTPUT}" = "_$(nvm_ls_remote_node)" ] \
|
||||
|| die "NVM_IOJS_ORG_MIRROR= nvm_remote_versions did not return contents of nvm_ls_remote_node; got ${OUTPUT}"
|
||||
[ "_${EXIT_CODE}" = '_0' ] || die "nvm_ls_remote_node= nvm_remote_versions did not exit with 0, got ${EXIT_CODE}"
|
||||
|
||||
cleanup
|
||||
|
||||
Reference in New Issue
Block a user