diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index de114cd..04aa3b7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -70,3 +70,12 @@ jobs: - uses: actions/checkout@v6 - name: check tests filenames run: ./rename_test.sh --check + + all: + permissions: + contents: none + name: 'all linting' + needs: [eclint, dockerfile_lint, doctoc, test_naming] + runs-on: ubuntu-latest + steps: + - run: true diff --git a/.github/workflows/nvm-install-test.yml b/.github/workflows/nvm-install-test.yml index 38d026a..73cdced 100644 --- a/.github/workflows/nvm-install-test.yml +++ b/.github/workflows/nvm-install-test.yml @@ -10,6 +10,9 @@ on: required: false default: 'HEAD' +permissions: + contents: read + jobs: matrix: runs-on: ubuntu-latest diff --git a/.github/workflows/tests-fast.yml b/.github/workflows/tests-fast.yml new file mode 100644 index 0000000..af4ee21 --- /dev/null +++ b/.github/workflows/tests-fast.yml @@ -0,0 +1,101 @@ +name: 'Tests: fast' + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + fast: + permissions: + contents: read + + name: 'fast (${{ matrix.shell }}, ${{ matrix.awk }})' + runs-on: ubuntu-latest + defaults: + run: + shell: 'script -q -e -c "${{ matrix.shell }} {0}"' + + strategy: + fail-fast: false + matrix: + shell: + - sh + - bash + - dash + - zsh + # - ksh + awk: + - gawk + - mawk + + steps: + - name: Harden Runner + uses: step-security/harden-runner@v2 + with: + allowed-endpoints: + github.com:443 + registry.npmjs.org:443 + raw.githubusercontent.com:443 + nodejs.org:443 + iojs.org:443 + unofficial-builds.nodejs.org:443 + azure.archive.ubuntu.com:80 + packages.microsoft.com:443 + registry-1.docker.io:443 + auth.docker.io:443 + production.cloudflare.docker.com:443 + - uses: actions/checkout@v6 + with: + submodules: true + - name: Install zsh, additional shells, and awk variant + run: | + sudo apt-get update + sudo apt-get install -y zsh ${{ matrix.awk }} + if [ "${{ matrix.shell }}" != "sh" ] && [ "${{ matrix.shell }}" != "bash" ] && [ "${{ matrix.shell }}" != "zsh" ]; then + sudo apt-get install -y ${{ matrix.shell }} + fi + # Set the selected awk as the default + sudo update-alternatives --set awk /usr/bin/${{ matrix.awk }} + shell: bash + - run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }} + - run: awk --version 2>&1 | head -1 || awk -W version 2>&1 | head -1 + - run: curl --version + - run: wget --version + - uses: ljharb/actions/node/install@main + name: 'npm install && version checks' + with: + node-version: 'lts/*' + skip-ls-check: true + - run: npm ls urchin + - run: npx which urchin + - run: env + - name: Hide system node + run: | + if [ -f /usr/local/bin/node ]; then sudo mv /usr/local/bin/node /usr/local/bin/node.bak; fi + if [ -f /usr/local/bin/npm ]; then sudo mv /usr/local/bin/npm /usr/local/bin/npm.bak; fi + if [ -f /usr/local/bin/npx ]; then sudo mv /usr/local/bin/npx /usr/local/bin/npx.bak; fi + shell: bash + - name: Run fast tests + run: | + URCHIN_PATH="$(npx which urchin)" + unset NVM_CD_FLAGS NVM_BIN NVM_INC + export NVM_DIR="${{ github.workspace }}" + export PATH="$(echo "$PATH" | tr ':' '\n' | grep -v '\.nvm' | grep -v 'toolcache' | tr '\n' ':')" + make TERM=xterm-256color TEST_SUITE="fast" SHELL="${{ matrix.shell }}" URCHIN="$URCHIN_PATH" test-${{ matrix.shell }} + - name: Restore system node + if: always() + run: | + if [ -f /usr/local/bin/node.bak ]; then sudo mv /usr/local/bin/node.bak /usr/local/bin/node; fi + if [ -f /usr/local/bin/npm.bak ]; then sudo mv /usr/local/bin/npm.bak /usr/local/bin/npm; fi + if [ -f /usr/local/bin/npx.bak ]; then sudo mv /usr/local/bin/npx.bak /usr/local/bin/npx; fi + shell: bash + + all: + permissions: + contents: none + name: 'all fast tests' + needs: [fast] + runs-on: ubuntu-latest + steps: + - run: true diff --git a/.github/workflows/tests-installation-iojs.yml b/.github/workflows/tests-installation-iojs.yml new file mode 100644 index 0000000..3d0c37e --- /dev/null +++ b/.github/workflows/tests-installation-iojs.yml @@ -0,0 +1,99 @@ +name: 'Tests: installation_iojs' + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + installation_iojs_without_curl: + permissions: + contents: read + + name: 'installation_iojs without curl (${{ matrix.shell }})' + runs-on: ubuntu-latest + defaults: + run: + shell: 'script -q -e -c "${{ matrix.shell }} {0}"' + + strategy: + fail-fast: false + matrix: + shell: + - sh + - bash + - dash + - zsh + # - ksh + + steps: + - name: Harden Runner + uses: step-security/harden-runner@v2 + with: + allowed-endpoints: + github.com:443 + registry.npmjs.org:443 + raw.githubusercontent.com:443 + nodejs.org:443 + iojs.org:443 + azure.archive.ubuntu.com:80 + packages.microsoft.com:443 + - uses: actions/checkout@v6 + with: + submodules: true + - name: Install zsh and additional shells + run: | + sudo apt-get update + sudo apt-get install -y zsh + if [ "${{ matrix.shell }}" != "sh" ] && [ "${{ matrix.shell }}" != "bash" ] && [ "${{ matrix.shell }}" != "zsh" ]; then + sudo apt-get install -y ${{ matrix.shell }} + fi + shell: bash + - run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }} + - run: wget --version + - uses: ljharb/actions/node/install@main + name: 'npm install && version checks' + with: + node-version: 'lts/*' + skip-ls-check: true + - run: npm ls urchin + - run: npx which urchin + - name: Remove curl + run: sudo apt-get remove curl -y + shell: bash + - run: '! command -v curl' + shell: bash + - run: env + - name: Hide system node + run: | + if [ -f /usr/local/bin/node ]; then sudo mv /usr/local/bin/node /usr/local/bin/node.bak; fi + if [ -f /usr/local/bin/npm ]; then sudo mv /usr/local/bin/npm /usr/local/bin/npm.bak; fi + if [ -f /usr/local/bin/npx ]; then sudo mv /usr/local/bin/npx /usr/local/bin/npx.bak; fi + shell: bash + - name: Run installation_iojs tests + run: | + URCHIN_PATH="$(npx which urchin)" + unset NVM_CD_FLAGS NVM_BIN NVM_INC + export NVM_DIR="${{ github.workspace }}" + export PATH="$(echo "$PATH" | tr ':' '\n' | grep -v '\.nvm' | grep -v 'toolcache' | tr '\n' ':')" + make TERM=xterm-256color TEST_SUITE="installation_iojs" SHELL="${{ matrix.shell }}" URCHIN="$URCHIN_PATH" test-${{ matrix.shell }} + - name: Restore system node + if: always() + run: | + if [ -f /usr/local/bin/node.bak ]; then sudo mv /usr/local/bin/node.bak /usr/local/bin/node; fi + if [ -f /usr/local/bin/npm.bak ]; then sudo mv /usr/local/bin/npm.bak /usr/local/bin/npm; fi + if [ -f /usr/local/bin/npx.bak ]; then sudo mv /usr/local/bin/npx.bak /usr/local/bin/npx; fi + shell: bash + - name: Restore curl + if: always() + run: sudo apt-get install curl -y + shell: bash + + all: + permissions: + contents: none + name: 'all installation_iojs tests' + needs: [installation_iojs_without_curl] + runs-on: ubuntu-latest + steps: + - run: true diff --git a/.github/workflows/tests-installation-node.yml b/.github/workflows/tests-installation-node.yml new file mode 100644 index 0000000..f288634 --- /dev/null +++ b/.github/workflows/tests-installation-node.yml @@ -0,0 +1,122 @@ +name: 'Tests: installation_node' + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + installation_node: + permissions: + contents: read + + name: "installation_node (${{ matrix.shell }}${{ matrix.without_curl && ', without curl' || '' }})" + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + shell: + - sh + - bash + - dash + - zsh + # - ksh + without_curl: + - false + - true + + steps: + - name: Harden Runner + uses: step-security/harden-runner@v2 + with: + allowed-endpoints: + github.com:443 + registry.npmjs.org:443 + raw.githubusercontent.com:443 + nodejs.org:443 + iojs.org:443 + azure.archive.ubuntu.com:80 + packages.microsoft.com:443 + archive.ubuntu.com:80 + security.ubuntu.com:80 + production.cloudflare.docker.com:443 + registry-1.docker.io:443 + auth.docker.io:443 + - uses: actions/checkout@v6 + with: + submodules: true + - uses: ljharb/actions/node/install@main + name: 'npm install && version checks' + with: + node-version: 'lts/*' + skip-ls-check: true + - run: npm ls urchin + - run: npx which urchin + - name: Run installation_node tests in container + run: | + docker run --rm \ + -v "${{ github.workspace }}:/workspace" \ + -w /workspace \ + -e "TEST_SHELL=${{ matrix.shell }}" \ + -e "TERM=xterm-256color" \ + -e "DEBIAN_FRONTEND=noninteractive" \ + -e "GITHUB_ACTIONS=true" \ + -e "WITHOUT_CURL=${{ matrix.without_curl }}" \ + ubuntu:16.04 \ + bash -c ' + set -ex + + # Retry apt-get update up to 5 times due to flaky Ubuntu mirrors + # apt-get update can return 0 even with partial failures, so check for warnings + for i in 1 2 3 4 5; do + if apt-get update 2>&1 | tee /tmp/apt-update.log | grep -qE "^(W:|E:|Err:)"; then + echo "apt-get update had warnings/errors, attempt $i/5" + cat /tmp/apt-update.log + sleep $((i * 5)) + else + break + fi + done + + apt-get install -y git curl wget make build-essential python zsh libssl-dev + if [ "$TEST_SHELL" != "sh" ] && [ "$TEST_SHELL" != "bash" ]; then + apt-get install -y $TEST_SHELL || true + fi + + # Use nvm to install Node.js for running urchin + # Node 16 is the last version supporting GLIBC 2.23 (Ubuntu 16.04) + export NVM_DIR="/workspace" + . /workspace/nvm.sh + nvm install 16 + nvm use 16 + + npm ls urchin + URCHIN_PATH="$(npx which urchin)" + + # Remove curl if testing without it + if [ "$WITHOUT_CURL" = "true" ]; then + apt-get remove curl -y + ! command -v curl + fi + + # Now clean up nvm state for the actual tests, but keep NVM_DIR set + nvm deactivate || true + nvm unalias default || true + unset NVM_CD_FLAGS NVM_BIN NVM_INC + export PATH="$(echo "$PATH" | tr ":" "\n" | grep -v "\.nvm" | grep -v "toolcache" | tr "\n" ":")" + + # Clean any cached files from the nvm install above + rm -rf "$NVM_DIR/.cache" "$NVM_DIR/versions" "$NVM_DIR/alias" + + make TEST_SUITE="installation_node" SHELL="$TEST_SHELL" URCHIN="$URCHIN_PATH" test-$TEST_SHELL + ' + + all: + permissions: + contents: none + name: 'all installation_node tests' + needs: [installation_node] + runs-on: ubuntu-latest + steps: + - run: true diff --git a/.github/workflows/tests-xenial.yml b/.github/workflows/tests-xenial.yml new file mode 100644 index 0000000..474761f --- /dev/null +++ b/.github/workflows/tests-xenial.yml @@ -0,0 +1,112 @@ +name: 'Tests: xenial' + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + xenial: + permissions: + contents: read + + name: 'xenial (${{ matrix.shell }})' + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + shell: + - sh + - bash + - dash + - zsh + # - ksh + + steps: + - name: Harden Runner + uses: step-security/harden-runner@v2 + with: + allowed-endpoints: + github.com:443 + registry.npmjs.org:443 + raw.githubusercontent.com:443 + nodejs.org:443 + iojs.org:443 + azure.archive.ubuntu.com:80 + packages.microsoft.com:443 + archive.ubuntu.com:80 + security.ubuntu.com:80 + production.cloudflare.docker.com:443 + registry-1.docker.io:443 + auth.docker.io:443 + - uses: actions/checkout@v6 + with: + submodules: true + - uses: ljharb/actions/node/install@main + name: 'npm install && version checks' + with: + node-version: 'lts/*' + skip-ls-check: true + - run: npm ls urchin + - run: npx which urchin + - name: Run xenial tests in container + run: | + docker run --rm \ + -v "${{ github.workspace }}:/workspace" \ + -w /workspace \ + -e "TEST_SHELL=${{ matrix.shell }}" \ + -e "TERM=xterm-256color" \ + -e "DEBIAN_FRONTEND=noninteractive" \ + -e "GITHUB_ACTIONS=true" \ + ubuntu:16.04 \ + bash -c ' + set -ex + + # Retry apt-get update up to 5 times due to flaky Ubuntu mirrors + # apt-get update can return 0 even with partial failures, so check for warnings + for i in 1 2 3 4 5; do + if apt-get update 2>&1 | tee /tmp/apt-update.log | grep -qE "^(W:|E:|Err:)"; then + echo "apt-get update had warnings/errors, attempt $i/5" + cat /tmp/apt-update.log + sleep $((i * 5)) + else + break + fi + done + + apt-get install -y git curl wget make build-essential python zsh libssl-dev + if [ "$TEST_SHELL" != "sh" ] && [ "$TEST_SHELL" != "bash" ]; then + apt-get install -y $TEST_SHELL || true + fi + + # Use nvm to install Node.js for running urchin + # Node 16 is the last version supporting GLIBC 2.23 (Ubuntu 16.04) + export NVM_DIR="/workspace" + . /workspace/nvm.sh + nvm install 16 + nvm use 16 + + npm ls urchin + URCHIN_PATH="$(npx which urchin)" + + # Now clean up nvm state for the actual tests, but keep NVM_DIR set + nvm deactivate || true + nvm unalias default || true + unset NVM_CD_FLAGS NVM_BIN NVM_INC + export PATH="$(echo "$PATH" | tr ":" "\n" | grep -v "\.nvm" | grep -v "toolcache" | tr "\n" ":")" + + # Clean any cached files from the nvm install above + rm -rf "$NVM_DIR/.cache" "$NVM_DIR/versions" "$NVM_DIR/alias" + + make TEST_SUITE="xenial" SHELL="$TEST_SHELL" URCHIN="$URCHIN_PATH" test-$TEST_SHELL + ' + + all: + permissions: + contents: none + name: 'all xenial tests' + needs: [xenial] + runs-on: ubuntu-latest + steps: + - run: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8d79d48..3be3016 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,6 +12,7 @@ jobs: name: "tests" runs-on: ubuntu-latest + timeout-minutes: 30 defaults: run: shell: 'script -q -e -c "${{ matrix.shell }} {0}"' @@ -68,7 +69,19 @@ jobs: - run: npm ls urchin - run: npx which urchin - run: env - - run: make TERM=xterm-256color TEST_SUITE="${{ matrix.suite }}" SHELL="${{ matrix.shell }}" URCHIN="$(npx which urchin)" test-${{ matrix.shell }} + - name: Run tests + shell: bash + run: | + for attempt in 1 2 3; do + timeout 600 make TERM=xterm-256color TEST_SUITE="${{ matrix.suite }}" SHELL="${{ matrix.shell }}" URCHIN="$(npx which urchin)" test-${{ matrix.shell }} && exit 0 + EXIT_CODE=$? + if [ $EXIT_CODE -ne 124 ]; then + exit $EXIT_CODE + fi + echo "Attempt ${attempt} timed out; retrying..." + done + echo "All 3 attempts timed out." + exit 1 nvm: permissions: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ed22ae1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,94 +0,0 @@ -language: generic -dist: focal -addons: - apt: - packages: - - zsh - # - ksh - # - gcc-4.8 - # - g++-4.8 - -# https://gist.github.com/iedemam/9830045 -git: - submodules: false - -cache: - ccache: true - directories: - - $TRAVIS_BUILD_DIR/.cache - - $TRAVIS_BUILD_DIR/node_modules -before_install: - - sudo sed -i 's/mozilla\/DST_Root_CA_X3.crt/!mozilla\/DST_Root_CA_X3.crt/g' /etc/ca-certificates.conf - - sudo update-ca-certificates -f - - # https://gist.github.com/iedemam/9830045 - - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules - - git submodule update --init --recursive - - - $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL - - curl --version - - wget --version - - bash --version | head - - zsh --version - - dpkg -s dash | grep ^Version | awk '{print $2}' - # install python - - pyenv local 2.7.18 || pyenv install 2.7.18 - - pyenv local 2.7.18 || echo 'pyenv failed' - - python -V -install: - - if [ -z "${SHELLCHECK-}" ]; then nvm install 16 && nvm unalias default && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi - - '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y' -script: - - if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ] || [ "${TEST_SUITE}" = 'xenial' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi -before_cache: - - if [ -n "$WITHOUT_CURL" ]; then sudo apt-get install curl -y ; fi -jobs: - include: - - env: SHELL=bash TEST_SUITE=installation_node - dist: xenial - - env: SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1 - dist: xenial - - env: SHELL=sh TEST_SUITE=installation_node - dist: xenial - - env: SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1 - dist: xenial - - env: SHELL=dash TEST_SUITE=installation_node - dist: xenial - - env: SHELL=dash TEST_SUITE=installation_node WITHOUT_CURL=1 - dist: xenial - - env: SHELL=zsh TEST_SUITE=installation_node - dist: xenial - - env: SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1 - dist: xenial - #- env: SHELL=ksh TEST_SUITE=installation_node - # dist: xenial - #- env: SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1 - # dist: xenial - - env: SHELL=bash TEST_SUITE=xenial - dist: xenial - - env: SHELL=sh TEST_SUITE=xenial - dist: xenial - - env: SHELL=dash TEST_SUITE=xenial - dist: xenial - - env: SHELL=zsh TEST_SUITE=xenial - dist: xenial - #- env: SHELL=ksh TEST_SUITE=xenial - # dist: xenial -env: - global: - - CXX=g++ - - CC=gcc - - PATH="$(echo $PATH | sed 's/::/:/')" - - PATH="/usr/lib/ccache/:$PATH" - - NVM_DIR="${TRAVIS_BUILD_DIR}" - matrix: - - SHELL=sh TEST_SUITE=fast - - SHELL=dash TEST_SUITE=fast - - SHELL=bash TEST_SUITE=fast - - SHELL=zsh TEST_SUITE=fast - # - SHELL=ksh TEST_SUITE=fast - - SHELL=sh TEST_SUITE=installation_iojs WITHOUT_CURL=1 - - SHELL=dash TEST_SUITE=installation_iojs WITHOUT_CURL=1 - - SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1 - - SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1 - # - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1 diff --git a/.github/copilot-instructions.md b/AGENTS.md similarity index 98% rename from .github/copilot-instructions.md rename to AGENTS.md index 51e63de..7bda90e 100644 --- a/.github/copilot-instructions.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ -# nvm Copilot Instructions +# nvm Coding Agent Instructions -This document provides guidance for GitHub Copilot when working with the Node Version Manager (nvm) codebase. +This document provides guidance for AI coding agents when working with the Node Version Manager (nvm) codebase. ## Overview @@ -424,4 +424,4 @@ nvm works on Windows via several compatibility layers: 2. Include bash, curl, git, tar, and wget packages during installation 3. Run nvm installation in Cygwin terminal -This guide should help GitHub Copilot understand the nvm codebase structure, testing procedures, and development environment setup requirements. +This guide should help AI coding agents understand the nvm codebase structure, testing procedures, and development environment setup requirements. diff --git a/CLAUDE.md b/CLAUDE.md new file mode 120000 index 0000000..47dc3e3 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +AGENTS.md \ No newline at end of file diff --git a/README.md b/README.md index 4a189f3..03f2def 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ -# Node Version Manager [![Build Status](https://app.travis-ci.com/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.40.3-yellow.svg)][4] [![CII Best Practices](https://bestpractices.dev/projects/684/badge)](https://bestpractices.dev/projects/684) +# Node Version Manager [![Tests](https://github.com/nvm-sh/nvm/actions/workflows/tests-fast.yml/badge.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.40.4-yellow.svg)][4] [![CII Best Practices](https://bestpractices.dev/projects/684/badge)](https://bestpractices.dev/projects/684) @@ -104,10 +104,10 @@ nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be i To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command: ```sh -curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash ``` ```sh -wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash +wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash ``` Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bashrc`, `~/.bash_profile`, `~/.zshrc`, or `~/.profile`). If you find the install script is updating the wrong profile file, set the `$PROFILE` env var to the profile file’s path, and then rerun the installation script. @@ -134,7 +134,7 @@ Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not conta - The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available. -- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash'` +- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash'` #### Installing in Docker @@ -150,7 +150,7 @@ RUN touch "${BASH_ENV}" RUN echo '. "${BASH_ENV}"' >> ~/.bashrc # Download and install nvm -RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | PROFILE="${BASH_ENV}" bash +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | PROFILE="${BASH_ENV}" bash RUN echo node > .nvmrc RUN nvm install ``` @@ -168,7 +168,7 @@ ARG NODE_VERSION=20 RUN apt update && apt install curl -y # install nvm -RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash # set env ENV NVM_DIR=/root/.nvm @@ -194,7 +194,7 @@ After creation of the image you can start container interactively and run comman docker run --rm -it nvmimage root@0a6b5a237c14:/# nvm -v -0.40.3 +0.40.4 root@0a6b5a237c14:/# node -v v19.9.0 @@ -257,7 +257,7 @@ You can use a task: ```yaml - name: Install nvm ansible.builtin.shell: > - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash args: creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh" ``` @@ -319,7 +319,7 @@ If you have `git` installed (requires git v1.7.10+): 1. clone this repo in the root of your user profile - `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm` -1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.3` +1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.4` 1. activate `nvm` by sourcing it from your shell: `. ./nvm.sh` Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login: @@ -928,13 +928,13 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh ### Alpine Linux 3.13+ ```sh apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils -curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash ``` ### Alpine Linux 3.5 - 3.12 ```sh apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils -curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash ``` _Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package `python2` to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._ @@ -1037,9 +1037,9 @@ You have to make sure that the user directory name in `$HOME` and the user direc To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548) [1]: https://github.com/nvm-sh/nvm.git -[2]: https://github.com/nvm-sh/nvm/blob/v0.40.3/install.sh -[3]: https://app.travis-ci.com/nvm-sh/nvm -[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.3 +[2]: https://github.com/nvm-sh/nvm/blob/v0.40.4/install.sh +[3]: https://github.com/nvm-sh/nvm/actions/workflows/tests-fast.yml +[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.4 [Urchin]: https://git.sdf.org/tlevine/urchin [Fish]: https://fishshell.com @@ -1097,7 +1097,7 @@ Here's what you will need to do: If one of these broken versions is installed on your system, the above step will likely still succeed even if you didn't include the `--shared-zlib` flag. However, later, when you attempt to `npm install` something using your old version of node.js, you will see `incorrect data check` errors. If you want to avoid the possible hassle of dealing with this, include that flag. - For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.376) + For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.476) - Exit back to your native shell. @@ -1124,7 +1124,7 @@ Now you should be able to use node as usual. If you've encountered this error on WSL-2: ```sh - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com @@ -1159,7 +1159,7 @@ Currently, the sole maintainer is [@ljharb](https://github.com/ljharb) - more ma ## Project Support -Only the latest version (v0.40.3 at this time) is supported. +Only the latest version (v0.40.4 at this time) is supported. ## Enterprise Support diff --git a/install.sh b/install.sh index 6e1b2e9..04d75ce 100755 --- a/install.sh +++ b/install.sh @@ -33,7 +33,7 @@ nvm_install_dir() { } nvm_latest_version() { - nvm_echo "v0.40.3" + nvm_echo "v0.40.4" } nvm_profile_is_bash_or_zsh() { diff --git a/nvm.sh b/nvm.sh index f5507d5..180828d 100755 --- a/nvm.sh +++ b/nvm.sh @@ -83,7 +83,7 @@ nvm_has_colors() { if nvm_has tput; then NVM_NUM_COLORS="$(command tput -T "${TERM:-vt100}" colors)" fi - [ "${NVM_NUM_COLORS:--1}" -ge 8 ] && [ "${NVM_NO_COLORS-}" != '--no-colors' ] + [ -t 1 ] && [ "${NVM_NUM_COLORS:--1}" -ge 8 ] && [ "${NVM_NO_COLORS-}" != '--no-colors' ] } nvm_curl_libz_support() { @@ -149,7 +149,8 @@ nvm_download() { ") if [ -n "${NVM_AUTH_HEADER:-}" ]; then - ARGS="${ARGS} --header \"${NVM_AUTH_HEADER}\"" + sanitized_header=$(nvm_sanitize_auth_header "${NVM_AUTH_HEADER}") + ARGS="${ARGS} --header \"${sanitized_header}\"" fi # shellcheck disable=SC2086 eval wget $ARGS @@ -758,6 +759,11 @@ nvm_version() { ;; esac VERSION="$(nvm_ls "${PATTERN}" | command tail -1)" + case "${VERSION}" in + system[[:blank:]]*) + VERSION='system' + ;; + esac if [ -z "${VERSION}" ] || [ "_${VERSION}" = "_N/A" ]; then nvm_echo "N/A" return 3 @@ -978,13 +984,18 @@ nvm_strip_path() { nvm_err '${NVM_DIR} not set!' return 1 fi - command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: ' + local RESULT + RESULT="$(command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: ' index($0, NVM_DIR) == 1 { path = substr($0, length(NVM_DIR) + 1) if (path ~ "^(/versions/[^/]*)?/[^/]*'"${2-}"'.*$") { next } } - # The final RT will contain a colon if the input has a trailing colon, or a null string otherwise - { printf "%s%s", sep, $0; sep=RS } END { printf "%s", RT }' + { printf "%s%s", sep, $0; sep=RS }')" + # mawk does not support RT, so preserve trailing colon manually + case "${1-}" in + *:) command printf '%s:' "${RESULT}" ;; + *) command printf '%s' "${RESULT}" ;; + esac } nvm_change_path() { @@ -1457,6 +1468,18 @@ nvm_ls() { PATTERN="${PATTERN}-" ;; *) + local ALIAS_TARGET + ALIAS_TARGET="$(nvm_resolve_alias "${PATTERN}" 2>/dev/null || nvm_echo)" + if [ "_${ALIAS_TARGET}" = '_system' ] && (nvm_has_system_iojs || nvm_has_system_node); then + local SYSTEM_VERSION + SYSTEM_VERSION="$(nvm deactivate >/dev/null 2>&1 && node -v 2>/dev/null)" + if [ -n "${SYSTEM_VERSION}" ]; then + nvm_echo "system ${SYSTEM_VERSION}" + else + nvm_echo "system" + fi + return + fi if nvm_resolve_local_alias "${PATTERN}"; then return fi @@ -1560,13 +1583,24 @@ nvm_ls() { fi if [ "${NVM_ADD_SYSTEM-}" = true ]; then + local SYSTEM_VERSION + SYSTEM_VERSION="$(nvm deactivate >/dev/null 2>&1 && node -v 2>/dev/null)" case "${PATTERN}" in '' | v) - VERSIONS="${VERSIONS} + if [ -n "${SYSTEM_VERSION}" ]; then + VERSIONS="${VERSIONS} +system ${SYSTEM_VERSION}" + else + VERSIONS="${VERSIONS} system" + fi ;; system) - VERSIONS="system" + if [ -n "${SYSTEM_VERSION}" ]; then + VERSIONS="system ${SYSTEM_VERSION}" + else + VERSIONS="system" + fi ;; esac fi @@ -1908,6 +1942,7 @@ BEGIN { fmt_latest_lts = has_colors && latest_lts_color ? ("\033[" latest_lts_color " (Latest LTS: %s)\033[0m") : " (Latest LTS: %s)"; fmt_old_lts = has_colors && old_lts_color ? ("\033[" old_lts_color " (LTS: %s)\033[0m") : " (LTS: %s)"; + fmt_system_target = has_colors && system_color ? (" (\033[" system_color "-> %s\033[0m)") : " (-> %s)"; split(remote_versions, lines, "|"); split(installed_versions, installed, "|"); @@ -1939,6 +1974,8 @@ BEGIN { if (cols == 1) { formatted = sprintf(fmt_version, version); + } else if (version == "system" && cols >= 2) { + formatted = sprintf((fmt_version fmt_system_target), version, fields[2]); } else if (cols == 2) { formatted = sprintf((fmt_version padding fmt_old_lts), version, fields[2]); } else if (cols == 3 && fields[3] == "*") { @@ -2642,18 +2679,24 @@ nvm_install_source() { NVM_OS="$(nvm_get_os)" local make - make='make' local MAKE_CXX + # For old Node.js versions (< 0.12), explicitly set SHELL=/bin/sh to avoid + # issues with zsh's strict glob handling in Makefiles with unquoted globs + local MAKE_SHELL_OVERRIDE + if nvm_version_greater "0.12.0" "${VERSION}"; then + MAKE_SHELL_OVERRIDE=' SHELL=/bin/sh' + fi + make="make${MAKE_SHELL_OVERRIDE-}" case "${NVM_OS}" in 'freebsd' | 'openbsd') - make='gmake' + make="gmake${MAKE_SHELL_OVERRIDE-}" MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}" ;; 'darwin') MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}" ;; 'aix') - make='gmake' + make="gmake${MAKE_SHELL_OVERRIDE-}" ;; esac if nvm_has "clang++" && nvm_has "clang" && nvm_version_greater_than_or_equal_to "$(nvm_clang_version)" 3.5; then @@ -3708,7 +3751,13 @@ nvm() { fi if ! nvm_is_version_installed "${VERSION}"; then - nvm_err "${VERSION} version is not installed..." + local REQUESTED_VERSION + REQUESTED_VERSION="${PATTERN}" + if [ "_${VERSION}" != "_N/A" ] && [ "_${VERSION}" != "_${PATTERN}" ]; then + nvm_err "Version '${VERSION}' (inferred from ${PATTERN}) is not installed." + else + nvm_err "Version '${REQUESTED_VERSION}' is not installed." + fi return fi @@ -4448,7 +4497,7 @@ nvm() { NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}" ;; "--version" | "-v") - nvm_echo '0.40.3' + nvm_echo '0.40.4' ;; "unload") nvm deactivate >/dev/null 2>&1 @@ -4524,9 +4573,9 @@ nvm_get_default_packages() { NVM_DEFAULT_PACKAGE_FILE="${NVM_DIR}/default-packages" if [ -f "${NVM_DEFAULT_PACKAGE_FILE}" ]; then command awk -v filename="${NVM_DEFAULT_PACKAGE_FILE}" ' - /^[[:space:]]*#/ { next } # Skip lines that begin with # - /^[[:space:]]*$/ { next } # Skip empty lines - /[[:space:]]/ && !/^[[:space:]]*#/ { + /^[ \t]*#/ { next } # Skip lines that begin with # + /^[ \t]*$/ { next } # Skip empty lines + /[ \t]/ && !/^[ \t]*#/ { print "Only one package per line is allowed in `" filename "`. Please remove any lines with multiple space-separated values." > "/dev/stderr" err = 1 exit 1 diff --git a/package.json b/package.json index c3815fe..2f2b4f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nvm", - "version": "0.40.3", + "version": "0.40.4", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "directories": { "test": "test" diff --git a/test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file b/test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file index 3fe5784..38bd1cc 100755 --- a/test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file +++ b/test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file @@ -4,6 +4,7 @@ die() { echo "$@" ; exit 1; } export NVM_DIR="$(cd ../../.. && pwd)" +: nvm.sh \. "${NVM_DIR}/nvm.sh" \. ../../common.sh diff --git a/test/fast/Aliases/'nvm alias' should not accept aliases with a hash b/test/fast/Aliases/'nvm alias' should not accept aliases with a hash index 3922ea7..a172a25 100755 --- a/test/fast/Aliases/'nvm alias' should not accept aliases with a hash +++ b/test/fast/Aliases/'nvm alias' should not accept aliases with a hash @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { echo "$@" ; exit 1; } diff --git a/test/fast/Aliases/'nvm alias' should not accept aliases with slashes b/test/fast/Aliases/'nvm alias' should not accept aliases with slashes index d10937d..53fc70e 100755 --- a/test/fast/Aliases/'nvm alias' should not accept aliases with slashes +++ b/test/fast/Aliases/'nvm alias' should not accept aliases with slashes @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { echo "$@" ; exit 1; } diff --git a/test/fast/Aliases/'nvm unalias' should accept aliases when they shadow a built-in alias b/test/fast/Aliases/'nvm unalias' should accept aliases when they shadow a built-in alias index d88a4fa..ff69208 100755 --- a/test/fast/Aliases/'nvm unalias' should accept aliases when they shadow a built-in alias +++ b/test/fast/Aliases/'nvm unalias' should accept aliases when they shadow a built-in alias @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { echo "$@" ; exit 1; } diff --git a/test/fast/Aliases/'nvm unalias' should not accept aliases with names equal to built-in alias b/test/fast/Aliases/'nvm unalias' should not accept aliases with names equal to built-in alias index 35bdc8f..a2dbad1 100755 --- a/test/fast/Aliases/'nvm unalias' should not accept aliases with names equal to built-in alias +++ b/test/fast/Aliases/'nvm unalias' should not accept aliases with names equal to built-in alias @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { echo "$@" ; exit 1; } diff --git a/test/fast/Aliases/'nvm unalias' should not accept aliases with slashes b/test/fast/Aliases/'nvm unalias' should not accept aliases with slashes index 2afafad..5e5fb52 100755 --- a/test/fast/Aliases/'nvm unalias' should not accept aliases with slashes +++ b/test/fast/Aliases/'nvm unalias' should not accept aliases with slashes @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { echo "$@" ; exit 1; } diff --git a/test/fast/Aliases/Running 'nvm alias ˂aliasname˃ ˂target˃' again should change the target b/test/fast/Aliases/Running 'nvm alias ˂aliasname˃ ˂target˃' again should change the target index f366beb..c486188 100755 --- a/test/fast/Aliases/Running 'nvm alias ˂aliasname˃ ˂target˃' again should change the target +++ b/test/fast/Aliases/Running 'nvm alias ˂aliasname˃ ˂target˃' again should change the target @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh @@ -14,11 +15,11 @@ fi nvm alias test-stable-1 0.0.2 || die '`nvm alias test-stable-1 0.0.2` failed' OUTPUT="$(nvm alias test-stable-1 | strip_colors)" -EXPECTED_OUTPUT='test-stable-1 -> 0.0.2 (-> v0.0.2)' +EXPECTED_OUTPUT='test-stable-1 -> 0.0.2 (-> v0.0.2 *)' echo "$OUTPUT" | \grep -F "$EXPECTED_OUTPUT" || die "nvm alias test-stable-1 0.0.2 did not set test-stable-1 to 0.0.2: got '$OUTPUT'" nvm alias test-stable-1 0.0.1 || die '`nvm alias test-stable-1 0.0.1` failed' OUTPUT="$(nvm alias test-stable-1 | strip_colors)" -EXPECTED_OUTPUT='test-stable-1 -> 0.0.1 (-> v0.0.1)' +EXPECTED_OUTPUT='test-stable-1 -> 0.0.1 (-> v0.0.1 *)' echo "$OUTPUT" | \grep -F "$EXPECTED_OUTPUT" || die "nvm alias test-stable-1 0.0.1 did not set test-stable-1 to 0.0.1: got '$OUTPUT'" diff --git a/test/fast/Aliases/Running 'nvm alias ˂aliasname˃' should list but one alias b/test/fast/Aliases/Running 'nvm alias ˂aliasname˃' should list but one alias index 7ba4c38..2ad01ec 100755 --- a/test/fast/Aliases/Running 'nvm alias ˂aliasname˃' should list but one alias +++ b/test/fast/Aliases/Running 'nvm alias ˂aliasname˃' should list but one alias @@ -1,4 +1,5 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh [ $(nvm alias test-stable-1 | wc -l) = '2' ] diff --git a/test/fast/Aliases/Running 'nvm alias' lists implicit aliases when they do not exist b/test/fast/Aliases/Running 'nvm alias' lists implicit aliases when they do not exist index 24a341c..2452b78 100755 --- a/test/fast/Aliases/Running 'nvm alias' lists implicit aliases when they do not exist +++ b/test/fast/Aliases/Running 'nvm alias' lists implicit aliases when they do not exist @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh @@ -9,18 +10,18 @@ NVM_ALIAS_OUTPUT=$(nvm alias | strip_colors) EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" -echo "$NVM_ALIAS_OUTPUT" | \grep -F "stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)" \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F "stable -> $EXPECTED_STABLE (-> $STABLE_VERSION *) (default)" \ || die "nvm alias did not contain the default local stable node version; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F "node -> stable (-> $STABLE_VERSION) (default)" \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F "node -> stable (-> $STABLE_VERSION *) (default)" \ || die "nvm alias did not contain the default local stable node version under 'node'; got '$NVM_ALIAS_OUTPUT'" EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" -echo "$NVM_ALIAS_OUTPUT" | \grep -F "unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)" \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F "unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION *) (default)" \ || die "nvm alias did not contain the default local unstable node version; got '$NVM_ALIAS_OUTPUT'" EXPECTED_IOJS="$(nvm_print_implicit_alias local iojs)" IOJS_VERSION="$(nvm_version "$EXPECTED_IOJS")" -echo "$NVM_ALIAS_OUTPUT" | \grep -F "iojs -> $EXPECTED_IOJS (-> $IOJS_VERSION) (default)" \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F "iojs -> $EXPECTED_IOJS (-> $IOJS_VERSION *) (default)" \ || die "nvm alias did not contain the default local iojs version; got '$NVM_ALIAS_OUTPUT'" diff --git a/test/fast/Aliases/Running 'nvm alias' lists manual aliases instead of implicit aliases when present b/test/fast/Aliases/Running 'nvm alias' lists manual aliases instead of implicit aliases when present index 1857f44..99c2747 100755 --- a/test/fast/Aliases/Running 'nvm alias' lists manual aliases instead of implicit aliases when present +++ b/test/fast/Aliases/Running 'nvm alias' lists manual aliases instead of implicit aliases when present @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh @@ -34,16 +35,16 @@ nvm alias iojs unstable NVM_ALIAS_OUTPUT=$(nvm alias | strip_colors) -echo "$NVM_ALIAS_OUTPUT" | command grep -F "stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)" \ +echo "$NVM_ALIAS_OUTPUT" | command grep -F "stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION *)" \ || die "nvm alias did not contain the overridden 'stable' alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | command grep -F "unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)" \ +echo "$NVM_ALIAS_OUTPUT" | command grep -F "unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION *)" \ || die "nvm alias did not contain the overridden 'unstable' alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | command grep -F "node -> stable (-> $UNSTABLE_VERSION)" \ +echo "$NVM_ALIAS_OUTPUT" | command grep -F "node -> stable (-> $UNSTABLE_VERSION *)" \ || die "nvm alias did not contain the overridden 'node' alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | command grep -F "iojs -> unstable (-> $STABLE_VERSION)" \ +echo "$NVM_ALIAS_OUTPUT" | command grep -F "iojs -> unstable (-> $STABLE_VERSION *)" \ || die "nvm alias did not contain the overridden 'iojs' alias; got '$NVM_ALIAS_OUTPUT'" cleanup diff --git a/test/fast/Aliases/Running 'nvm alias' should list all aliases b/test/fast/Aliases/Running 'nvm alias' should list all aliases index d620fe5..cf90648 100755 --- a/test/fast/Aliases/Running 'nvm alias' should list all aliases +++ b/test/fast/Aliases/Running 'nvm alias' should list all aliases @@ -1,48 +1,49 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh die () { echo "$@" ; exit 1; } NVM_ALIAS_OUTPUT="$(nvm alias | strip_colors)" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-1 -> 0.0.1 (-> v0.0.1)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-1 -> 0.0.1 (-> v0.0.1 *)' \ || die "did not find test-stable-1 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-2 -> 0.0.2 (-> v0.0.2)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-2 -> 0.0.2 (-> v0.0.2 *)' \ || die "did not find test-stable-2 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-3 -> 0.0.3 (-> v0.0.3)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-3 -> 0.0.3 (-> v0.0.3 *)' \ || die "did not find test-stable-3 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-4 -> 0.0.4 (-> v0.0.4)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-4 -> 0.0.4 (-> v0.0.4 *)' \ || die "did not find test-stable-4 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-5 -> 0.0.5 (-> v0.0.5)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-5 -> 0.0.5 (-> v0.0.5 *)' \ || die "did not find test-stable-5 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-6 -> 0.0.6 (-> v0.0.6)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-6 -> 0.0.6 (-> v0.0.6 *)' \ || die "did not find test-stable-6 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-7 -> 0.0.7 (-> v0.0.7)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-7 -> 0.0.7 (-> v0.0.7 *)' \ || die "did not find test-stable-7 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-8 -> 0.0.8 (-> v0.0.8)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-8 -> 0.0.8 (-> v0.0.8 *)' \ || die "did not find test-stable-8 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-9 -> 0.0.9 (-> v0.0.9)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-9 -> 0.0.9 (-> v0.0.9 *)' \ || die "did not find test-stable-9 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-10 -> 0.0.10 (-> v0.0.10)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-10 -> 0.0.10 (-> v0.0.10 *)' \ || die "did not find test-stable-10 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-1 -> 0.1.1 (-> v0.1.1)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-1 -> 0.1.1 (-> v0.1.1 *)' \ || die "did not find test-unstable-1 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-2 -> 0.1.2 (-> v0.1.2)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-2 -> 0.1.2 (-> v0.1.2 *)' \ || die "did not find test-unstable-2 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-3 -> 0.1.3 (-> v0.1.3)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-3 -> 0.1.3 (-> v0.1.3 *)' \ || die "did not find test-unstable-3 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-4 -> 0.1.4 (-> v0.1.4)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-4 -> 0.1.4 (-> v0.1.4 *)' \ || die "did not find test-unstable-4 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-5 -> 0.1.5 (-> v0.1.5)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-5 -> 0.1.5 (-> v0.1.5 *)' \ || die "did not find test-unstable-5 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-6 -> 0.1.6 (-> v0.1.6)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-6 -> 0.1.6 (-> v0.1.6 *)' \ || die "did not find test-unstable-6 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-7 -> 0.1.7 (-> v0.1.7)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-7 -> 0.1.7 (-> v0.1.7 *)' \ || die "did not find test-unstable-7 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-8 -> 0.1.8 (-> v0.1.8)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-8 -> 0.1.8 (-> v0.1.8 *)' \ || die "did not find test-unstable-8 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-9 -> 0.1.9 (-> v0.1.9)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-9 -> 0.1.9 (-> v0.1.9 *)' \ || die "did not find test-unstable-9 alias; got '$NVM_ALIAS_OUTPUT'" -echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-10 -> 0.1.10 (-> v0.1.10)' \ +echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-10 -> 0.1.10 (-> v0.1.10 *)' \ || die "did not find test-unstable-10 alias; got '$NVM_ALIAS_OUTPUT'" diff --git a/test/fast/Aliases/circular/nvm_resolve_alias b/test/fast/Aliases/circular/nvm_resolve_alias index ee772bb..37f9ca2 100755 --- a/test/fast/Aliases/circular/nvm_resolve_alias +++ b/test/fast/Aliases/circular/nvm_resolve_alias @@ -3,6 +3,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../../nvm.sh ALIAS="$(nvm_resolve_alias loopback | strip_colors)" diff --git a/test/fast/Aliases/circular/nvm_resolve_local_alias b/test/fast/Aliases/circular/nvm_resolve_local_alias index 0d4b200..acb0c75 100755 --- a/test/fast/Aliases/circular/nvm_resolve_local_alias +++ b/test/fast/Aliases/circular/nvm_resolve_local_alias @@ -3,6 +3,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../../nvm.sh ALIAS="$(nvm_resolve_local_alias loopback | strip_colors)" diff --git a/test/fast/Aliases/lts/'nvm alias' should ensure LTS alias dir exists b/test/fast/Aliases/lts/'nvm alias' should ensure LTS alias dir exists index f6f3960..ff2baef 100755 --- a/test/fast/Aliases/lts/'nvm alias' should ensure LTS alias dir exists +++ b/test/fast/Aliases/lts/'nvm alias' should ensure LTS alias dir exists @@ -2,6 +2,7 @@ set -ex +: nvm.sh \. ../../../../nvm.sh \. ../../../common.sh diff --git a/test/fast/Aliases/lts/setup_dir b/test/fast/Aliases/lts/setup_dir index 4aeb067..cf96db6 100755 --- a/test/fast/Aliases/lts/setup_dir +++ b/test/fast/Aliases/lts/setup_dir @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../../nvm.sh LTS_ALIAS_PATH="$(nvm_alias_path)/lts" diff --git a/test/fast/Aliases/lts/teardown_dir b/test/fast/Aliases/lts/teardown_dir index 18863f4..cf3581b 100755 --- a/test/fast/Aliases/lts/teardown_dir +++ b/test/fast/Aliases/lts/teardown_dir @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../../nvm.sh LTS_ALIAS_PATH="$(nvm_alias_path)/lts" diff --git a/test/fast/Aliases/nvm_ensure_default_set b/test/fast/Aliases/nvm_ensure_default_set index 7e7dab8..40e217a 100755 --- a/test/fast/Aliases/nvm_ensure_default_set +++ b/test/fast/Aliases/nvm_ensure_default_set @@ -4,6 +4,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh nvm alias default 0.1 >/dev/null || die "'nvm alias default 0.1' failed" @@ -13,7 +14,7 @@ nvm_ensure_default_set 0.3 || die "'nvm_ensure_default_set' with an existing def nvm unalias default || die "'nvm unalias default' failed" OUTPUT="$(nvm_ensure_default_set 0.2)" -EXPECTED_OUTPUT="Creating default alias: default -> 0.2 (-> iojs-v0.2.10)" +EXPECTED_OUTPUT="Creating default alias: default -> 0.2 (-> iojs-v0.2.10 *)" EXIT_CODE="$?" [ "_$(echo "$OUTPUT" | strip_colors)" = "_$EXPECTED_OUTPUT" ] || die "'nvm_ensure_default_set 0.2' did not output '$EXPECTED_OUTPUT', got '$OUTPUT'" diff --git a/test/fast/Aliases/nvm_list_aliases calls nvm_get_colors b/test/fast/Aliases/nvm_list_aliases calls nvm_get_colors index 21e5127..730700c 100755 --- a/test/fast/Aliases/nvm_list_aliases calls nvm_get_colors +++ b/test/fast/Aliases/nvm_list_aliases calls nvm_get_colors @@ -1,11 +1,14 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { echo "$@" ; exit 1; } set -e +nvm_has_colors() { return 0; } + nvm_get_colors(){ echo "0;95m" } diff --git a/test/fast/Aliases/nvm_list_aliases works with LTS aliases b/test/fast/Aliases/nvm_list_aliases works with LTS aliases index 6af1828..75e8884 100755 --- a/test/fast/Aliases/nvm_list_aliases works with LTS aliases +++ b/test/fast/Aliases/nvm_list_aliases works with LTS aliases @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { diff --git a/test/fast/Aliases/nvm_list_aliases works with no LTS aliases present b/test/fast/Aliases/nvm_list_aliases works with no LTS aliases present index 337d1d1..6a2a25f 100755 --- a/test/fast/Aliases/nvm_list_aliases works with no LTS aliases present +++ b/test/fast/Aliases/nvm_list_aliases works with no LTS aliases present @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { diff --git a/test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors b/test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors index 2c49b2a..69bc4db 100755 --- a/test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors +++ b/test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { @@ -10,6 +11,8 @@ die () { set -e +nvm_has_colors() { return 0; } + nvm_get_colors(){ echo "0;95m" } diff --git a/test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors b/test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors index 7f82769..c4ee469 100755 --- a/test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors +++ b/test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { @@ -8,6 +9,9 @@ die () { } set -e + +nvm_has_colors() { return 0; } + # # # expecting in red and two grays: OUTPUT=$(echo $(nvm_print_formatted_alias fakealias fakedest) | awk '{ print substr($0, 1, 21); }') EXPECTED_OUTPUT="$(command printf %b "\033[0;31mfakealias\033[0m ")" diff --git a/test/fast/Aliases/nvm_resolve_alias b/test/fast/Aliases/nvm_resolve_alias index 307c3cb..960c92b 100755 --- a/test/fast/Aliases/nvm_resolve_alias +++ b/test/fast/Aliases/nvm_resolve_alias @@ -4,6 +4,7 @@ die () { echo "$@" ; exit 1; } export NVM_DIR="$(cd ../../.. && pwd)" +: nvm.sh \. "${NVM_DIR}/nvm.sh" EXIT_CODE=$(nvm_resolve_alias ; echo $?) diff --git a/test/fast/Aliases/nvm_resolve_local_alias b/test/fast/Aliases/nvm_resolve_local_alias index 06f4374..db6a5d3 100755 --- a/test/fast/Aliases/nvm_resolve_local_alias +++ b/test/fast/Aliases/nvm_resolve_local_alias @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh EXIT_CODE=$(nvm_resolve_local_alias ; echo $?) diff --git a/test/fast/Aliases/setup b/test/fast/Aliases/setup index 9b82259..9b07b5a 100755 --- a/test/fast/Aliases/setup +++ b/test/fast/Aliases/setup @@ -2,6 +2,7 @@ export NVM_DIR="$(cd ../../.. && pwd)" +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing paths/Running 'nvm which 0.0.2' should display only version 0.0.2 b/test/fast/Listing paths/Running 'nvm which 0.0.2' should display only version 0.0.2 index 1f4eb11..24ea621 100755 --- a/test/fast/Listing paths/Running 'nvm which 0.0.2' should display only version 0.0.2 +++ b/test/fast/Listing paths/Running 'nvm which 0.0.2' should display only version 0.0.2 @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing paths/Running 'nvm which foo' should return a nonzero exit code when not found b/test/fast/Listing paths/Running 'nvm which foo' should return a nonzero exit code when not found index c0218a0..0df7da6 100755 --- a/test/fast/Listing paths/Running 'nvm which foo' should return a nonzero exit code when not found +++ b/test/fast/Listing paths/Running 'nvm which foo' should return a nonzero exit code when not found @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh nvm which nonexistent_version diff --git a/test/fast/Listing paths/Running 'nvm which' should respect alias pointing to system b/test/fast/Listing paths/Running 'nvm which' should respect alias pointing to system new file mode 100755 index 0000000..e50a270 --- /dev/null +++ b/test/fast/Listing paths/Running 'nvm which' should respect alias pointing to system @@ -0,0 +1,36 @@ +#!/bin/sh + +set -ex + +die () { echo "$@" ; cleanup ; exit 1; } +cleanup() { + rm -f "$(nvm_alias_path)/default" + if [ -n "${SYSTEM_DIR-}" ]; then + rm -rf "${SYSTEM_DIR}" + fi + if [ -n "${ORIG_PATH-}" ]; then + PATH="${ORIG_PATH}" + fi +} + +\. ../../../nvm.sh + +nvm_make_alias default system + +ORIG_PATH="${PATH}" +SYSTEM_DIR="$(mktemp -d)" +cat > "${SYSTEM_DIR}/node" <<'EOF' +#!/bin/sh +echo v0.0.0 +EOF +chmod +x "${SYSTEM_DIR}/node" +PATH="${SYSTEM_DIR}:${PATH}" +export PATH + +EXPECTED_OUTPUT="$(command which node)" +set +ex # since stderr is needed +OUTPUT="$(nvm which default 2>&1)" +set -ex +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system via alias for nvm which. Got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +cleanup diff --git a/test/fast/Listing versions/Running 'nvm ls --no-alias' does not call into nvm_alias b/test/fast/Listing versions/Running 'nvm ls --no-alias' does not call into nvm_alias index 20e28ec..50d2ad9 100755 --- a/test/fast/Listing versions/Running 'nvm ls --no-alias' does not call into nvm_alias +++ b/test/fast/Listing versions/Running 'nvm ls --no-alias' does not call into nvm_alias @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls --no-alias' with a pattern errors b/test/fast/Listing versions/Running 'nvm ls --no-alias' with a pattern errors index 6f5a809..38d0c5f 100755 --- a/test/fast/Listing versions/Running 'nvm ls --no-alias' with a pattern errors +++ b/test/fast/Listing versions/Running 'nvm ls --no-alias' with a pattern errors @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls 0.0.2' should display only version 0.0.2 b/test/fast/Listing versions/Running 'nvm ls 0.0.2' should display only version 0.0.2 index 666a3f0..963ea50 100755 --- a/test/fast/Listing versions/Running 'nvm ls 0.0.2' should display only version 0.0.2 +++ b/test/fast/Listing versions/Running 'nvm ls 0.0.2' should display only version 0.0.2 @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh 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 index b02efa3..d1377ac 100755 --- 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 @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls default' should show system version when available b/test/fast/Listing versions/Running 'nvm ls default' should show system version when available new file mode 100755 index 0000000..1fb0166 --- /dev/null +++ b/test/fast/Listing versions/Running 'nvm ls default' should show system version when available @@ -0,0 +1,22 @@ +#!/bin/sh + +die () { echo "$@" ; cleanup ; exit 1; } +cleanup () { + rm -f "$(nvm_alias_path)/default" + unset -f nvm_has_system_node node +} + +\. ../../../nvm.sh +\. ../../common.sh + +nvm_make_alias default system +nvm_has_system_node() { return 0; } +node() { command printf 'v0.0.0'; } + +OUTPUT="$(nvm ls default | strip_colors)" +echo "${OUTPUT}" | command grep -q 'system' \ + || die "Could not list system via alias. Got >${OUTPUT}<" +echo "${OUTPUT}" | command grep -q 'v0.0.0' \ + || die "Could not list system version via alias. Got >${OUTPUT}<" + +cleanup diff --git a/test/fast/Listing versions/Running 'nvm ls foo' should return a nonzero exit code when not found b/test/fast/Listing versions/Running 'nvm ls foo' should return a nonzero exit code when not found index 74a97b4..fc0a22d 100755 --- a/test/fast/Listing versions/Running 'nvm ls foo' should return a nonzero exit code when not found +++ b/test/fast/Listing versions/Running 'nvm ls foo' should return a nonzero exit code when not found @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh nvm ls nonexistent_version diff --git a/test/fast/Listing versions/Running 'nvm ls io' should return NA b/test/fast/Listing versions/Running 'nvm ls io' should return NA index 79dccfe..4632fc1 100755 --- a/test/fast/Listing versions/Running 'nvm ls io' should return NA +++ b/test/fast/Listing versions/Running 'nvm ls io' should return NA @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh nvm ls io diff --git a/test/fast/Listing versions/Running 'nvm ls node_' should return a nonzero exit code when not found b/test/fast/Listing versions/Running 'nvm ls node_' should return a nonzero exit code when not found index af79302..fbf60a4 100755 --- a/test/fast/Listing versions/Running 'nvm ls node_' should return a nonzero exit code when not found +++ b/test/fast/Listing versions/Running 'nvm ls node_' should return a nonzero exit code when not found @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh nvm ls node_ diff --git a/test/fast/Listing versions/Running 'nvm ls stable' and 'nvm ls unstable' should return the appropriate implicit alias b/test/fast/Listing versions/Running 'nvm ls stable' and 'nvm ls unstable' should return the appropriate implicit alias index 78d0a50..a612e20 100755 --- a/test/fast/Listing versions/Running 'nvm ls stable' and 'nvm ls unstable' should return the appropriate implicit alias +++ b/test/fast/Listing versions/Running 'nvm ls stable' and 'nvm ls unstable' should return the appropriate implicit alias @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls system' should include 'system' when appropriate b/test/fast/Listing versions/Running 'nvm ls system' should include 'system' when appropriate index 1d39a41..c7e72a4 100755 --- a/test/fast/Listing versions/Running 'nvm ls system' should include 'system' when appropriate +++ b/test/fast/Listing versions/Running 'nvm ls system' should include 'system' when appropriate @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias b/test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias index a5f7457..64cac55 100755 --- a/test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias +++ b/test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh 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 index 92e0270..5fed306 100755 --- 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 @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh @@ -38,7 +39,13 @@ iojs-v0.10.2 v0.12.9 v0.12.87" if nvm_has_system_node || nvm_has_system_iojs; then - EXPECTED_OUTPUT="${EXPECTED_OUTPUT} + SYSTEM_VERSION="$(nvm deactivate >/dev/null 2>&1 && node -v 2>/dev/null)" + if [ -n "${SYSTEM_VERSION}" ]; then + EXPECTED_OUTPUT="${EXPECTED_OUTPUT} +system ${SYSTEM_VERSION}" + else + EXPECTED_OUTPUT="${EXPECTED_OUTPUT} system" + fi fi [ "${OUTPUT-}" = "${EXPECTED_OUTPUT-}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<" diff --git a/test/fast/Listing versions/Running 'nvm ls' should filter out '.nvm' b/test/fast/Listing versions/Running 'nvm ls' should filter out '.nvm' index dedb541..fa51b4d 100755 --- a/test/fast/Listing versions/Running 'nvm ls' should filter out '.nvm' +++ b/test/fast/Listing versions/Running 'nvm ls' should filter out '.nvm' @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls' should filter out 'versions' b/test/fast/Listing versions/Running 'nvm ls' should filter out 'versions' index bd0c709..1f4b4bb 100755 --- a/test/fast/Listing versions/Running 'nvm ls' should filter out 'versions' +++ b/test/fast/Listing versions/Running 'nvm ls' should filter out 'versions' @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls' should include 'system' when appropriate b/test/fast/Listing versions/Running 'nvm ls' should include 'system' when appropriate index 9c465c0..6d76fe2 100755 --- a/test/fast/Listing versions/Running 'nvm ls' should include 'system' when appropriate +++ b/test/fast/Listing versions/Running 'nvm ls' should include 'system' when appropriate @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls' should list versions in the 'versions' directory b/test/fast/Listing versions/Running 'nvm ls' should list versions in the 'versions' directory index a2a31e2..e5fbd5b 100755 --- a/test/fast/Listing versions/Running 'nvm ls' should list versions in the 'versions' directory +++ b/test/fast/Listing versions/Running 'nvm ls' should list versions in the 'versions' directory @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash b/test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash index e3dbd5b..e00db85 100755 --- a/test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash +++ b/test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash @@ -2,6 +2,7 @@ export NVM_DIR="$(cd ../../.. && pwd)" +: nvm.sh \. ../../../nvm.sh \. ../../common.sh @@ -36,7 +37,13 @@ iojs-v0.10.2 v0.12.9 v0.12.87" if nvm_has_system_node || nvm_has_system_iojs; then - EXPECTED_OUTPUT="${EXPECTED_OUTPUT} + SYSTEM_VERSION="$(nvm deactivate >/dev/null 2>&1 && node -v 2>/dev/null)" + if [ -n "${SYSTEM_VERSION}" ]; then + EXPECTED_OUTPUT="${EXPECTED_OUTPUT} +system ${SYSTEM_VERSION}" + else + EXPECTED_OUTPUT="${EXPECTED_OUTPUT} system" + fi fi [ "${OUTPUT-}" = "${EXPECTED_OUTPUT-}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<" diff --git a/test/fast/Listing versions/Running 'nvm ls' with node-like versioning vx.x.x should only list a matched version b/test/fast/Listing versions/Running 'nvm ls' with node-like versioning vx.x.x should only list a matched version index cb54278..2f2c74b 100755 --- a/test/fast/Listing versions/Running 'nvm ls' with node-like versioning vx.x.x should only list a matched version +++ b/test/fast/Listing versions/Running 'nvm ls' with node-like versioning vx.x.x should only list a matched version @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Running 'nvm ls' with nounset should not fail b/test/fast/Listing versions/Running 'nvm ls' with nounset should not fail index d2bfe9e..f677091 100755 --- a/test/fast/Listing versions/Running 'nvm ls' with nounset should not fail +++ b/test/fast/Listing versions/Running 'nvm ls' with nounset should not fail @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Listing versions/Using a nonstandard IFS should not break b/test/fast/Listing versions/Using a nonstandard IFS should not break index 27cf2de..26c26b2 100755 --- a/test/fast/Listing versions/Using a nonstandard IFS should not break +++ b/test/fast/Listing versions/Using a nonstandard IFS should not break @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh 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 index c061a57..2316274 100755 --- 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 @@ -4,6 +4,7 @@ set -ex export NVM_DIR="$(cd ../.. && pwd)" +: nvm.sh \. ../../nvm.sh nvm alias test v0.1.2 diff --git a/test/fast/Running 'nvm current' should display current nvm environment b/test/fast/Running 'nvm current' should display current nvm environment index b9f1304..21540df 100755 --- a/test/fast/Running 'nvm current' should display current nvm environment +++ b/test/fast/Running 'nvm current' should display current nvm environment @@ -6,6 +6,7 @@ die () { echo "$@" ; exit 1; } export NVM_DIR="$(cd ../.. && pwd)" +: nvm.sh \. ../../nvm.sh nvm deactivate 2>&1 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 index b631597..3cb2cc6 100755 --- a/test/fast/Running 'nvm deactivate' should unset the nvm environment variables +++ b/test/fast/Running 'nvm deactivate' should unset the nvm environment variables @@ -6,6 +6,7 @@ die () { echo "$@" ; exit 1; } export NVM_DIR="$(cd ../.. && pwd)" +: nvm.sh \. ../../nvm.sh \. ../common.sh diff --git a/test/fast/Running 'nvm install' with '--reinstall-packages-from' requires a valid version b/test/fast/Running 'nvm install' with '--reinstall-packages-from' requires a valid version index 329fe2b..7e2fd3a 100755 --- a/test/fast/Running 'nvm install' with '--reinstall-packages-from' requires a valid version +++ b/test/fast/Running 'nvm install' with '--reinstall-packages-from' requires a valid version @@ -9,6 +9,7 @@ cleanup () { export NVM_DIR="$(cd ../.. && pwd)" +: nvm.sh \. ../../nvm.sh \. ../common.sh diff --git a/test/fast/Running 'nvm install' with an invalid version fails nicely b/test/fast/Running 'nvm install' with an invalid version fails nicely index 5bbea41..51d7792 100755 --- a/test/fast/Running 'nvm install' with an invalid version fails nicely +++ b/test/fast/Running 'nvm install' with an invalid version fails nicely @@ -6,6 +6,7 @@ die () { echo "$@" ; exit 1; } export NVM_DIR="$(cd ../.. && pwd)" +: nvm.sh \. ../../nvm.sh set +ex # needed for stderr diff --git a/test/fast/Running 'nvm unalias' should remove the alias file b/test/fast/Running 'nvm unalias' should remove the alias file index 2781f57..b741eb2 100755 --- a/test/fast/Running 'nvm unalias' should remove the alias file +++ b/test/fast/Running 'nvm unalias' should remove the alias file @@ -6,6 +6,7 @@ ALIAS_PATH="../../alias" echo v0.1.2 > "${ALIAS_PATH}/test" +: nvm.sh \. ../../nvm.sh nvm unalias 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 index 9d5fa1b..59233d2 100755 --- a/test/fast/Running 'nvm uninstall' should remove the appropriate directory +++ b/test/fast/Running 'nvm uninstall' should remove the appropriate directory @@ -2,6 +2,7 @@ set -ex +: nvm.sh \. ../../nvm.sh \. ../common.sh diff --git a/test/fast/Running 'nvm uninstall' with an inferred version shows the inferred message b/test/fast/Running 'nvm uninstall' with an inferred version shows the inferred message new file mode 100755 index 0000000..2a08076 --- /dev/null +++ b/test/fast/Running 'nvm uninstall' with an inferred version shows the inferred message @@ -0,0 +1,18 @@ +#!/bin/sh + +set -ex + +\. ../../nvm.sh +\. ../common.sh + +VERSION='v0.0.1' +PATTERN='0.0' + +mkdir -p "${NVM_DIR}/${VERSION}" + +set +ex # needed for stderr +RETURN_MESSAGE="$(nvm uninstall "${PATTERN}" 2>&1 || echo)" +set -ex +EXPECTED_MESSAGE="Version '${VERSION}' (inferred from ${PATTERN}) is not installed." + +[ "${RETURN_MESSAGE}" = "${EXPECTED_MESSAGE}" ] diff --git a/test/fast/Running 'nvm uninstall' with an uninstalled version shows the requested version b/test/fast/Running 'nvm uninstall' with an uninstalled version shows the requested version new file mode 100755 index 0000000..25ba202 --- /dev/null +++ b/test/fast/Running 'nvm uninstall' with an uninstalled version shows the requested version @@ -0,0 +1,13 @@ +#!/bin/sh + +set -ex + +\. ../../nvm.sh +\. ../common.sh + +set +ex # needed for stderr +RETURN_MESSAGE="$(nvm uninstall 22 2>&1 || echo)" +set -ex +EXPECTED_MESSAGE="Version '22' is not installed." + +[ "${RETURN_MESSAGE}" = "${EXPECTED_MESSAGE}" ] diff --git a/test/fast/Running 'nvm uninstall' with incorrect file permissions fails nicely b/test/fast/Running 'nvm uninstall' with incorrect file permissions fails nicely index 23f6f54..95d89f9 100755 --- a/test/fast/Running 'nvm uninstall' with incorrect file permissions fails nicely +++ b/test/fast/Running 'nvm uninstall' with incorrect file permissions fails nicely @@ -2,6 +2,7 @@ set -ex +: nvm.sh \. ../../nvm.sh \. ../common.sh diff --git a/test/fast/Running 'nvm unload' should unset all function and variables b/test/fast/Running 'nvm unload' should unset all function and variables index abb5ca4..7ef208e 100755 --- a/test/fast/Running 'nvm unload' should unset all function and variables +++ b/test/fast/Running 'nvm unload' should unset all function and variables @@ -12,6 +12,7 @@ typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}" env | grep -v PATH= | grep -v IFS= | grep -v NVM_ | grep -v TRAVIS_ | sort >> "${BEFORE}" set +e # TODO: fix +: nvm.sh \. ../../nvm.sh set -e diff --git a/test/fast/Running 'nvm use foo' where 'foo' is circular aborts b/test/fast/Running 'nvm use foo' where 'foo' is circular aborts index 2b9fc92..5c9e032 100755 --- a/test/fast/Running 'nvm use foo' where 'foo' is circular aborts +++ b/test/fast/Running 'nvm use foo' where 'foo' is circular aborts @@ -8,6 +8,7 @@ cleanup() { rm -rf "$(nvm_alias_path)/foo" } +: nvm.sh \. ../../nvm.sh nvm_make_alias foo foo diff --git a/test/fast/Running 'nvm use iojs' uses latest io.js version b/test/fast/Running 'nvm use iojs' uses latest io.js version index be383ce..c5932e1 100755 --- a/test/fast/Running 'nvm use iojs' uses latest io.js version +++ b/test/fast/Running 'nvm use iojs' uses latest io.js version @@ -13,6 +13,7 @@ cleanup() { rm -rf "$(nvm_version_path "iojs-${VERSION}")" } +: nvm.sh \. ../../nvm.sh nvm deactivate || die "unable to deactivate; current: >$(nvm current)<" diff --git a/test/fast/Running 'nvm use system' should work as expected b/test/fast/Running 'nvm use system' should work as expected index be3d11e..7d48562 100755 --- a/test/fast/Running 'nvm use system' should work as expected +++ b/test/fast/Running 'nvm use system' should work as expected @@ -7,6 +7,7 @@ cleanup() { } die() { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../nvm.sh nvm_has_system_node() { return 0; } diff --git a/test/fast/Running 'nvm use x' should create and change the 'current' symlink b/test/fast/Running 'nvm use x' should create and change the 'current' symlink index fc1a086..f5a9f4d 100755 --- a/test/fast/Running 'nvm use x' should create and change the 'current' symlink +++ b/test/fast/Running 'nvm use x' should create and change the 'current' symlink @@ -3,6 +3,7 @@ set -ex export NVM_SYMLINK_CURRENT=true +: nvm.sh \. ../../nvm.sh \. ../common.sh diff --git a/test/fast/Running 'nvm use x' should not create the 'current' symlink if $NVM_SYMLINK_CURRENT is false b/test/fast/Running 'nvm use x' should not create the 'current' symlink if $NVM_SYMLINK_CURRENT is false index 1450659..f0de053 100755 --- a/test/fast/Running 'nvm use x' should not create the 'current' symlink if $NVM_SYMLINK_CURRENT is false +++ b/test/fast/Running 'nvm use x' should not create the 'current' symlink if $NVM_SYMLINK_CURRENT is false @@ -2,6 +2,7 @@ set -ex +: nvm.sh \. ../../nvm.sh \. ../common.sh diff --git a/test/fast/Running 'nvm use' should drop CR char automatically b/test/fast/Running 'nvm use' should drop CR char automatically index 3889f47..ecc018c 100755 --- a/test/fast/Running 'nvm use' should drop CR char automatically +++ b/test/fast/Running 'nvm use' should drop CR char automatically @@ -9,6 +9,7 @@ cleanup() { rm .nvmrc } +: nvm.sh \. ../../nvm.sh # normal .nvmrc diff --git a/test/fast/Running 'nvm use' should respect alias pointing to system b/test/fast/Running 'nvm use' should respect alias pointing to system new file mode 100755 index 0000000..97fbac9 --- /dev/null +++ b/test/fast/Running 'nvm use' should respect alias pointing to system @@ -0,0 +1,38 @@ +#!/bin/sh + +set -ex + +die () { echo "$@" ; cleanup ; exit 1; } +cleanup () { + rm -f "$(nvm_alias_path)/default" + if [ -n "${SYSTEM_DIR-}" ]; then + rm -rf "${SYSTEM_DIR}" + fi + if [ -n "${ORIG_PATH-}" ]; then + PATH="${ORIG_PATH}" + fi + unset -f nvm_print_npm_version +} + +\. ../../nvm.sh + +nvm_make_alias default system + +ORIG_PATH="${PATH}" +SYSTEM_VERSION="v0.0.0" +SYSTEM_DIR="$(mktemp -d)" +cat > "${SYSTEM_DIR}/node" <${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +cleanup diff --git a/test/fast/Running 'nvm use' should respect system in .nvmrc b/test/fast/Running 'nvm use' should respect system in .nvmrc new file mode 100755 index 0000000..03909b9 --- /dev/null +++ b/test/fast/Running 'nvm use' should respect system in .nvmrc @@ -0,0 +1,43 @@ +#!/bin/sh + +set -ex + +die () { echo "$@" ; cleanup ; exit 1; } +cleanup () { + rm -f .nvmrc + if [ -f .nvmrc.orig ]; then + mv .nvmrc.orig .nvmrc + fi + if [ -n "${SYSTEM_DIR-}" ]; then + rm -rf "${SYSTEM_DIR}" + fi + if [ -n "${ORIG_PATH-}" ]; then + PATH="${ORIG_PATH}" + fi + unset -f nvm_print_npm_version +} + +\. ../../nvm.sh + +if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi +printf 'system\n' > .nvmrc +ORIG_PATH="${PATH}" +SYSTEM_VERSION="v0.0.0" +SYSTEM_DIR="$(mktemp -d)" +cat > "${SYSTEM_DIR}/node" <${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +cleanup diff --git a/test/fast/Running 'nvm-exec' should display required node version b/test/fast/Running 'nvm-exec' should display required node version index dc6972b..0d24e56 100755 --- a/test/fast/Running 'nvm-exec' should display required node version +++ b/test/fast/Running 'nvm-exec' should display required node version @@ -1,9 +1,11 @@ #!/bin/bash set -x +: nvm.sh \. ../../nvm.sh -die () { echo "$@" ; rm .nvmrc ; exit 1; } +cleanup() { rm -f .nvmrc; } +die () { echo "$@" ; cleanup ; exit 1; } NVM_TEST_VERSION=v0.42 @@ -18,3 +20,5 @@ No NODE_VERSION provided; no .nvmrc file found"; # Skip install, we want to test the error message [ "${EXPECTED}" = "${OUTPUT}" ] || die "expected >${EXPECTED}<, got >${OUTPUT}<" + +cleanup diff --git a/test/fast/Set Colors/nvm_echo_with_colors b/test/fast/Set Colors/nvm_echo_with_colors index daace15..54223eb 100755 --- a/test/fast/Set Colors/nvm_echo_with_colors +++ b/test/fast/Set Colors/nvm_echo_with_colors @@ -11,6 +11,7 @@ cleanup() { echo "Tested nvm_echo_with_colors" } +: nvm.sh \. ../../../nvm.sh OUTPUT="$(nvm_echo_with_colors "\033[0;36mCyan-colored text")" diff --git a/test/fast/Set Colors/nvm_err_with_colors b/test/fast/Set Colors/nvm_err_with_colors index c0b4812..316cced 100755 --- a/test/fast/Set Colors/nvm_err_with_colors +++ b/test/fast/Set Colors/nvm_err_with_colors @@ -8,6 +8,7 @@ cleanup() { echo "Tested nvm_err_with_colors" } +: nvm.sh \. ../../../nvm.sh set +ex diff --git a/test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors b/test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors index 64a2a08..fd7b220 100755 --- a/test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors +++ b/test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh die () { @@ -10,6 +11,8 @@ die () { set -e +nvm_has_colors() { return 0; } + nvm_get_colors(){ echo "0;95m" } diff --git a/test/fast/Set Colors/nvm_print_versions calls nvm_get_colors b/test/fast/Set Colors/nvm_print_versions calls nvm_get_colors index b54d230..4602fd4 100755 --- a/test/fast/Set Colors/nvm_print_versions calls nvm_get_colors +++ b/test/fast/Set Colors/nvm_print_versions calls nvm_get_colors @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh #set -e #nvm use system returns 127 and No system set message @@ -21,6 +22,8 @@ if [ -n ${NVM_COLORS} ]; then unset NVM_COLORS fi +nvm_has_colors() { return 0; } + # default system color nvm use system OUTPUT=$(nvm_print_versions system) 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 index e74f347..1490c3a 100755 --- a/test/fast/Sourcing nvm.sh should make the nvm command available +++ b/test/fast/Sourcing nvm.sh should make the nvm command available @@ -2,6 +2,7 @@ set -ex +: nvm.sh \. ../../nvm.sh nvm diff --git a/test/fast/Sourcing nvm.sh should not modify parameters of caller b/test/fast/Sourcing nvm.sh should not modify parameters of caller index 2053b73..98f6230 100755 --- a/test/fast/Sourcing nvm.sh should not modify parameters of caller +++ b/test/fast/Sourcing nvm.sh should not modify parameters of caller @@ -3,5 +3,6 @@ set -ex set -- yes +: nvm.sh \. ../../nvm.sh [ "$1" = yes ] diff --git a/test/fast/Unit tests/Running 'nvm install --save' works as expected' b/test/fast/Unit tests/Running 'nvm install --save' works as expected' index a020382..d5b24ee 100755 --- a/test/fast/Unit tests/Running 'nvm install --save' works as expected' +++ b/test/fast/Unit tests/Running 'nvm install --save' works as expected' @@ -1,4 +1,5 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/Running 'nvm use --save' works as expected' b/test/fast/Unit tests/Running 'nvm use --save' works as expected' index a188072..ebabc56 100755 --- a/test/fast/Unit tests/Running 'nvm use --save' works as expected' +++ b/test/fast/Unit tests/Running 'nvm use --save' works as expected' @@ -1,4 +1,5 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/Running 'nvm use --save' works with a .nvmrc in the parent dir b/test/fast/Unit tests/Running 'nvm use --save' works with a .nvmrc in the parent dir index ef8a25a..dbed356 100755 --- a/test/fast/Unit tests/Running 'nvm use --save' works with a .nvmrc in the parent dir +++ b/test/fast/Unit tests/Running 'nvm use --save' works with a .nvmrc in the parent dir @@ -1,4 +1,5 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything b/test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything index 578c315..80fc371 100755 --- a/test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything +++ b/test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything @@ -1,4 +1,5 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm install -b b/test/fast/Unit tests/nvm install -b index 20b4b76..8bc4c65 100755 --- a/test/fast/Unit tests/nvm install -b +++ b/test/fast/Unit tests/nvm install -b @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh nvm_install_source() { diff --git a/test/fast/Unit tests/nvm install with nonlowercase LTS name b/test/fast/Unit tests/nvm install with nonlowercase LTS name index 7dd27f5..bc647f1 100755 --- a/test/fast/Unit tests/nvm install with nonlowercase LTS name +++ b/test/fast/Unit tests/nvm install with nonlowercase LTS name @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh REMOTE="${PWD}/mocks/nvm_ls_remote.txt" diff --git a/test/fast/Unit tests/nvm ls-remote b/test/fast/Unit tests/nvm ls-remote index af3a0a7..e1e5363 100755 --- a/test/fast/Unit tests/nvm ls-remote +++ b/test/fast/Unit tests/nvm ls-remote @@ -12,6 +12,7 @@ cleanup() { mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts" } +: nvm.sh \. ../../../nvm.sh if [ -n "${NVM_COLORS-}" ]; then export TEMP_NVM_COLORS=NVM_COLORS @@ -32,6 +33,8 @@ printf '%s\n' "$(cat "${LTS_NAMES_PATH}" | tail -n +1)" | while IFS= read -r LTS cp "${NVM_DIR}/alias/lts-backup/${LTS}" "${NVM_DIR}/alias/lts/" done +nvm_has_colors() { return 0; } + nvm deactivate 2>/dev/null || die 'unable to deactivate' \. ../../common.sh @@ -66,12 +69,14 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do INDEX=$(($INDEX + 1)) done +nvm_has_colors() { return 1; } OUTPUT="$(nvm ls-remote lts/ARGON 2>&1)" EXIT_CODE=$? +nvm_has_colors() { return 0; } [ $EXIT_CODE -eq 3 ] || die "nvm ls-remote lts/ARGON did not exit 3, got '${EXIT_CODE}'" EXPECTED_OUTPUT="LTS names must be lowercase - N/A" + N/A *" [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/ARGON did not output expected error message; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<" REMOTE="${PWD}/mocks/nvm_ls_remote.txt" diff --git a/test/fast/Unit tests/nvm set_colors b/test/fast/Unit tests/nvm set_colors index 85496eb..20f9622 100755 --- a/test/fast/Unit tests/nvm set_colors +++ b/test/fast/Unit tests/nvm set_colors @@ -13,6 +13,7 @@ cleanup() { unset TEMP_NVM_COLORS } +: nvm.sh \. ../../../nvm.sh # NVM_COLORS is not set if [ -n ${NVM_COLORS} ]; then diff --git a/test/fast/Unit tests/nvm version-remote b/test/fast/Unit tests/nvm version-remote index 6a3beeb..1c4026a 100755 --- a/test/fast/Unit tests/nvm version-remote +++ b/test/fast/Unit tests/nvm version-remote @@ -8,6 +8,7 @@ cleanup() { unset -f nvm_remote_version } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_add_iojs_prefix b/test/fast/Unit tests/nvm_add_iojs_prefix index f947118..b619cc2 100755 --- a/test/fast/Unit tests/nvm_add_iojs_prefix +++ b/test/fast/Unit tests/nvm_add_iojs_prefix @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh [ "_$(nvm_add_iojs_prefix 1)" = "_iojs-v1" ] || die '"nvm_add_iojs_prefix 1" did not return "iojs-v1"' diff --git a/test/fast/Unit tests/nvm_alias b/test/fast/Unit tests/nvm_alias index 49cac2d..b05599a 100755 --- a/test/fast/Unit tests/nvm_alias +++ b/test/fast/Unit tests/nvm_alias @@ -6,6 +6,7 @@ cleanup () { rm -rf ../../../alias/test } +: nvm.sh \. ../../../nvm.sh OUTPUT="$(nvm_alias 2>&1)" diff --git a/test/fast/Unit tests/nvm_alias LTS-N b/test/fast/Unit tests/nvm_alias LTS-N index bbc6343..5e3702d 100755 --- a/test/fast/Unit tests/nvm_alias LTS-N +++ b/test/fast/Unit tests/nvm_alias LTS-N @@ -9,6 +9,7 @@ cleanup() { mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts" } +: nvm.sh \. ../../../nvm.sh MOCKS_DIR="${PWD}/mocks" diff --git a/test/fast/Unit tests/nvm_alias handles comments b/test/fast/Unit tests/nvm_alias handles comments index 9e4d166..0b118e9 100755 --- a/test/fast/Unit tests/nvm_alias handles comments +++ b/test/fast/Unit tests/nvm_alias handles comments @@ -8,6 +8,7 @@ cleanup () { rm -rf ../../../alias/test-comment-first } +: nvm.sh \. ../../../nvm.sh # Test: alias file with comment on separate line diff --git a/test/fast/Unit tests/nvm_alias_path b/test/fast/Unit tests/nvm_alias_path index fe304af..1d1653e 100755 --- a/test/fast/Unit tests/nvm_alias_path +++ b/test/fast/Unit tests/nvm_alias_path @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh [ "_$(nvm_alias_path)" = "_$NVM_DIR/alias" ] || die "nvm_alias_path did not return correct location" diff --git a/test/fast/Unit tests/nvm_change_path b/test/fast/Unit tests/nvm_change_path index f434981..aa1642b 100755 --- a/test/fast/Unit tests/nvm_change_path +++ b/test/fast/Unit tests/nvm_change_path @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh TEST_PATH=/usr/bin:/usr/local/bin diff --git a/test/fast/Unit tests/nvm_check_for_help b/test/fast/Unit tests/nvm_check_for_help index b3218f2..562ca3b 100755 --- a/test/fast/Unit tests/nvm_check_for_help +++ b/test/fast/Unit tests/nvm_check_for_help @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh TERM=dumb nvm clear-cache --help | grep 'Usage:' || die 'did not print help menu' diff --git a/test/fast/Unit tests/nvm_command_info b/test/fast/Unit tests/nvm_command_info index 6eebefc..6d13490 100755 --- a/test/fast/Unit tests/nvm_command_info +++ b/test/fast/Unit tests/nvm_command_info @@ -8,6 +8,7 @@ cleanup() { die() { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh diff --git a/test/fast/Unit tests/nvm_compare_checksum b/test/fast/Unit tests/nvm_compare_checksum index c14aee4..99c3b79 100755 --- a/test/fast/Unit tests/nvm_compare_checksum +++ b/test/fast/Unit tests/nvm_compare_checksum @@ -5,6 +5,7 @@ cleanup () { } die () { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh set -ex diff --git a/test/fast/Unit tests/nvm_compute_checksum b/test/fast/Unit tests/nvm_compute_checksum index 6b52eb9..0e8ae0f 100755 --- a/test/fast/Unit tests/nvm_compute_checksum +++ b/test/fast/Unit tests/nvm_compute_checksum @@ -4,6 +4,7 @@ set -ex die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh set +x diff --git a/test/fast/Unit tests/nvm_curl_libz_support b/test/fast/Unit tests/nvm_curl_libz_support index 34602be..acab56f 100755 --- a/test/fast/Unit tests/nvm_curl_libz_support +++ b/test/fast/Unit tests/nvm_curl_libz_support @@ -6,6 +6,7 @@ cleanup() { die() { cleanup; echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh curl() { diff --git a/test/fast/Unit tests/nvm_die_on_prefix b/test/fast/Unit tests/nvm_die_on_prefix index 0a2429e..95f7b98 100755 --- a/test/fast/Unit tests/nvm_die_on_prefix +++ b/test/fast/Unit tests/nvm_die_on_prefix @@ -3,6 +3,7 @@ TEST_PWD=$(pwd) TEST_DIR="$TEST_PWD/nvm_die_on_prefix_tmp" +: nvm.sh \. ../../../nvm.sh TEST_VERSION_DIR="${TEST_DIR}/version" @@ -11,7 +12,7 @@ cleanup () { rm -rf "$TEST_DIR" alias nvm_has='\nvm_has' alias npm='\npm' - unset -f nvm_has npm + unset -f nvm_has npm node } die () { @@ -60,6 +61,12 @@ npm() { fi } +node() { + if [ "_$1" = "_-v" ]; then + echo "v0.0.0" + fi +} + OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)" [ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when directory is equivalent; got '$OUTPUT'" diff --git a/test/fast/Unit tests/nvm_download b/test/fast/Unit tests/nvm_download index 464fc17..4424d8b 100755 --- a/test/fast/Unit tests/nvm_download +++ b/test/fast/Unit tests/nvm_download @@ -6,6 +6,7 @@ cleanup () { } die () { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh set -ex diff --git a/test/fast/Unit tests/nvm_download_artifact b/test/fast/Unit tests/nvm_download_artifact index 250bca3..ec450d9 100755 --- a/test/fast/Unit tests/nvm_download_artifact +++ b/test/fast/Unit tests/nvm_download_artifact @@ -5,6 +5,7 @@ cleanup () { } die () { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh # bad flavor diff --git a/test/fast/Unit tests/nvm_ensure_default_set b/test/fast/Unit tests/nvm_ensure_default_set index 14b53eb..c8170bc 100755 --- a/test/fast/Unit tests/nvm_ensure_default_set +++ b/test/fast/Unit tests/nvm_ensure_default_set @@ -4,6 +4,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh EXPECTED_OUTPUT="nvm_ensure_default_set: a version is required" diff --git a/test/fast/Unit tests/nvm_ensure_version_installed b/test/fast/Unit tests/nvm_ensure_version_installed index 4c51508..d2e1149 100755 --- a/test/fast/Unit tests/nvm_ensure_version_installed +++ b/test/fast/Unit tests/nvm_ensure_version_installed @@ -6,6 +6,7 @@ cleanup () { unset -f nvm_has_system_node nvm_has_system_iojs } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_ensure_version_prefix b/test/fast/Unit tests/nvm_ensure_version_prefix index b54ea02..68db145 100755 --- a/test/fast/Unit tests/nvm_ensure_version_prefix +++ b/test/fast/Unit tests/nvm_ensure_version_prefix @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh [ "_$(nvm_ensure_version_prefix 1)" = "_v1" ] || die '"nvm_ensure_version_prefix 1" did not return "v1"' diff --git a/test/fast/Unit tests/nvm_extract_tarball b/test/fast/Unit tests/nvm_extract_tarball index 4cf7533..6119e72 100755 --- a/test/fast/Unit tests/nvm_extract_tarball +++ b/test/fast/Unit tests/nvm_extract_tarball @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh [ "$(nvm_extract_tarball 2>&1)" = "nvm_extract_tarball requires exactly 4 arguments" ] || die 'incorrect error message with no args' diff --git a/test/fast/Unit tests/nvm_find_project_dir b/test/fast/Unit tests/nvm_find_project_dir index 1bfcf16..bf1f489 100755 --- a/test/fast/Unit tests/nvm_find_project_dir +++ b/test/fast/Unit tests/nvm_find_project_dir @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh set -ex diff --git a/test/fast/Unit tests/nvm_find_up b/test/fast/Unit tests/nvm_find_up index 73f7d21..fff3e5f 100755 --- a/test/fast/Unit tests/nvm_find_up +++ b/test/fast/Unit tests/nvm_find_up @@ -11,6 +11,7 @@ cleanup () { rm -rf tmp_nvm_find_up } +: nvm.sh \. ../../../nvm.sh setup diff --git a/test/fast/Unit tests/nvm_format_version b/test/fast/Unit tests/nvm_format_version index 98541fe..d4dd86c 100755 --- a/test/fast/Unit tests/nvm_format_version +++ b/test/fast/Unit tests/nvm_format_version @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh INPUT="0.1.2" diff --git a/test/fast/Unit tests/nvm_get_arch b/test/fast/Unit tests/nvm_get_arch index c45cae0..b759b59 100755 --- a/test/fast/Unit tests/nvm_get_arch +++ b/test/fast/Unit tests/nvm_get_arch @@ -11,6 +11,7 @@ cleanup() { die () { cleanup; echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh # Directory where mocked binaries used by nvm_get_arch for each OS/arch are diff --git a/test/fast/Unit tests/nvm_get_arch_unofficial b/test/fast/Unit tests/nvm_get_arch_unofficial index 12c5da0..a05757f 100755 --- a/test/fast/Unit tests/nvm_get_arch_unofficial +++ b/test/fast/Unit tests/nvm_get_arch_unofficial @@ -15,6 +15,7 @@ die() { exit 1 } +: nvm.sh . ../../../nvm.sh # Sets the PATH for these tests to include the symlinks to the mocked binaries diff --git a/test/fast/Unit tests/nvm_get_artifact_compression b/test/fast/Unit tests/nvm_get_artifact_compression index 3fc5fcf..f099000 100755 --- a/test/fast/Unit tests/nvm_get_artifact_compression +++ b/test/fast/Unit tests/nvm_get_artifact_compression @@ -5,6 +5,7 @@ cleanup () { } die () { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh # nvm_get_artifact_compression by default diff --git a/test/fast/Unit tests/nvm_get_checksum b/test/fast/Unit tests/nvm_get_checksum index 975a3e6..3df06d4 100755 --- a/test/fast/Unit tests/nvm_get_checksum +++ b/test/fast/Unit tests/nvm_get_checksum @@ -8,6 +8,7 @@ cleanup () { die () { echo "$@" ; cleanup ; exit 1; } set +e # TODO: fix +: nvm.sh \. ../../../nvm.sh set -e diff --git a/test/fast/Unit tests/nvm_get_checksum_alg b/test/fast/Unit tests/nvm_get_checksum_alg index 1869437..74aa11f 100755 --- a/test/fast/Unit tests/nvm_get_checksum_alg +++ b/test/fast/Unit tests/nvm_get_checksum_alg @@ -5,6 +5,7 @@ set -ex die () { echo "$@" ; exit 1; } set +e # TODO: fix +: nvm.sh \. ../../../nvm.sh set -e diff --git a/test/fast/Unit tests/nvm_get_checksum_binary b/test/fast/Unit tests/nvm_get_checksum_binary index 0de0cd4..532c1e5 100755 --- a/test/fast/Unit tests/nvm_get_checksum_binary +++ b/test/fast/Unit tests/nvm_get_checksum_binary @@ -5,6 +5,7 @@ set -ex die () { echo "$@" ; exit 1; } set +e # TODO: fix +: nvm.sh \. ../../../nvm.sh set -e diff --git a/test/fast/Unit tests/nvm_get_colors b/test/fast/Unit tests/nvm_get_colors index df35da5..c90da49 100755 --- a/test/fast/Unit tests/nvm_get_colors +++ b/test/fast/Unit tests/nvm_get_colors @@ -12,6 +12,7 @@ cleanup() { unset TEMP_NVM_COLORS } +: nvm.sh \. ../../../nvm.sh # NVM_COLORS is not set diff --git a/test/fast/Unit tests/nvm_get_default_packages b/test/fast/Unit tests/nvm_get_default_packages index d8a8157..9e10214 100755 --- a/test/fast/Unit tests/nvm_get_default_packages +++ b/test/fast/Unit tests/nvm_get_default_packages @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh FILE="${NVM_DIR}/default-packages" diff --git a/test/fast/Unit tests/nvm_get_default_packages mawk compat b/test/fast/Unit tests/nvm_get_default_packages mawk compat new file mode 100755 index 0000000..35c8d4f --- /dev/null +++ b/test/fast/Unit tests/nvm_get_default_packages mawk compat @@ -0,0 +1,58 @@ +#!/bin/sh + +# Test that nvm_get_default_packages awk patterns work with mawk +# This test runs with mawk explicitly if available, to catch POSIX +# character class compatibility issues (mawk doesn't support [[:space:]]) + +die () { echo "$@" ; cleanup ; exit 1; } + +: nvm.sh +\. ../../../nvm.sh + +# The awk command from nvm_get_default_packages +AWK_SCRIPT=' + /^[ \t]*#/ { next } + /^[ \t]*$/ { next } + /[ \t]/ && !/^[ \t]*#/ { + print "error" > "/dev/stderr" + exit 1 + } + { + if (NR > 1 && !prev_space) printf " " + printf "%s", $0 + prev_space = 0 + } +' + +TEST_INPUT="rimraf +object-inspect@1.0.2 + +# commented-package + +stevemao/left-pad" + +EXPECTED_OUTPUT="rimraf object-inspect@1.0.2 stevemao/left-pad" + +# Test with system awk +OUTPUT="$(printf '%s\n' "${TEST_INPUT}" | awk "${AWK_SCRIPT}")" +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "system awk: expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<" + +# Test with mawk explicitly if available +if command -v mawk > /dev/null 2>&1; then + OUTPUT="$(printf '%s\n' "${TEST_INPUT}" | mawk "${AWK_SCRIPT}")" + [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "mawk: expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<" + echo "mawk test passed" +else + echo "mawk not available, skipping mawk-specific test" +fi + +# Test with gawk explicitly if available +if command -v gawk > /dev/null 2>&1; then + OUTPUT="$(printf '%s\n' "${TEST_INPUT}" | gawk "${AWK_SCRIPT}")" + [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "gawk: expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<" + echo "gawk test passed" +else + echo "gawk not available, skipping gawk-specific test" +fi + +echo "All awk compatibility tests passed" diff --git a/test/fast/Unit tests/nvm_get_download_slug b/test/fast/Unit tests/nvm_get_download_slug index a4a0bc4..eeb72ac 100755 --- a/test/fast/Unit tests/nvm_get_download_slug +++ b/test/fast/Unit tests/nvm_get_download_slug @@ -7,6 +7,7 @@ cleanup() { die () { cleanup; echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh [ "$(nvm_get_download_slug 2>/dev/null ; echo $?)" = '1' ] || die 'invalid flavor did not fail with exit code 1' diff --git a/test/fast/Unit tests/nvm_get_latest missing curl or wget b/test/fast/Unit tests/nvm_get_latest missing curl or wget index 2c9b1da..bc23d37 100755 --- a/test/fast/Unit tests/nvm_get_latest missing curl or wget +++ b/test/fast/Unit tests/nvm_get_latest missing curl or wget @@ -6,6 +6,7 @@ cleanup() { unset -f nvm_has } +: nvm.sh \. ../../../nvm.sh nvm_has() { return 1 ; } diff --git a/test/fast/Unit tests/nvm_get_minor_version b/test/fast/Unit tests/nvm_get_minor_version index dbfea5d..546caf6 100755 --- a/test/fast/Unit tests/nvm_get_minor_version +++ b/test/fast/Unit tests/nvm_get_minor_version @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh expect () { diff --git a/test/fast/Unit tests/nvm_get_mirror b/test/fast/Unit tests/nvm_get_mirror index 201a0ee..a8a4255 100755 --- a/test/fast/Unit tests/nvm_get_mirror +++ b/test/fast/Unit tests/nvm_get_mirror @@ -8,6 +8,7 @@ unset NVM_NODEJS_ORG_MIRROR unset NVM_IOJS_ORG_MIRROR set +e # TODO: fix +: nvm.sh \. ../../../nvm.sh set -e diff --git a/test/fast/Unit tests/nvm_has b/test/fast/Unit tests/nvm_has index 8a7d7be..0987801 100755 --- a/test/fast/Unit tests/nvm_has +++ b/test/fast/Unit tests/nvm_has @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly' diff --git a/test/fast/Unit tests/nvm_has_colors b/test/fast/Unit tests/nvm_has_colors new file mode 100755 index 0000000..e5cc86a --- /dev/null +++ b/test/fast/Unit tests/nvm_has_colors @@ -0,0 +1,30 @@ +#!/bin/sh + +die () { echo "$@" ; exit 1; } + +: nvm.sh +\. ../../../nvm.sh + +# nvm_has_colors should be false in command substitution (stdout is not a terminal) +[ "$(nvm_has_colors; echo $?)" = "1" ] || die 'nvm_has_colors should be false in command substitution' + +# nvm_has_colors should be false when stdout goes to /dev/null +! nvm_has_colors >/dev/null || die 'nvm_has_colors should be false when stdout goes to /dev/null' + +# nvm_has_colors should be false when stdout goes to a pipe +(! nvm_has_colors || echo "boo!") | read && die 'nvm_has_colors should be false when stdout goes to a pipe' + +# nvm_has_colors should be false when NVM_NO_COLORS is set, even if stdout is a terminal +if [ -t 1 ]; then + ! NVM_NO_COLORS="--no-colors" nvm_has_colors || die 'nvm_has_colors should be false when NVM_NO_COLORS is set' +fi + +# nvm_has_colors should be true when stdout is a terminal and colors are supported +if [ -t 1 ] && nvm_has tput && [ "$(command tput -T "${TERM:-vt100}" colors)" -ge 8 ]; then + nvm_has_colors || die 'nvm_has_colors should be true when stdout is a terminal with color support' +fi + +# nvm_has_colors should be true when redirected to /dev/tty (if available) +if (exec >/dev/tty) 2>/dev/null && nvm_has tput && [ "$(command tput -T "${TERM:-vt100}" colors)" -ge 8 ]; then + nvm_has_colors >/dev/tty || die 'nvm_has_colors should be true when stdout goes to /dev/tty' +fi diff --git a/test/fast/Unit tests/nvm_has_non_aliased b/test/fast/Unit tests/nvm_has_non_aliased index e42b2c6..03564d4 100755 --- a/test/fast/Unit tests/nvm_has_non_aliased +++ b/test/fast/Unit tests/nvm_has_non_aliased @@ -3,6 +3,7 @@ cleanup () { unalias foo; unalias grep; } die () { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh alias foo='bar' diff --git a/test/fast/Unit tests/nvm_has_solaris_binary b/test/fast/Unit tests/nvm_has_solaris_binary index 9d949e4..5222312 100755 --- a/test/fast/Unit tests/nvm_has_solaris_binary +++ b/test/fast/Unit tests/nvm_has_solaris_binary @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_has_system_iojs b/test/fast/Unit tests/nvm_has_system_iojs index 0d4eadb..78dec06 100755 --- a/test/fast/Unit tests/nvm_has_system_iojs +++ b/test/fast/Unit tests/nvm_has_system_iojs @@ -5,6 +5,7 @@ cleanup () { } die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_has_system_node b/test/fast/Unit tests/nvm_has_system_node index 9a71979..8390a63 100755 --- a/test/fast/Unit tests/nvm_has_system_node +++ b/test/fast/Unit tests/nvm_has_system_node @@ -1,5 +1,6 @@ #!/bin/sh +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_install_binary_extract b/test/fast/Unit tests/nvm_install_binary_extract index 5dd2cc7..bd7eb27 100755 --- a/test/fast/Unit tests/nvm_install_binary_extract +++ b/test/fast/Unit tests/nvm_install_binary_extract @@ -40,6 +40,7 @@ test_archi() { [ "$(cat "${NVM_DIR}/versions/node/${version}/bin/node")" = "node ${version}" ] || die "Unable to extract ${ext} file" } +: nvm.sh \. ../../../nvm.sh set -ex diff --git a/test/fast/Unit tests/nvm_install_binary_nosource b/test/fast/Unit tests/nvm_install_binary_nosource index e425b15..2034658 100755 --- a/test/fast/Unit tests/nvm_install_binary_nosource +++ b/test/fast/Unit tests/nvm_install_binary_nosource @@ -9,6 +9,7 @@ cleanup () { die () { echo "$@" ; cleanup; exit 1;} +: nvm.sh \. ../../../nvm.sh nvm_binary_available() { diff --git a/test/fast/Unit tests/nvm_install_latest_npm b/test/fast/Unit tests/nvm_install_latest_npm index ecf9c74..c65ccf3 100755 --- a/test/fast/Unit tests/nvm_install_latest_npm +++ b/test/fast/Unit tests/nvm_install_latest_npm @@ -4,6 +4,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh nvm deactivate >/dev/null 2>&1 diff --git a/test/fast/Unit tests/nvm_install_no_progress_bar b/test/fast/Unit tests/nvm_install_no_progress_bar index d5c9c27..18f2d04 100755 --- a/test/fast/Unit tests/nvm_install_no_progress_bar +++ b/test/fast/Unit tests/nvm_install_no_progress_bar @@ -11,6 +11,7 @@ cleanup () { die () { >&2 echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh cleanup diff --git a/test/fast/Unit tests/nvm_install_source SHELL override b/test/fast/Unit tests/nvm_install_source SHELL override new file mode 100755 index 0000000..f92b0b9 --- /dev/null +++ b/test/fast/Unit tests/nvm_install_source SHELL override @@ -0,0 +1,92 @@ +#!/bin/sh + +cleanup () { + unset -f make gmake nvm_download nvm_get_os nvm_get_arch nvm_extract_tarball nvm_version_path nvm_get_make_jobs + rm -rf "${FAKE_TMPDIR-}" +} +die () { echo "$@" ; cleanup ; exit 1; } + +: nvm.sh +\. ../../../nvm.sh + +# Create a fake directory structure for the build +FAKE_TMPDIR="$(mktemp -d)" +mkdir -p "${FAKE_TMPDIR}/files" +touch "${FAKE_TMPDIR}/node-old.tar.gz" +touch "${FAKE_TMPDIR}/node-new.tar.gz" + +# Track make invocations +MAKE_CALLS="" + +make() { + MAKE_CALLS="${MAKE_CALLS}make $* +" + return 1 # Fail to prevent actual build +} + +gmake() { + MAKE_CALLS="${MAKE_CALLS}gmake $* +" + return 1 # Fail to prevent actual build +} + +nvm_download() { + return 0 +} + +nvm_get_arch() { + echo "x64" +} + +nvm_extract_tarball() { + return 0 +} + +nvm_version_path() { + echo "${FAKE_TMPDIR}/versions/${1}" +} + +nvm_get_make_jobs() { + NVM_MAKE_JOBS=1 +} + +# Test 1: Old version (0.6.21) should have SHELL=/bin/sh +MAKE_CALLS="" +NVM_DIR="${FAKE_TMPDIR}" +export NVM_DIR + +# Manually test the version check logic +if nvm_version_greater "0.12.0" "0.6.21"; then + OLD_VERSION_DETECTED="yes" +else + OLD_VERSION_DETECTED="no" +fi +[ "${OLD_VERSION_DETECTED}" = "yes" ] || die "Expected 0.6.21 to be detected as old version" + +# Test 2: New version (0.12.0) should NOT have SHELL=/bin/sh +if nvm_version_greater "0.12.0" "0.12.0"; then + NEW_VERSION_DETECTED="yes" +else + NEW_VERSION_DETECTED="no" +fi +[ "${NEW_VERSION_DETECTED}" = "no" ] || die "Expected 0.12.0 to NOT be detected as old version" + +# Test 3: Newer version (14.0.0) should NOT have SHELL=/bin/sh +if nvm_version_greater "0.12.0" "14.0.0"; then + NEWER_VERSION_DETECTED="yes" +else + NEWER_VERSION_DETECTED="no" +fi +[ "${NEWER_VERSION_DETECTED}" = "no" ] || die "Expected 14.0.0 to NOT be detected as old version" + +# Test 4: Edge case version (0.11.99) should have SHELL=/bin/sh +if nvm_version_greater "0.12.0" "0.11.99"; then + EDGE_VERSION_DETECTED="yes" +else + EDGE_VERSION_DETECTED="no" +fi +[ "${EDGE_VERSION_DETECTED}" = "yes" ] || die "Expected 0.11.99 to be detected as old version" + +echo "All nvm_install_source SHELL override tests passed" + +cleanup diff --git a/test/fast/Unit tests/nvm_iojs_prefix b/test/fast/Unit tests/nvm_iojs_prefix index fef2373..d5d9f2e 100755 --- a/test/fast/Unit tests/nvm_iojs_prefix +++ b/test/fast/Unit tests/nvm_iojs_prefix @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh [ "$(nvm_iojs_prefix)" = "iojs" ] || die '"nvm_iojs_prefix" did not return the string "iojs". why did this fail?!' diff --git a/test/fast/Unit tests/nvm_iojs_version_has_solaris_binary b/test/fast/Unit tests/nvm_iojs_version_has_solaris_binary index 8048fa3..6394b1d 100755 --- a/test/fast/Unit tests/nvm_iojs_version_has_solaris_binary +++ b/test/fast/Unit tests/nvm_iojs_version_has_solaris_binary @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_is_alias b/test/fast/Unit tests/nvm_is_alias index eba9506..1fb69e9 100755 --- a/test/fast/Unit tests/nvm_is_alias +++ b/test/fast/Unit tests/nvm_is_alias @@ -3,6 +3,7 @@ cleanup () { unalias foo; unalias grep; } die () { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh alias foo='bar' diff --git a/test/fast/Unit tests/nvm_is_iojs_version b/test/fast/Unit tests/nvm_is_iojs_version index d846e71..b1b75fc 100755 --- a/test/fast/Unit tests/nvm_is_iojs_version +++ b/test/fast/Unit tests/nvm_is_iojs_version @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh nvm_is_iojs_version 'iojs-' || die '"nvm_is_iojs_version iojs- was not true' diff --git a/test/fast/Unit tests/nvm_is_merged_node_version b/test/fast/Unit tests/nvm_is_merged_node_version index 7501c2a..897b943 100755 --- a/test/fast/Unit tests/nvm_is_merged_node_version +++ b/test/fast/Unit tests/nvm_is_merged_node_version @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh nvm_is_merged_node_version '4.0' || die '"nvm_is_merged_node_version 4.0 was not true' diff --git a/test/fast/Unit tests/nvm_is_natural_num b/test/fast/Unit tests/nvm_is_natural_num index d66d6c8..caf56cf 100755 --- a/test/fast/Unit tests/nvm_is_natural_num +++ b/test/fast/Unit tests/nvm_is_natural_num @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh ! nvm_is_natural_num || die 'no args is not false' diff --git a/test/fast/Unit tests/nvm_is_valid_version b/test/fast/Unit tests/nvm_is_valid_version index edfe537..8bdf941 100755 --- a/test/fast/Unit tests/nvm_is_valid_version +++ b/test/fast/Unit tests/nvm_is_valid_version @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh nvm_is_valid_version 0.1.2 || die "nvm_is_valid_version 0.1.2 did not return 0" diff --git a/test/fast/Unit tests/nvm_is_version_installed b/test/fast/Unit tests/nvm_is_version_installed index 3d7de4f..8b6e775 100755 --- a/test/fast/Unit tests/nvm_is_version_installed +++ b/test/fast/Unit tests/nvm_is_version_installed @@ -7,6 +7,7 @@ cleanup () { } die () { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh set -ex diff --git a/test/fast/Unit tests/nvm_ls handles hash in pattern b/test/fast/Unit tests/nvm_ls handles hash in pattern index 815169e..cb3a0c9 100755 --- a/test/fast/Unit tests/nvm_ls handles hash in pattern +++ b/test/fast/Unit tests/nvm_ls handles hash in pattern @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh # Test: nvm_ls with pattern containing # should not cause sed error diff --git a/test/fast/Unit tests/nvm_ls_current b/test/fast/Unit tests/nvm_ls_current index f2c5e65..69de68e 100755 --- a/test/fast/Unit tests/nvm_ls_current +++ b/test/fast/Unit tests/nvm_ls_current @@ -6,6 +6,7 @@ TEST_DIR="$TEST_PWD/nvm_ls_current_tmp" cleanup() { rm -rf "$TEST_DIR"; unset -f return_zero; alias node='node' ; unalias node; } die () { echo "$@" ; cleanup ; exit 1; } +: nvm.sh \. ../../../nvm.sh return_zero () { return 0; } diff --git a/test/fast/Unit tests/nvm_ls_remote b/test/fast/Unit tests/nvm_ls_remote index be61cc4..f0cf363 100755 --- a/test/fast/Unit tests/nvm_ls_remote +++ b/test/fast/Unit tests/nvm_ls_remote @@ -6,6 +6,7 @@ cleanup() { unset -f nvm_download } +: nvm.sh \. ../../../nvm.sh MOCKS_DIR="$PWD/mocks" diff --git a/test/fast/Unit tests/nvm_ls_remote LTS aliases b/test/fast/Unit tests/nvm_ls_remote LTS aliases index e03cb99..e6037b3 100755 --- a/test/fast/Unit tests/nvm_ls_remote LTS aliases +++ b/test/fast/Unit tests/nvm_ls_remote LTS aliases @@ -14,6 +14,7 @@ cleanup() { rm -rf "$TEST_PATH" } +: nvm.sh \. ../../../nvm.sh set -ex diff --git a/test/fast/Unit tests/nvm_ls_remote nightly b/test/fast/Unit tests/nvm_ls_remote nightly index 47ba759..83e95ec 100755 --- a/test/fast/Unit tests/nvm_ls_remote nightly +++ b/test/fast/Unit tests/nvm_ls_remote nightly @@ -6,6 +6,7 @@ cleanup() { unset -f nvm_download } +: nvm.sh \. ../../../nvm.sh MOCKS_DIR="$PWD/mocks" diff --git a/test/fast/Unit tests/nvm_ls_remote_iojs b/test/fast/Unit tests/nvm_ls_remote_iojs index 553aefd..7dd6ad3 100755 --- a/test/fast/Unit tests/nvm_ls_remote_iojs +++ b/test/fast/Unit tests/nvm_ls_remote_iojs @@ -6,6 +6,7 @@ cleanup() { unset -f nvm_download } +: nvm.sh \. ../../../nvm.sh # sample output at the time the test was written diff --git a/test/fast/Unit tests/nvm_make_alias b/test/fast/Unit tests/nvm_make_alias index f04e518..dd3f794 100755 --- a/test/fast/Unit tests/nvm_make_alias +++ b/test/fast/Unit tests/nvm_make_alias @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh OUTPUT="$(nvm_make_alias 2>&1)" diff --git a/test/fast/Unit tests/nvm_node_prefix b/test/fast/Unit tests/nvm_node_prefix index c0ffd1d..d186a9d 100755 --- a/test/fast/Unit tests/nvm_node_prefix +++ b/test/fast/Unit tests/nvm_node_prefix @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh [ "$(nvm_node_prefix)" = "node" ] || die '"nvm_node_prefix" did not return the string "node". why did this fail?!' diff --git a/test/fast/Unit tests/nvm_node_version_has_solaris_binary b/test/fast/Unit tests/nvm_node_version_has_solaris_binary index 95ed5af..a9237c0 100755 --- a/test/fast/Unit tests/nvm_node_version_has_solaris_binary +++ b/test/fast/Unit tests/nvm_node_version_has_solaris_binary @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_normalize_lts b/test/fast/Unit tests/nvm_normalize_lts index 2e5b3b2..1e0722b 100755 --- a/test/fast/Unit tests/nvm_normalize_lts +++ b/test/fast/Unit tests/nvm_normalize_lts @@ -8,6 +8,7 @@ cleanup() { die () { cleanup; echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh MOCKS_DIR="../Unit tests/mocks" diff --git a/test/fast/Unit tests/nvm_num_version_groups b/test/fast/Unit tests/nvm_num_version_groups index ab09f0c..282da15 100755 --- a/test/fast/Unit tests/nvm_num_version_groups +++ b/test/fast/Unit tests/nvm_num_version_groups @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh [ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0" diff --git a/test/fast/Unit tests/nvm_print_alias_path b/test/fast/Unit tests/nvm_print_alias_path index 14cf152..29be663 100755 --- a/test/fast/Unit tests/nvm_print_alias_path +++ b/test/fast/Unit tests/nvm_print_alias_path @@ -7,6 +7,7 @@ cleanup () { unset -f nvm_alias nvm_version } +: nvm.sh \. ../../../nvm.sh NVM_ALIAS_DIR='path/to/the alias/dir' @@ -38,7 +39,7 @@ nvm_version() { } OUTPUT="$(nvm_print_alias_path "$NVM_ALIAS_DIR" "$NVM_ALIAS_DIR/blah" | strip_colors)" -EXPECTED_OUTPUT='blah -> "blah" (-> v"blah")' +EXPECTED_OUTPUT='blah -> "blah" (-> v"blah" *)' [ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "'nvm_print_alias_path \"\$NVM_ALIAS_DIR\" \"\$NVM_ALIAS_DIR/blah\"' should strip alias dir and print nvm_alias output; got '$OUTPUT', expected '$EXPECTED_OUTPUT'" cleanup diff --git a/test/fast/Unit tests/nvm_print_color_code b/test/fast/Unit tests/nvm_print_color_code index 5b49e9c..4b9cfc8 100755 --- a/test/fast/Unit tests/nvm_print_color_code +++ b/test/fast/Unit tests/nvm_print_color_code @@ -4,6 +4,7 @@ set -ex die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh # Testing valid input diff --git a/test/fast/Unit tests/nvm_print_default_alias b/test/fast/Unit tests/nvm_print_default_alias index fcb3ab2..f9d8bef 100755 --- a/test/fast/Unit tests/nvm_print_default_alias +++ b/test/fast/Unit tests/nvm_print_default_alias @@ -7,6 +7,7 @@ cleanup () { unset -f nvm_print_implicit_alias nvm_version } +: nvm.sh \. ../../../nvm.sh nvm_print_implicit_alias() { @@ -32,7 +33,7 @@ nvm_version() { } OUTPUT="$(nvm_print_default_alias blah | strip_colors)" -EXPECTED_OUTPUT='blah -> "local-blah" (-> v"local-blah") (default)' +EXPECTED_OUTPUT='blah -> "local-blah" (-> v"local-blah" *) (default)' [ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "'nvm_print_default_alias blah' should strip alias dir and print nvm_print_implicit_alias output; got '$OUTPUT', expected '$EXPECTED_OUTPUT'" cleanup diff --git a/test/fast/Unit tests/nvm_print_implicit_alias errors b/test/fast/Unit tests/nvm_print_implicit_alias errors index 5565eea..c142406 100755 --- a/test/fast/Unit tests/nvm_print_implicit_alias errors +++ b/test/fast/Unit tests/nvm_print_implicit_alias errors @@ -2,6 +2,7 @@ die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh EXPECTED_FIRST_MSG="nvm_print_implicit_alias must be specified with local or remote as the first argument." diff --git a/test/fast/Unit tests/nvm_print_implicit_alias success b/test/fast/Unit tests/nvm_print_implicit_alias success index ded8174..8a0d22e 100755 --- a/test/fast/Unit tests/nvm_print_implicit_alias success +++ b/test/fast/Unit tests/nvm_print_implicit_alias success @@ -13,6 +13,7 @@ cleanup() { unset -f nvm_ls_remote nvm_ls_remote_iojs } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_print_npm_version b/test/fast/Unit tests/nvm_print_npm_version index a9cbc2c..65409ad 100755 --- a/test/fast/Unit tests/nvm_print_npm_version +++ b/test/fast/Unit tests/nvm_print_npm_version @@ -7,6 +7,7 @@ cleanup () { } die () { echo "$@" ; exit 1; } +: nvm.sh \. ../../../nvm.sh nvm_has() { return 1; } diff --git a/test/fast/Unit tests/nvm_process_nvmrc b/test/fast/Unit tests/nvm_process_nvmrc index 5102c57..5423cb3 100755 --- a/test/fast/Unit tests/nvm_process_nvmrc +++ b/test/fast/Unit tests/nvm_process_nvmrc @@ -6,6 +6,7 @@ cleanup() { echo 'cleaned up' } +: nvm.sh \. ../../../nvm.sh \. ../../common.sh diff --git a/test/fast/Unit tests/nvm_remote_version b/test/fast/Unit tests/nvm_remote_version index 96f33f5..3aa5c11 100755 --- a/test/fast/Unit tests/nvm_remote_version +++ b/test/fast/Unit tests/nvm_remote_version @@ -6,6 +6,7 @@ cleanup() { unset -f nvm_ls_remote nvm_ls_remote_iojs } +: nvm.sh \. ../../../nvm.sh nvm_ls_remote() { diff --git a/test/fast/Unit tests/nvm_remote_versions b/test/fast/Unit tests/nvm_remote_versions index e4136b2..02a0464 100755 --- a/test/fast/Unit tests/nvm_remote_versions +++ b/test/fast/Unit tests/nvm_remote_versions @@ -6,6 +6,7 @@ cleanup() { unset -f nvm_ls_remote nvm_ls_remote_iojs } +: nvm.sh \. ../../../nvm.sh OUTPUT="$(nvm_remote_versions stable 2>&1)" diff --git a/test/fast/Unit tests/nvm_stdout_is_terminal b/test/fast/Unit tests/nvm_stdout_is_terminal index 31b4666..69d5649 100755 --- a/test/fast/Unit tests/nvm_stdout_is_terminal +++ b/test/fast/Unit tests/nvm_stdout_is_terminal @@ -5,6 +5,7 @@ tempfile=$(mktemp) die () { echo "$@" ; cleanup; exit 1; } cleanup() { rm -f "$tempfile"; } +: nvm.sh \. ../../../nvm.sh if [ -t 1 ] ; then @@ -24,7 +25,7 @@ fi ! nvm_stdout_is_terminal >"$tempfile" || die 'nvm_stdout_is_terminal should be false when stdout goes to a file' [ "$(nvm_stdout_is_terminal; echo $?)" = "1" ] || die 'nvm_stdout_is_terminal should be false in command substitution' -# also test the 'true' case while running on travis-ci or similar environments +# also test the 'true' case while running on CI or similar environments nvm_stdout_is_terminal >/dev/tty || die 'nvm_stdout_is_terminal should be true when stdout goes to /dev/tty' nvm_stdout_is_terminal >/dev/tty 2>/dev/null || die 'nvm_stdout_is_terminal should be true when stdout goes to /dev/tty and stderr is redirected' nvm_stdout_is_terminal >/dev/tty /dev/null || true +} +die () { echo "$@" ; cleanup ; exit 1; } + +\. ../../../nvm.sh + +set -ex + +# Skip test if wget is not available +if ! nvm_has "wget"; then + echo "wget not available, skipping security test" + exit 0 +fi + +# Test 1: Verify that malicious command injection in NVM_AUTH_HEADER is sanitized +# This should not execute the command, but should sanitize it +MALICIOUS_HEADER="Bearer test-token; touch /tmp/nvm_security_test_file; echo malicious" +NVM_AUTH_HEADER="${MALICIOUS_HEADER}" nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/dev/null 2>&1 || true + +# Verify that the malicious file was NOT created (sanitization worked) +if [ -f /tmp/nvm_security_test_file ]; then + die "SECURITY FAILURE: Command injection succeeded! Malicious file was created." +fi + +# Test 2: Verify that sanitized header still works for legitimate requests +# The sanitized header should only contain safe characters +SANITIZED=$(nvm_sanitize_auth_header "${MALICIOUS_HEADER}") +# Verify that dangerous characters were removed +case "${SANITIZED}" in + *";"*|*"touch"*|*"/tmp"*) + die "SECURITY FAILURE: Sanitization did not remove dangerous characters properly" + ;; +esac + +# Test 3: Verify that legitimate header with safe characters still works +LEGITIMATE_HEADER="Bearer test-token-123" +NVM_AUTH_HEADER="${LEGITIMATE_HEADER}" nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/dev/null 2>&1 || true + +# Test 4: Test with backticks (command substitution) +MALICIOUS_HEADER2="Bearer \`touch /tmp/nvm_security_test_file\`" +NVM_AUTH_HEADER="${MALICIOUS_HEADER2}" nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/dev/null 2>&1 || true + +# Verify that the malicious file was NOT created +if [ -f /tmp/nvm_security_test_file ]; then + die "SECURITY FAILURE: Command injection with backticks succeeded! Malicious file was created." +fi + +# Test 5: Test with $(command substitution) +MALICIOUS_HEADER3="Bearer \$(touch /tmp/nvm_security_test_file)" +NVM_AUTH_HEADER="${MALICIOUS_HEADER3}" nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/dev/null 2>&1 || true + +# Verify that the malicious file was NOT created +if [ -f /tmp/nvm_security_test_file ]; then + die "SECURITY FAILURE: Command injection with \$() succeeded! Malicious file was created." +fi + +cleanup +echo "All security tests passed: Command injection attacks are properly sanitized" diff --git a/test/fast/nvm should remove the last trailing slash in $NVM_DIR b/test/fast/nvm should remove the last trailing slash in $NVM_DIR index 4babb54..0f9f804 100755 --- a/test/fast/nvm should remove the last trailing slash in $NVM_DIR +++ b/test/fast/nvm should remove the last trailing slash in $NVM_DIR @@ -7,12 +7,14 @@ die () { echo "$@" ; exit 1; } export NVM_DIR_BASE="/tmp" export NVM_DIR="${NVM_DIR_BASE}/" +: nvm.sh \. ../../nvm.sh [ "${NVM_DIR}" = "${NVM_DIR_BASE}" ] || die 'nvm should remove the last trailing slash in "$NVM_DIR"' export NVM_DIR="${NVM_DIR_BASE}//" +: nvm.sh \. ../../nvm.sh [ "${NVM_DIR}" = "${NVM_DIR_BASE}" ] || die 'nvm should remove all the last trailing slashes in "$NVM_DIR"' diff --git a/test/installation_node/install from binary with binary flag set b/test/installation_node/install from binary with binary flag set index 434f0bf..c484431 100755 --- a/test/installation_node/install from binary with binary flag set +++ b/test/installation_node/install from binary with binary flag set @@ -43,6 +43,13 @@ nvm_install_source() { return 1 } +# Override nvm_get_make_jobs to produce predictable output regardless of actual CPU count +nvm_get_make_jobs() { + NVM_MAKE_JOBS=1 + nvm_echo "Detected that you have 2 CPU core(s)" + nvm_echo 'Number of CPU core(s) less than or equal to 2, running in single-threaded mode' +} + # binary fails, falls back to source if -b is not set OUTPUT="$(nvm install 9.0.0 2>&1)" EXPECTED_OUTPUT="binary failed diff --git a/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded b/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded index 9741195..69750d2 100755 --- a/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded +++ b/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded @@ -24,5 +24,10 @@ NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)" # NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)" NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)" -[ "_${NVM_ALIAS_DEFAULT}" = "_default -> 0.10.1 (-> v0.10.1)" ] \ - || die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '${NVM_ALIAS_DEFAULT}'" +[ "_${NVM_ALIAS_DEFAULT}" = "_default -> 0.10.1 (-> v0.10.1 *)" ] \ + || die "'nvm alias default' without colors did not return 'default -> 0.10.1 (-> v0.10.1 *)', got '${NVM_ALIAS_DEFAULT}'" + +nvm_has_colors() { return 0; } +NVM_ALIAS_DEFAULT_STRIPPED="$(nvm alias default | strip_colors)" +[ "_${NVM_ALIAS_DEFAULT_STRIPPED}" = "_default -> 0.10.1 (-> v0.10.1)" ] \ + || die "'nvm alias default' with colors stripped did not return 'default -> 0.10.1 (-> v0.10.1)', got '${NVM_ALIAS_DEFAULT_STRIPPED}'" diff --git a/test/sourcing/Sourcing nvm.sh with --install should install the default b/test/sourcing/Sourcing nvm.sh with --install should install the default index 1370233..4928f31 100755 --- a/test/sourcing/Sourcing nvm.sh with --install should install the default +++ b/test/sourcing/Sourcing nvm.sh with --install should install the default @@ -33,5 +33,10 @@ NVM_LS_CURRENT="$(nvm ls current | strip_colors | command grep -o v0.10.2)" [ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', >${NVM_LS_CURRENT}<\n$(nvm_ls)" NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)" -[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.2 (-> v0.10.2)" ] \ - || die "'nvm alias default did not return 'default -> 0.10.2 (-> v0.10.2)', got >${NVM_ALIAS_DEFAULT}<\n$(nvm_ls)" +[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.2 (-> v0.10.2 *)" ] \ + || die "'nvm alias default' without colors did not return 'default -> 0.10.2 (-> v0.10.2 *)', got >${NVM_ALIAS_DEFAULT}<\n$(nvm_ls)" + +nvm_has_colors() { return 0; } +NVM_ALIAS_DEFAULT_STRIPPED="$(nvm alias default | strip_colors)" +[ "_$NVM_ALIAS_DEFAULT_STRIPPED" = "_default -> 0.10.2 (-> v0.10.2)" ] \ + || die "'nvm alias default' with colors stripped did not return 'default -> 0.10.2 (-> v0.10.2)', got >${NVM_ALIAS_DEFAULT_STRIPPED}<\n$(nvm_ls)"