From 9190297d5eecaba6df0eba30a883535db2a84207 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 22 Aug 2012 09:49:48 -0400 Subject: [PATCH 01/15] Hide errors from `which unsetopt` Errors occurred when it was run in bash. --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 9e157a6..fb9b6c2 100755 --- a/nvm.sh +++ b/nvm.sh @@ -12,7 +12,7 @@ fi # Make zsh glob matching behave same as bash # This fixes the "zsh: no matches found" errors -if [[ `which unsetopt` ]]; then +if [[ `which unsetopt 2>/dev/null` ]]; then unsetopt nomatch 2>/dev/null fi From 2eeea1480538d0986293b8fd070a19587b42b71a Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 19:17:09 -0400 Subject: [PATCH 02/15] tests from readme --- test/fast/source | 4 ++++ test/slow/install | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100755 test/fast/source create mode 100755 test/slow/install diff --git a/test/fast/source b/test/fast/source new file mode 100755 index 0000000..f183212 --- /dev/null +++ b/test/fast/source @@ -0,0 +1,4 @@ +#!/bin/sh + +. ../nvm.sh +nvm diff --git a/test/slow/install b/test/slow/install new file mode 100755 index 0000000..c9a592c --- /dev/null +++ b/test/slow/install @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e +. ../../nvm.sh + +# Remove the stuff we're clobbering. +[ -e ../v0.6.14 ] && rm -R ../v0.6.14 + +# Install +nvm install 0.6.14 + +# Check +[ -d ../v0.6.14 ] From 9454096bc637dde37e682fd99ba934c9f2142dc0 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 19:51:00 -0400 Subject: [PATCH 03/15] fast tests --- test/fast/deactivate | 6 ++++++ test/fast/ls | 9 +++++++++ test/fast/setup | 10 ++++++++++ test/fast/source | 2 +- test/fast/teardown | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 test/fast/deactivate create mode 100755 test/fast/ls create mode 100755 test/fast/setup create mode 100755 test/fast/teardown diff --git a/test/fast/deactivate b/test/fast/deactivate new file mode 100755 index 0000000..1dcef65 --- /dev/null +++ b/test/fast/deactivate @@ -0,0 +1,6 @@ +#!/bin/sh + +. ../../nvm.sh +nvm && +nvm deactivate && +! nvm diff --git a/test/fast/ls b/test/fast/ls new file mode 100755 index 0000000..065e6fd --- /dev/null +++ b/test/fast/ls @@ -0,0 +1,9 @@ +#!/bin/sh + +. ../../nvm.sh +mkdir -p ../../v0.0.{1,3,9} + +# The result should contain the version numbers. +nvm ls | grep v0.0.1 && +nvm ls | grep v0.0.3 && +nvm ls | grep v0.0.9 diff --git a/test/fast/setup b/test/fast/setup new file mode 100755 index 0000000..a043e3b --- /dev/null +++ b/test/fast/setup @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +( + cd ../.. + + # Back up + mkdir -p bak + mv v* src alias bak || sleep 0s +) diff --git a/test/fast/source b/test/fast/source index f183212..24f8efa 100755 --- a/test/fast/source +++ b/test/fast/source @@ -1,4 +1,4 @@ #!/bin/sh -. ../nvm.sh +. ../../nvm.sh nvm diff --git a/test/fast/teardown b/test/fast/teardown new file mode 100755 index 0000000..0582ecc --- /dev/null +++ b/test/fast/teardown @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +( + cd ../.. + + # Remove temporary files + rm -fR v* src alias + + # Restore + if [ -d bak ] + then + mv bak/* . || sleep 0s + rmdir bak + fi +) From 1f5d12c73ce6a565c6df34b179441c7b7833dfc9 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 19:54:55 -0400 Subject: [PATCH 04/15] alias --- test/fast/alias_creates_file | 5 +++++ test/fast/{ls => ls_shows_versions} | 0 2 files changed, 5 insertions(+) create mode 100755 test/fast/alias_creates_file rename test/fast/{ls => ls_shows_versions} (100%) diff --git a/test/fast/alias_creates_file b/test/fast/alias_creates_file new file mode 100755 index 0000000..0ac4eb2 --- /dev/null +++ b/test/fast/alias_creates_file @@ -0,0 +1,5 @@ +#!/bin/sh + +. ../../nvm.sh +nvm alias test v0.1.2 +[ $(cat ../../alias/test) = 'v0.1.2' ] diff --git a/test/fast/ls b/test/fast/ls_shows_versions similarity index 100% rename from test/fast/ls rename to test/fast/ls_shows_versions From 200688644a06af4304b803900f0d3143218e97fd Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 19:56:37 -0400 Subject: [PATCH 05/15] unalias --- test/fast/unalias_removes_file | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 test/fast/unalias_removes_file diff --git a/test/fast/unalias_removes_file b/test/fast/unalias_removes_file new file mode 100755 index 0000000..f8ed49d --- /dev/null +++ b/test/fast/unalias_removes_file @@ -0,0 +1,6 @@ +#!/bin/sh + +echo v0.1.2 > ../../alias/test +. ../../nvm.sh +nvm unalias test +! [ -e ../../alias/test ] From c6bad42e83b8e33c8890cfb75b11b9c7ea38c9db Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 20:06:37 -0400 Subject: [PATCH 06/15] more alias tests --- test/fast/deactivate | 0 test/fast/multiple_aliases/all | 4 ++++ test/fast/multiple_aliases/setup_dir | 6 ++++++ test/fast/multiple_aliases/some | 4 ++++ test/fast/setup | 2 +- 5 files changed, 15 insertions(+), 1 deletion(-) mode change 100755 => 100644 test/fast/deactivate create mode 100755 test/fast/multiple_aliases/all create mode 100755 test/fast/multiple_aliases/setup_dir create mode 100755 test/fast/multiple_aliases/some diff --git a/test/fast/deactivate b/test/fast/deactivate old mode 100755 new mode 100644 diff --git a/test/fast/multiple_aliases/all b/test/fast/multiple_aliases/all new file mode 100755 index 0000000..42b1945 --- /dev/null +++ b/test/fast/multiple_aliases/all @@ -0,0 +1,4 @@ +#!/bin/sh + +. ../../../nvm.sh +[ $(nvm alias | wc -l) = '10' ] diff --git a/test/fast/multiple_aliases/setup_dir b/test/fast/multiple_aliases/setup_dir new file mode 100755 index 0000000..3649602 --- /dev/null +++ b/test/fast/multiple_aliases/setup_dir @@ -0,0 +1,6 @@ +#!/bin/sh + +for i in $(seq 1 10) + do + echo v0.0.$i > ../../../alias/test$i +done diff --git a/test/fast/multiple_aliases/some b/test/fast/multiple_aliases/some new file mode 100755 index 0000000..78d0022 --- /dev/null +++ b/test/fast/multiple_aliases/some @@ -0,0 +1,4 @@ +#!/bin/sh + +. ../../../nvm.sh +[ $(nvm alias test1 | wc -l) = '2' ] diff --git a/test/fast/setup b/test/fast/setup index a043e3b..49a3cb8 100755 --- a/test/fast/setup +++ b/test/fast/setup @@ -1,5 +1,4 @@ #!/bin/sh -set -e ( cd ../.. @@ -7,4 +6,5 @@ set -e # Back up mkdir -p bak mv v* src alias bak || sleep 0s + mkdir src alias ) From 2b4d4ff6e797de2d9fa969d2730082868b60d71f Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 20:23:57 -0400 Subject: [PATCH 07/15] tests --- .gitignore | 3 +++ test/fast/setup | 3 +-- test/fast/setup_dir | 9 +++++++++ test/fast/teardown | 11 +---------- test/fast/teardown_dir | 13 +++++++++++++ test/fast/uninstall | 10 ++++++++++ 6 files changed, 37 insertions(+), 12 deletions(-) create mode 100755 test/fast/setup_dir create mode 100755 test/fast/teardown_dir create mode 100755 test/fast/uninstall diff --git a/.gitignore b/.gitignore index d72736e..11a7953 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ HEAD src v* alias + +# For testing +bak diff --git a/test/fast/setup b/test/fast/setup index 49a3cb8..b433b5c 100755 --- a/test/fast/setup +++ b/test/fast/setup @@ -4,7 +4,6 @@ cd ../.. # Back up - mkdir -p bak - mv v* src alias bak || sleep 0s + rm -Rf v* src alias mkdir src alias ) diff --git a/test/fast/setup_dir b/test/fast/setup_dir new file mode 100755 index 0000000..1bba6c2 --- /dev/null +++ b/test/fast/setup_dir @@ -0,0 +1,9 @@ +#!/bin/sh + +( + cd ../.. + + # Back up + mkdir -p bak + mv v* src alias bak || sleep 0s +) diff --git a/test/fast/teardown b/test/fast/teardown index 0582ecc..954850f 100755 --- a/test/fast/teardown +++ b/test/fast/teardown @@ -1,16 +1,7 @@ #!/bin/sh -set -e +# Remove temporary files ( cd ../.. - - # Remove temporary files rm -fR v* src alias - - # Restore - if [ -d bak ] - then - mv bak/* . || sleep 0s - rmdir bak - fi ) diff --git a/test/fast/teardown_dir b/test/fast/teardown_dir new file mode 100755 index 0000000..1e6d005 --- /dev/null +++ b/test/fast/teardown_dir @@ -0,0 +1,13 @@ +#!/bin/sh + +( + cd ../.. + + # Restore + if [ -d bak ] + then + mv bak/* . || sleep 0s + rmdir bak + fi + mkdir -p src alias +) diff --git a/test/fast/uninstall b/test/fast/uninstall new file mode 100755 index 0000000..ba1ddbb --- /dev/null +++ b/test/fast/uninstall @@ -0,0 +1,10 @@ +#!/bin/sh + +cd ../.. +mkdir v0.0.1 +mkdir src/node-v0.0.1 + +. ./nvm.sh +nvm uninstall v0.0.1 + +[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1' ] From 8d34835e9b1d099cdbb97f24244ba412dc4bd13c Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 20:29:27 -0400 Subject: [PATCH 08/15] document testing --- README.markdown | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.markdown b/README.markdown index 938e425..b202d20 100644 --- a/README.markdown +++ b/README.markdown @@ -57,6 +57,28 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +## Running tests +Tests are written in [Urchin](http://www.urchin.sh). Install Urchin like so. + + wget -O /usr/local/bin https://raw.github.com/scraperwiki/urchin/master/urchin + chmod +x /usr/local/bin/urchin + +(Or put it some other place in your PATH.) + +There are slow tests and fast tests. The slow tests do things like install node +and check that the right versions are used. The fast tests fake this to test +things like aliases and uninstalling. From the root of the nvm git repository, +run the fast tests like this. + + urchin test/fast + +Run the slow tests like this. + + urchin test/slow + +Run all of the tests like this + + urchin test ## Bash completion From 601741f657034a65c6e27c194deccc196f2eff7a Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 21:02:49 -0400 Subject: [PATCH 09/15] warn not to run while testing --- README.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.markdown b/README.markdown index b202d20..ee4be80 100644 --- a/README.markdown +++ b/README.markdown @@ -80,6 +80,8 @@ Run all of the tests like this urchin test +Nota bene: Avoid running nvm while the tests are running. + ## Bash completion To activate, you need to source `bash_completion`: From 850e91f0233c3176822f3870d1e675a605dc809d Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 21:04:40 -0400 Subject: [PATCH 10/15] chmod +x deactivate --- test/fast/deactivate | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/fast/deactivate diff --git a/test/fast/deactivate b/test/fast/deactivate old mode 100644 new mode 100755 From 87f057d6a4fa5b04cc62a11ae6cdf695a7c096f2 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 21:06:34 -0400 Subject: [PATCH 11/15] specify the version (commit) of urchin --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index ee4be80..1982c94 100644 --- a/README.markdown +++ b/README.markdown @@ -60,7 +60,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI ## Running tests Tests are written in [Urchin](http://www.urchin.sh). Install Urchin like so. - wget -O /usr/local/bin https://raw.github.com/scraperwiki/urchin/master/urchin + wget -O /usr/local/bin https://raw.github.com/scraperwiki/urchin/83b0e53536d05a13501a9dc69b1a481158fedb24/urchin chmod +x /usr/local/bin/urchin (Or put it some other place in your PATH.) From 562cd9ca72fb0b3cf4fefa3f8b5ffbbe66e32b39 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 21:13:31 -0400 Subject: [PATCH 12/15] installation test --- test/slow/install | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/slow/install b/test/slow/install index c9a592c..ed26e81 100755 --- a/test/slow/install +++ b/test/slow/install @@ -4,10 +4,11 @@ set -e . ../../nvm.sh # Remove the stuff we're clobbering. -[ -e ../v0.6.14 ] && rm -R ../v0.6.14 +[ -e ../../v0.6.14 ] && rm -R ../../v0.6.14 # Install nvm install 0.6.14 # Check -[ -d ../v0.6.14 ] +[ -d ../../v0.6.14 ] +nvm use v0.6.14 --version | grep v0.6.14 From 6f2b1a23ce49b74c61579ab79055ac5e548e4e57 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 21:13:50 -0400 Subject: [PATCH 13/15] run --- test/slow/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/slow/install b/test/slow/install index ed26e81..460627b 100755 --- a/test/slow/install +++ b/test/slow/install @@ -11,4 +11,4 @@ nvm install 0.6.14 # Check [ -d ../../v0.6.14 ] -nvm use v0.6.14 --version | grep v0.6.14 +nvm run v0.6.14 --version | grep v0.6.14 From 2e5a7914c5b5dcd8db21351f7470e324d9824fc8 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 21:19:30 -0400 Subject: [PATCH 14/15] tests for ls --- test/fast/ls/base should show all versions | 14 ++++++++++++++ test/fast/ls/second number version | 10 ++++++++++ test/fast/ls_shows_versions | 9 --------- 3 files changed, 24 insertions(+), 9 deletions(-) create mode 100755 test/fast/ls/base should show all versions create mode 100755 test/fast/ls/second number version delete mode 100755 test/fast/ls_shows_versions diff --git a/test/fast/ls/base should show all versions b/test/fast/ls/base should show all versions new file mode 100755 index 0000000..dfba0da --- /dev/null +++ b/test/fast/ls/base should show all versions @@ -0,0 +1,14 @@ +#!/bin/sh + +. ../../../nvm.sh + +mkdir ../../../v0.0.{1,3,9} +mkdir ../../../v0.3.{1,3,9} + +# The result should contain the version numbers. +nvm ls | grep v0.0.1 && +nvm ls | grep v0.0.3 && +nvm ls | grep v0.0.9 && +nvm ls | grep v0.3.1 && +nvm ls | grep v0.3.3 && +nvm ls | grep v0.3.9 diff --git a/test/fast/ls/second number version b/test/fast/ls/second number version new file mode 100755 index 0000000..5a3d450 --- /dev/null +++ b/test/fast/ls/second number version @@ -0,0 +1,10 @@ +#!/bin/sh + +mkdir ../../../v0.1.3 +mkdir ../../../v0.2.3 + +. ../../../nvm.sh + +# The result should contain only the appropriate version numbers. +nvm ls 0.2 | grep v0.2.3 && +nvm ls 0.1 | grep -v v0.2.3 diff --git a/test/fast/ls_shows_versions b/test/fast/ls_shows_versions deleted file mode 100755 index 065e6fd..0000000 --- a/test/fast/ls_shows_versions +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -. ../../nvm.sh -mkdir -p ../../v0.0.{1,3,9} - -# The result should contain the version numbers. -nvm ls | grep v0.0.1 && -nvm ls | grep v0.0.3 && -nvm ls | grep v0.0.9 From 8827d6d14a8d9cd7ab6eac29ac1d5a35ea3ba413 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 21:24:57 -0400 Subject: [PATCH 15/15] switch unsetopt to the thing creationix has --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 544c176..2bed1f5 100755 --- a/nvm.sh +++ b/nvm.sh @@ -12,7 +12,7 @@ fi # Make zsh glob matching behave same as bash # This fixes the "zsh: no matches found" errors -if [[ `which unsetopt 2>/dev/null` ]]; then +if [ ! -z "$(which unsetopt 2>/dev/null)" ]; then unsetopt nomatch 2>/dev/null fi