From a27d39139bc1d92f2e98eae97c8f76efc0d16bb6 Mon Sep 17 00:00:00 2001 From: Thomas Levine Date: Wed, 10 Oct 2012 19:17:09 -0400 Subject: [PATCH] tests from readme fast tests alias unalias more alias tests tests document testing warn not to run while testing chmod +x deactivate specify the version (commit) of urchin installation test run tests for ls switch unsetopt to the thing creationix has rename tests urchin log adjust urchin version --- .gitignore | 4 ++++ README.markdown | 24 +++++++++++++++++++ nvm.sh | 2 +- ... \" should list but one alias." | 4 ++++ ...ng \"nvm alias\" should list all aliases." | 4 ++++ test/fast/Aliases/setup_dir | 6 +++++ ...0.2\" should display only 0.2.x versions." | 10 ++++++++ ...\" should display all installed versions." | 14 +++++++++++ ...uld create a file in the alias directory." | 5 ++++ ...ould unset the nvm environment variables." | 6 +++++ ...m unalias\" should remove the alias file." | 6 +++++ ... should remove the appropriate directory." | 10 ++++++++ ....sh should make the nvm command available. | 4 ++++ test/fast/setup | 9 +++++++ test/fast/setup_dir | 9 +++++++ test/fast/teardown | 7 ++++++ test/fast/teardown_dir | 13 ++++++++++ test/slow/install | 14 +++++++++++ 18 files changed, 150 insertions(+), 1 deletion(-) create mode 100755 "test/fast/Aliases/Running \"nvm alias \" should list but one alias." create mode 100755 "test/fast/Aliases/Running \"nvm alias\" should list all aliases." create mode 100755 test/fast/Aliases/setup_dir create mode 100755 "test/fast/Listing versions/Running \"nvm ls 0.2\" should display only 0.2.x versions." create mode 100755 "test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." create mode 100755 "test/fast/Running \"nvm alias\" should create a file in the alias directory." create mode 100755 "test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." create mode 100755 "test/fast/Running \"nvm unalias\" should remove the alias file." create mode 100755 "test/fast/Running \"nvm uninstall\" should remove the appropriate directory." create mode 100755 test/fast/Sourcing nvm.sh should make the nvm command available. create mode 100755 test/fast/setup create mode 100755 test/fast/setup_dir create mode 100755 test/fast/teardown create mode 100755 test/fast/teardown_dir create mode 100755 test/slow/install diff --git a/.gitignore b/.gitignore index d72736e..32d72b6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ HEAD src v* alias + +# For testing +bak +.urchin.log diff --git a/README.markdown b/README.markdown index 938e425..f8c186d 100644 --- a/README.markdown +++ b/README.markdown @@ -57,6 +57,30 @@ 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/0c6837cfbdd0963903bf0463b05160c2aecc22ef/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 + +Nota bene: Avoid running nvm while the tests are running. ## Bash completion 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 diff --git "a/test/fast/Aliases/Running \"nvm alias \" should list but one alias." "b/test/fast/Aliases/Running \"nvm alias \" should list but one alias." new file mode 100755 index 0000000..78d0022 --- /dev/null +++ "b/test/fast/Aliases/Running \"nvm alias \" should list but one alias." @@ -0,0 +1,4 @@ +#!/bin/sh + +. ../../../nvm.sh +[ $(nvm alias test1 | wc -l) = '2' ] diff --git "a/test/fast/Aliases/Running \"nvm alias\" should list all aliases." "b/test/fast/Aliases/Running \"nvm alias\" should list all aliases." new file mode 100755 index 0000000..42b1945 --- /dev/null +++ "b/test/fast/Aliases/Running \"nvm alias\" should list all aliases." @@ -0,0 +1,4 @@ +#!/bin/sh + +. ../../../nvm.sh +[ $(nvm alias | wc -l) = '10' ] diff --git a/test/fast/Aliases/setup_dir b/test/fast/Aliases/setup_dir new file mode 100755 index 0000000..3649602 --- /dev/null +++ b/test/fast/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/Listing versions/Running \"nvm ls 0.2\" should display only 0.2.x versions." "b/test/fast/Listing versions/Running \"nvm ls 0.2\" should display only 0.2.x versions." new file mode 100755 index 0000000..5a3d450 --- /dev/null +++ "b/test/fast/Listing versions/Running \"nvm ls 0.2\" should display only 0.2.x versions." @@ -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/Listing versions/Running \"nvm ls\" should display all installed versions." "b/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." new file mode 100755 index 0000000..dfba0da --- /dev/null +++ "b/test/fast/Listing versions/Running \"nvm ls\" should display all installed 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/Running \"nvm alias\" should create a file in the alias directory." "b/test/fast/Running \"nvm alias\" should create a file in the alias directory." new file mode 100755 index 0000000..0ac4eb2 --- /dev/null +++ "b/test/fast/Running \"nvm alias\" should create a file in the alias directory." @@ -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/Running \"nvm deactivate\" should unset the nvm environment variables." "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." new file mode 100755 index 0000000..1dcef65 --- /dev/null +++ "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." @@ -0,0 +1,6 @@ +#!/bin/sh + +. ../../nvm.sh +nvm && +nvm deactivate && +! nvm diff --git "a/test/fast/Running \"nvm unalias\" should remove the alias file." "b/test/fast/Running \"nvm unalias\" should remove the alias file." new file mode 100755 index 0000000..f8ed49d --- /dev/null +++ "b/test/fast/Running \"nvm unalias\" should remove the alias file." @@ -0,0 +1,6 @@ +#!/bin/sh + +echo v0.1.2 > ../../alias/test +. ../../nvm.sh +nvm unalias test +! [ -e ../../alias/test ] diff --git "a/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." "b/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." new file mode 100755 index 0000000..ba1ddbb --- /dev/null +++ "b/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." @@ -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' ] diff --git a/test/fast/Sourcing nvm.sh should make the nvm command available. b/test/fast/Sourcing nvm.sh should make the nvm command available. new file mode 100755 index 0000000..24f8efa --- /dev/null +++ b/test/fast/Sourcing nvm.sh should make the nvm command available. @@ -0,0 +1,4 @@ +#!/bin/sh + +. ../../nvm.sh +nvm diff --git a/test/fast/setup b/test/fast/setup new file mode 100755 index 0000000..b433b5c --- /dev/null +++ b/test/fast/setup @@ -0,0 +1,9 @@ +#!/bin/sh + +( + cd ../.. + + # Back up + 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 new file mode 100755 index 0000000..954850f --- /dev/null +++ b/test/fast/teardown @@ -0,0 +1,7 @@ +#!/bin/sh + +# Remove temporary files +( + cd ../.. + rm -fR v* src alias +) 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/slow/install b/test/slow/install new file mode 100755 index 0000000..460627b --- /dev/null +++ b/test/slow/install @@ -0,0 +1,14 @@ +#!/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 ] +nvm run v0.6.14 --version | grep v0.6.14