Skip to content
Myr

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

3 files+52 added−9 removed

added:test/fast/Unit tests/nvm_find_up+26 added
1#!/bin/sh23die () { echo $@ ; cleanup ; exit 1; }4setup() {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}10cleanup () {11 rm -rf tmp_nvm_find_up12}1314. ../../../nvm.sh1516setup1718TEST_DIR="$PWD"1920[ "~$(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"2425cleanup26
added:test/fast/Unit tests/nvm_has+12 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh67nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly'89[ "~$(nvm_has foobarbaz 2>&1)" = "~" ] || die "nvm_has does not suppress error output"1011! 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 lines
97 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}106107nvm_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}114115nvm_version_dir() {
57 unmodified lines
173 fi174}175176nvm_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}179180nvm_format_version() {181 echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
12 unmodified lines
194}195196nvm_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}202203nvm_ls_current() {204 local NODE_PATH
634 unmodified lines
839 ;;840 esac841}842842nvm ls default >/dev/null && nvm use default >/dev/null || true843if nvm ls default >/dev/null; then844 nvm use default >/dev/null845elif nvm_rc_version >/dev/null 2>&1; then846 nvm use >/dev/null847fi848