Merge pull request #525 from creationix/add_unit_tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add unit tests
authored by Jordan Harband · committed by Jordan Harband · parents 64de890, e186fa2 · Browse files · 3 files·+52 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+52 added−9 removed
- tests:+38 added−0 removed
- other:+14 added−9 removed
Provenance
- Commit
5363ff8- Tree
358cc53- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent 1
64de890- Parent 2
e186fa2
3 files changed+52 added−9 removed
added:test/fast/Unit tests/nvm_find_up+26 added
1+#!/bin/sh2+3+die () { echo $@ ; cleanup ; exit 1; }4+setup() {5+ cleanup6+ mkdir -p tmp_nvm_find_up/a/b/c/d7+ touch tmp_nvm_find_up/test8+ touch tmp_nvm_find_up/a/b/c/test9+}10+cleanup () {11+ rm -rf tmp_nvm_find_up12+}13+14+. ../../../nvm.sh15+16+setup17+18+TEST_DIR="$PWD"19+20+[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 1 dir up"21+[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 2 dirs up"22+[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find in current dir"23+[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find 1 level up from current dir"24+25+cleanup26+added:test/fast/Unit tests/nvm_has+12 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+. ../../../nvm.sh6+7+nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly'8+9+[ "~$(nvm_has foobarbaz 2>&1)" = "~" ] || die "nvm_has does not suppress error output"10+11+! nvm_has foobarbaz && ! type foobarbaz >/dev/null 2>&1 || die "nvm_has does not return a nonzero exit code when not found"12+modified:nvm.sh+14 added-9 removed
96 unmodified lines97 NVMRC_PATH="$(nvm_find_nvmrc)"98 if [ -e "$NVMRC_PATH" ]; then99 read NVM_RC_VERSION < "$NVMRC_PATH"100 echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>"101+ else102+ >&2 echo "No .nvmrc file found"103+ return 1104 fi105 }106 107 nvm_version_greater() {108 local LHS106- LHS=$(echo "$1" | awk -F. '{for (i=1;i<=NF;++i) printf "%010d",$i}')109+ LHS=$(nvm_normalize_version "$1")110 local RHS108- RHS=$(echo "$2" | awk -F. '{for (i=1;i<=NF;++i) printf "%010d",$i}')111+ RHS=$(nvm_normalize_version "$2")112 [ $LHS -gt $RHS ];113 }114 115 nvm_version_dir() {57 unmodified lines173 fi174 }175 176 nvm_normalize_version() {174- echo "$1" | sed -e 's/^v//' | \awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'177+ echo "$1" | sed -e 's/^v//' | \awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'178 }179 180 nvm_format_version() {181 echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'12 unmodified lines194 }195 196 nvm_binary_available() {197 # binaries started with node 0.8.6195- local MINIMAL196- MINIMAL="0.8.6"197- local VERSION198- VERSION=$1199- [ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]198+ local LAST_VERSION_WITHOUT_BINARY199+ LAST_VERSION_WITHOUT_BINARY="0.8.5"200+ nvm_version_greater "$1" "$LAST_VERSION_WITHOUT_BINARY"201 }202 203 nvm_ls_current() {204 local NODE_PATH634 unmodified lines839 ;;840 esac841 }842 842-nvm ls default >/dev/null && nvm use default >/dev/null || true843+if nvm ls default >/dev/null; then844+ nvm use default >/dev/null845+elif nvm_rc_version >/dev/null 2>&1; then846+ nvm use >/dev/null847+fi848