2015-09-29 07:02:34 +08:00
|
|
|
|
assert_ok() {
|
|
|
|
|
local FUNCTION=$1
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
|
|
$($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have succeeded, but failed'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert_not_ok() {
|
|
|
|
|
local FUNCTION=$1
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
|
|
! $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have failed, but succeeded'
|
|
|
|
|
}
|
2016-04-28 08:05:33 +08:00
|
|
|
|
|
|
|
|
|
strip_colors() {
|
|
|
|
|
while read -r line; do
|
|
|
|
|
echo "$line" | LC_ALL=C command sed 's/\[[ -?]*[@-~]//g'
|
|
|
|
|
done
|
|
|
|
|
}
|
2016-07-08 06:38:34 +08:00
|
|
|
|
|
|
|
|
|
make_echo() {
|
|
|
|
|
echo "#!/bin/sh" > "$1"
|
|
|
|
|
echo "echo \"${2}\"" > "$1"
|
|
|
|
|
chmod a+x "$1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
make_fake_node() {
|
|
|
|
|
local VERSION
|
|
|
|
|
VERSION="${1-}"
|
|
|
|
|
[ -n "${VERSION}" ] || return 1
|
|
|
|
|
|
2019-02-24 07:24:02 +08:00
|
|
|
|
local FORMATTED_VERSION
|
|
|
|
|
FORMATTED_VERSION="$(nvm_format_version "${VERSION}")"
|
|
|
|
|
|
2016-07-08 06:38:34 +08:00
|
|
|
|
local BIN_PATH
|
2019-02-24 07:24:02 +08:00
|
|
|
|
BIN_PATH="$(nvm_version_path "${FORMATTED_VERSION}")/bin"
|
|
|
|
|
[ "${BIN_PATH}" != "/bin" ] || {
|
|
|
|
|
echo >&2 'nvm_version_path was empty'
|
|
|
|
|
return 5
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-08 06:38:34 +08:00
|
|
|
|
mkdir -p "${BIN_PATH}" || {
|
|
|
|
|
echo >&2 'unable to make bin dir'
|
|
|
|
|
return 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
make_echo "${BIN_PATH}/node" "${VERSION}" || {
|
|
|
|
|
echo >&2 'unable to make fake node bin'
|
|
|
|
|
return 3
|
|
|
|
|
}
|
2019-02-24 07:24:02 +08:00
|
|
|
|
|
|
|
|
|
nvm_is_version_installed "${FORMATTED_VERSION}" || {
|
|
|
|
|
echo >&2 'fake node is not installed'
|
|
|
|
|
return 4
|
|
|
|
|
}
|
2016-07-08 06:38:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
make_fake_iojs() {
|
|
|
|
|
local VERSION
|
|
|
|
|
VERSION="${1-}"
|
|
|
|
|
[ -n "${VERSION}" ] || return 1
|
|
|
|
|
|
2019-02-24 07:24:02 +08:00
|
|
|
|
local FORMATTED_VERSION
|
|
|
|
|
FORMATTED_VERSION="$(nvm_format_version "iojs-${VERSION}")"
|
|
|
|
|
|
2016-07-08 06:38:34 +08:00
|
|
|
|
local BIN_PATH
|
2019-02-24 07:24:02 +08:00
|
|
|
|
BIN_PATH="$(nvm_version_path "${FORMATTED_VERSION}")/bin"
|
|
|
|
|
[ "${BIN_PATH}" != "/bin" ] || {
|
|
|
|
|
echo >&2 'nvm_version_path was empty'
|
|
|
|
|
return 5
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-08 06:38:34 +08:00
|
|
|
|
mkdir -p "${BIN_PATH}" || {
|
|
|
|
|
echo >&2 'unable to make bin dir'
|
|
|
|
|
return 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
make_echo "${BIN_PATH}/node" "${VERSION}" || {
|
|
|
|
|
echo >&2 'unable to make fake node bin'
|
|
|
|
|
return 3
|
|
|
|
|
}
|
|
|
|
|
make_echo "${BIN_PATH}/iojs" "${VERSION}" || {
|
|
|
|
|
echo >&2 'unable to make fake iojs bin'
|
|
|
|
|
return 3
|
|
|
|
|
}
|
2019-02-24 07:24:02 +08:00
|
|
|
|
|
|
|
|
|
nvm_is_version_installed "${FORMATTED_VERSION}" || {
|
|
|
|
|
echo >&2 'fake iojs is not installed'
|
|
|
|
|
return 4
|
|
|
|
|
}
|
2016-07-08 06:38:34 +08:00
|
|
|
|
}
|
2016-05-26 14:48:15 +08:00
|
|
|
|
|
|
|
|
|
watch() {
|
|
|
|
|
$@ &
|
|
|
|
|
local JOB
|
|
|
|
|
JOB=$!
|
2016-08-15 06:40:39 +08:00
|
|
|
|
while true; do sleep 15; >&2 echo '* ping *'; done &
|
2016-05-26 14:48:15 +08:00
|
|
|
|
wait $JOB;
|
|
|
|
|
local EXIT_CODE
|
|
|
|
|
EXIT_CODE=$?
|
|
|
|
|
kill %2;
|
|
|
|
|
return $EXIT_CODE
|
|
|
|
|
}
|