mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-08-20 04:23:43 +00:00
Compare commits
1 Commits
607f8af347
...
b0fc881b65
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b0fc881b65 |
3
.github/workflows/tests.yml
vendored
3
.github/workflows/tests.yml
vendored
@ -58,11 +58,12 @@ jobs:
|
|||||||
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
|
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
|
||||||
- run: curl --version
|
- run: curl --version
|
||||||
- run: wget --version
|
- run: wget --version
|
||||||
- uses: ljharb/actions/node/install@main
|
- uses: ljharb/actions/node/run@main
|
||||||
name: 'npm install && version checks'
|
name: 'npm install && version checks'
|
||||||
with:
|
with:
|
||||||
node-version: 'lts/*'
|
node-version: 'lts/*'
|
||||||
skip-ls-check: true
|
skip-ls-check: true
|
||||||
|
shell-command: echo installed
|
||||||
- run: npm ls urchin
|
- run: npm ls urchin
|
||||||
- run: npx which urchin
|
- run: npx which urchin
|
||||||
- run: env
|
- run: env
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -22,5 +22,3 @@ current
|
|||||||
npm-shrinkwrap.json
|
npm-shrinkwrap.json
|
||||||
package-lock.json
|
package-lock.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
|
||||||
target/
|
|
||||||
|
26
README.md
26
README.md
@ -6,7 +6,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|
||||||
# Node Version Manager [][3] [][4] [](https://bestpractices.dev/projects/684)
|
# Node Version Manager [][3] [][4] [](https://bestpractices.dev/projects/684)
|
||||||
|
|
||||||
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
|
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
|
||||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
@ -102,10 +102,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:
|
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
|
```sh
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
|
||||||
```
|
```
|
||||||
```sh
|
```sh
|
||||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/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 (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
|
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 (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
|
||||||
@ -127,7 +127,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.
|
- 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.1/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.0/install.sh | bash'`
|
||||||
|
|
||||||
#### Troubleshooting on Linux
|
#### Troubleshooting on Linux
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ You can use a task:
|
|||||||
```yaml
|
```yaml
|
||||||
- name: Install nvm
|
- name: Install nvm
|
||||||
ansible.builtin.shell: >
|
ansible.builtin.shell: >
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
|
||||||
args:
|
args:
|
||||||
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
||||||
```
|
```
|
||||||
@ -237,7 +237,7 @@ If you have `git` installed (requires git v1.7.10+):
|
|||||||
|
|
||||||
1. clone this repo in the root of your user profile
|
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`
|
- `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.1`
|
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.0`
|
||||||
1. activate `nvm` by sourcing it from your shell: `. ./nvm.sh`
|
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:
|
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
|
||||||
@ -843,13 +843,13 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
|
|||||||
### Alpine Linux 3.13+
|
### Alpine Linux 3.13+
|
||||||
```sh
|
```sh
|
||||||
apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
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.1/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
### Alpine Linux 3.5 - 3.12
|
### Alpine Linux 3.5 - 3.12
|
||||||
```sh
|
```sh
|
||||||
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
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.1/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/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._
|
_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._
|
||||||
@ -952,9 +952,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)
|
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
|
[1]: https://github.com/nvm-sh/nvm.git
|
||||||
[2]: https://github.com/nvm-sh/nvm/blob/v0.40.1/install.sh
|
[2]: https://github.com/nvm-sh/nvm/blob/v0.40.0/install.sh
|
||||||
[3]: https://app.travis-ci.com/nvm-sh/nvm
|
[3]: https://app.travis-ci.com/nvm-sh/nvm
|
||||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.1
|
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.0
|
||||||
[Urchin]: https://git.sdf.org/tlevine/urchin
|
[Urchin]: https://git.sdf.org/tlevine/urchin
|
||||||
[Fish]: https://fishshell.com
|
[Fish]: https://fishshell.com
|
||||||
|
|
||||||
@ -1012,7 +1012,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.
|
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.
|
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.
|
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.176)
|
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.076)
|
||||||
|
|
||||||
- Exit back to your native shell.
|
- Exit back to your native shell.
|
||||||
|
|
||||||
@ -1039,7 +1039,7 @@ Now you should be able to use node as usual.
|
|||||||
If you've encountered this error on WSL-2:
|
If you've encountered this error on WSL-2:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
|
||||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||||
Dload Upload Total Spent Left Speed
|
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
|
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com
|
||||||
@ -1074,7 +1074,7 @@ Currently, the sole maintainer is [@ljharb](https://github.com/ljharb) - more ma
|
|||||||
|
|
||||||
## Project Support
|
## Project Support
|
||||||
|
|
||||||
Only the latest version (v0.40.1 at this time) is supported.
|
Only the latest version (v0.40.0 at this time) is supported.
|
||||||
|
|
||||||
## Enterprise Support
|
## Enterprise Support
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ nvm_install_dir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nvm_latest_version() {
|
nvm_latest_version() {
|
||||||
nvm_echo "v0.40.1"
|
nvm_echo "v0.40.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_profile_is_bash_or_zsh() {
|
nvm_profile_is_bash_or_zsh() {
|
||||||
|
14
nvm.sh
14
nvm.sh
@ -2199,7 +2199,7 @@ nvm_install_binary_extract() {
|
|||||||
command mkdir -p "${VERSION_PATH}" || return 1
|
command mkdir -p "${VERSION_PATH}" || return 1
|
||||||
|
|
||||||
if [ "${NVM_OS}" = 'win' ]; then
|
if [ "${NVM_OS}" = 'win' ]; then
|
||||||
command mv "${TMPDIR}/"*/* "${VERSION_PATH}/" || return 1
|
command mv "${TMPDIR}/"*/* "${VERSION_PATH}" || return 1
|
||||||
command chmod +x "${VERSION_PATH}"/node.exe || return 1
|
command chmod +x "${VERSION_PATH}"/node.exe || return 1
|
||||||
command chmod +x "${VERSION_PATH}"/npm || return 1
|
command chmod +x "${VERSION_PATH}"/npm || return 1
|
||||||
command chmod +x "${VERSION_PATH}"/npx 2>/dev/null
|
command chmod +x "${VERSION_PATH}"/npx 2>/dev/null
|
||||||
@ -2278,8 +2278,8 @@ nvm_install_binary() {
|
|||||||
|
|
||||||
# Read nosource from arguments
|
# Read nosource from arguments
|
||||||
if [ "${nosource-}" = '1' ]; then
|
if [ "${nosource-}" = '1' ]; then
|
||||||
nvm_err 'Binary download failed. Download from source aborted.'
|
nvm_err 'Binary download failed. Download from source aborted.'
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nvm_err 'Binary download failed, trying source.'
|
nvm_err 'Binary download failed, trying source.'
|
||||||
@ -2922,11 +2922,11 @@ nvm_is_natural_num() {
|
|||||||
|
|
||||||
nvm_write_nvmrc() {
|
nvm_write_nvmrc() {
|
||||||
local VERSION_STRING
|
local VERSION_STRING
|
||||||
VERSION_STRING=$(nvm_version "${1-}")
|
VERSION_STRING=$(nvm_version "${1-$VERSION_STRING}")
|
||||||
if [ "${VERSION_STRING}" = '∞' ] || [ "${VERSION_STRING}" = 'N/A' ]; then
|
if [ "$VERSION_STRING" = '∞' ] || [ "$VERSION_STRING" = 'N/A' ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo "${VERSION_STRING}" | tee "$PWD"/.nvmrc > /dev/null || {
|
echo "$VERSION_STRING" | tee "$PWD"/.nvmrc > /dev/null || {
|
||||||
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
||||||
nvm_err "Warning: Unable to write version number ($VERSION_STRING) to .nvmrc"
|
nvm_err "Warning: Unable to write version number ($VERSION_STRING) to .nvmrc"
|
||||||
fi
|
fi
|
||||||
@ -4396,7 +4396,7 @@ nvm() {
|
|||||||
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
|
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
|
||||||
;;
|
;;
|
||||||
"--version" | "-v")
|
"--version" | "-v")
|
||||||
nvm_echo '0.40.1'
|
nvm_echo '0.40.0'
|
||||||
;;
|
;;
|
||||||
"unload")
|
"unload")
|
||||||
nvm deactivate >/dev/null 2>&1
|
nvm deactivate >/dev/null 2>&1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nvm",
|
"name": "nvm",
|
||||||
"version": "0.40.1",
|
"version": "0.40.0",
|
||||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
@ -14,8 +14,6 @@
|
|||||||
"test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node test-$shell",
|
"test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node test-$shell",
|
||||||
"test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell",
|
"test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell",
|
||||||
"test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell",
|
"test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell",
|
||||||
"test:check-exec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ ! -x \"$file\" ] && [[ \"$file\" != *.* ]] && [[ \"$file\" != test/fixtures/* ]]; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",
|
|
||||||
"test:check-nonexec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ -x \"$file\" ] && [ ! -d \"$file\" ] && { [[ \"$file\" =~ '\\.(json|txt|sh|js|log)$' ]] || [[ \"$file\" =~ '^test/(mocks|fixtures)/.*' ]]; }; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",
|
|
||||||
"doctoc": "doctoc --title='## Table of Contents' --github README.md",
|
"doctoc": "doctoc --title='## Table of Contents' --github README.md",
|
||||||
"predoctoc:check": "cp README.md v-README.md.orig && npm run doctoc",
|
"predoctoc:check": "cp README.md v-README.md.orig && npm run doctoc",
|
||||||
"doctoc:check": "diff -q README.md v-README.md.orig",
|
"doctoc:check": "diff -q README.md v-README.md.orig",
|
||||||
|
@ -4,58 +4,40 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
TEST_VERSION='v0.2.4'
|
TEST_VERSION="v0.2.4"
|
||||||
|
|
||||||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
||||||
|
|
||||||
cleanup() {
|
cleanup () {
|
||||||
nvm cache clear
|
nvm cache clear
|
||||||
nvm deactivate
|
nvm deactivate
|
||||||
nvm unalias default
|
nvm unalias default
|
||||||
rm -rf "${NVM_DIR}/v0.2.4" .nvmrc
|
rm -rf ${NVM_DIR}/v* .nvmrc
|
||||||
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
||||||
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die () {
|
||||||
echo "$@"
|
echo "$@"
|
||||||
cleanup
|
cleanup
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
|
||||||
nvm_ls_remote() {
|
nvm_ls_remote() {
|
||||||
if [ -n "${PATTERN}" ]; then
|
cat "$REMOTE"
|
||||||
cat "${REMOTE}" | \grep "${PATTERN}"
|
|
||||||
else
|
|
||||||
cat "${REMOTE}"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
||||||
nvm_ls_remote_iojs() {
|
nvm_ls_remote_iojs() {
|
||||||
local PATTERN
|
cat "$REMOTE_IOJS"
|
||||||
PATTERN="${1-}"
|
|
||||||
if [ -n "${PATTERN}" ]; then
|
|
||||||
cat "${REMOTE_IOJS}" | \grep "${PATTERN}"
|
|
||||||
else
|
|
||||||
cat "${REMOTE_IOJS}"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
make_fake_node "${TEST_VERSION}"
|
make_fake_node "$TEST_VERSION"
|
||||||
|
|
||||||
nvm install -w "${TEST_VERSION}" || die "\`nvm install -w ${TEST_VERSION}\` failed"
|
nvm install --save "$TEST_VERSION" || die "\`nvm install --save $TEST_VERSION\` failed"
|
||||||
OUTPUT="$(cat .nvmrc)"
|
OUTPUT="$(cat .nvmrc)"
|
||||||
|
|
||||||
nvm_is_valid_version "${OUTPUT}" \
|
nvm_is_valid_version "$(cat .nvmrc)" \
|
||||||
|| die "\`nvm install -w ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
|| die "\`nvm install --save $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
||||||
|
|
||||||
rm .nvmrc || die 'removing of .nvmrc failed'
|
|
||||||
|
|
||||||
nvm install --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"
|
|
||||||
OUTPUT="$(cat .nvmrc)"
|
|
||||||
|
|
||||||
nvm_is_valid_version "${OUTPUT}" \
|
|
||||||
|| die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
\. ../../../nvm.sh
|
|
||||||
\. ../../common.sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
TEST_VERSION='v0.2.4'
|
|
||||||
|
|
||||||
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
nvm cache clear
|
|
||||||
nvm deactivate
|
|
||||||
nvm unalias default
|
|
||||||
rm -rf "${NVM_DIR}/v0.2.4" .nvmrc
|
|
||||||
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
|
||||||
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
|
||||||
}
|
|
||||||
|
|
||||||
die() {
|
|
||||||
echo "$@"
|
|
||||||
cleanup
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
|
||||||
nvm_ls_remote() {
|
|
||||||
if [ -n "${PATTERN}" ]; then
|
|
||||||
cat "${REMOTE}" | \grep "${PATTERN}"
|
|
||||||
else
|
|
||||||
cat "${REMOTE}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
|
||||||
nvm_ls_remote_iojs() {
|
|
||||||
local PATTERN
|
|
||||||
PATTERN="${1-}"
|
|
||||||
if [ -n "${PATTERN}" ]; then
|
|
||||||
cat "${REMOTE_IOJS}" | \grep "${PATTERN}"
|
|
||||||
else
|
|
||||||
cat "${REMOTE_IOJS}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
make_fake_node "${TEST_VERSION}"
|
|
||||||
|
|
||||||
nvm use -w "${TEST_VERSION}" || die "\`nvm install -w ${TEST_VERSION}\` failed"
|
|
||||||
OUTPUT="$(cat .nvmrc)"
|
|
||||||
|
|
||||||
nvm_is_valid_version "${OUTPUT}" \
|
|
||||||
|| die "\`nvm install -w ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
|
||||||
|
|
||||||
rm .nvmrc || die 'removing of .nvmrc failed'
|
|
||||||
|
|
||||||
nvm use --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"
|
|
||||||
OUTPUT="$(cat .nvmrc)"
|
|
||||||
|
|
||||||
nvm_is_valid_version "${OUTPUT}" \
|
|
||||||
|| die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
|
||||||
|
|
||||||
cleanup
|
|
@ -12,7 +12,7 @@ cleanup () {
|
|||||||
nvm cache clear
|
nvm cache clear
|
||||||
nvm deactivate
|
nvm deactivate
|
||||||
nvm unalias default
|
nvm unalias default
|
||||||
rm -rf "${NVM_DIR}/${TEST_VERSION:?}" .nvmrc
|
rm -rf ${NVM_DIR}/v* .nvmrc
|
||||||
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
||||||
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||||
}
|
}
|
||||||
@ -23,29 +23,21 @@ die () {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
|
||||||
nvm_ls_remote() {
|
nvm_ls_remote() {
|
||||||
cat "${REMOTE}"
|
cat "$REMOTE"
|
||||||
}
|
}
|
||||||
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
|
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
||||||
nvm_ls_remote_iojs() {
|
nvm_ls_remote_iojs() {
|
||||||
cat "${REMOTE_IOJS}"
|
cat "$REMOTE_IOJS"
|
||||||
}
|
}
|
||||||
|
|
||||||
make_fake_node "${TEST_VERSION}"
|
make_fake_node "$TEST_VERSION"
|
||||||
|
|
||||||
OUTPUT=$(nvm use --save --silent "${TEST_VERSION}" || die "\`nvm use --save --silent ${TEST_VERSION}\` failed")
|
OUTPUT=$(nvm use --save --silent "$TEST_VERSION" || die "\`nvm use --save --silent $TEST_VERSION\` failed")
|
||||||
EXPECTED_OUTPUT=''
|
EXPECTED_OUTPUT=""
|
||||||
|
|
||||||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|| die "\`nvm use --save --silent ${TEST_VERSION}\` output was not silenced to '${EXPECTED_OUTPUT}'; got '${OUTPUT}'"
|
|| die "\`nvm use --save --silent $TEST_VERSION\` output was not silenced to '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
||||||
rm .nvmrc || die 'removing of .nvmrc failed'
|
|
||||||
|
|
||||||
OUTPUT=$(nvm use -w --silent "${TEST_VERSION}" || die "\`nvm use -w --silent ${TEST_VERSION}\` failed")
|
|
||||||
EXPECTED_OUTPUT=''
|
|
||||||
|
|
||||||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|
|
||||||
|| die "\`nvm use -w --silent ${TEST_VERSION}\` output was not silenced to '${EXPECTED_OUTPUT}'; got '${OUTPUT}'"
|
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
62
test/fast/Unit tests/Running 'nvm use -w' works as expected'
Executable file
62
test/fast/Unit tests/Running 'nvm use -w' works as expected'
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
||||||
|
|
||||||
|
TEST_VERSION="v0.2.4"
|
||||||
|
|
||||||
|
cleanup () {
|
||||||
|
nvm cache clear
|
||||||
|
nvm deactivate
|
||||||
|
nvm unalias default
|
||||||
|
rm -rf ${NVM_DIR}/v* .nvmrc
|
||||||
|
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
||||||
|
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||||
|
}
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo "$@"
|
||||||
|
cleanup
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm deactivate 2>/dev/null || die 'unable to deactivate'
|
||||||
|
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
|
||||||
|
nvm_ls_remote() {
|
||||||
|
cat "$REMOTE"
|
||||||
|
}
|
||||||
|
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
cat "$REMOTE_IOJS"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_fake_node "$TEST_VERSION"
|
||||||
|
|
||||||
|
# 1. install
|
||||||
|
|
||||||
|
nvm install -w "$TEST_VERSION" || die "\`nvm install -w $TEST_VERSION\` failed"
|
||||||
|
OUTPUT="$(cat .nvmrc)"
|
||||||
|
|
||||||
|
nvm_is_valid_version "$(cat .nvmrc)" \
|
||||||
|
|| die "\`nvm install -w $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
unset OUTPUT
|
||||||
|
|
||||||
|
# 2. use
|
||||||
|
|
||||||
|
nvm use -w "$TEST_VERSION" || die "\`nvm use -w $TEST_VERSION\` failed"
|
||||||
|
OUTPUT="$(cat .nvmrc)"
|
||||||
|
|
||||||
|
nvm_is_valid_version "$(cat .nvmrc)" \
|
||||||
|
|| die "\`nvm use -w $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
cleanup
|
@ -22,11 +22,11 @@ nvm deactivate 2>/dev/null || die 'unable to deactivate'
|
|||||||
|
|
||||||
\. ../../common.sh
|
\. ../../common.sh
|
||||||
|
|
||||||
MOCKS_DIR="${PWD}/mocks"
|
MOCKS_DIR="$PWD/mocks"
|
||||||
|
|
||||||
nvm_download() {
|
nvm_download() {
|
||||||
if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then
|
if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then
|
||||||
cat "${MOCKS_DIR}/nodejs.org-dist-index.tab"
|
cat "$MOCKS_DIR/nodejs.org-dist-index.tab"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
return 42
|
return 42
|
||||||
@ -34,15 +34,15 @@ nvm_download() {
|
|||||||
|
|
||||||
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote lts.txt"
|
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote lts.txt"
|
||||||
OUTPUT="$(nvm ls-remote --lts | sed 's/[ \t]*$//')"
|
OUTPUT="$(nvm ls-remote --lts | sed 's/[ \t]*$//')"
|
||||||
EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )"
|
EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"
|
||||||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote --lts did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm ls-remote --lts did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
|
||||||
|
|
||||||
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote lts.txt"
|
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote lts.txt"
|
||||||
OUTPUT="$(nvm ls-remote "lts/*" | sed 's/[ \t]*$//')"
|
OUTPUT="$(nvm ls-remote "lts/*" | sed 's/[ \t]*$//')"
|
||||||
EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )"
|
EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"
|
||||||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/* did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm ls-remote lts/* did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
|
||||||
|
|
||||||
MOCKS_DIR="${PWD}/mocks"
|
MOCKS_DIR="$PWD/mocks"
|
||||||
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
|
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
|
||||||
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"
|
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"
|
||||||
|
|
||||||
@ -56,18 +56,18 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do
|
|||||||
INDEX=$(($INDEX + 1))
|
INDEX=$(($INDEX + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
|
||||||
nvm_ls_remote() {
|
nvm_ls_remote() {
|
||||||
cat "${REMOTE}"
|
cat "$REMOTE"
|
||||||
}
|
}
|
||||||
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
|
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
||||||
nvm_ls_remote_iojs() {
|
nvm_ls_remote_iojs() {
|
||||||
cat "${REMOTE_IOJS}"
|
cat "$REMOTE_IOJS"
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote.txt"
|
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote.txt"
|
||||||
OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')"
|
OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')"
|
||||||
EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )"
|
EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"
|
||||||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "bare nvm ls-remote did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm ls-remote did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
cleanup () {
|
cleanup () {
|
||||||
unset -f die cleanup
|
unset -f die cleanup NVM_AUTH_HEADER
|
||||||
docker stop httpbin && docker rm httpbin
|
docker stop httpbin && docker rm httpbin
|
||||||
}
|
}
|
||||||
die () { echo "$@" ; cleanup ; exit 1; }
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
@ -17,12 +17,13 @@ nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/de
|
|||||||
! nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/wrong_install.sh" >/dev/null || die "nvm_download should fail to download no existing file"
|
! nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/wrong_install.sh" >/dev/null || die "nvm_download should fail to download no existing file"
|
||||||
|
|
||||||
# nvm_download should pass when calling with auth header
|
# nvm_download should pass when calling with auth header
|
||||||
docker pull kennethreitz/httpbin && SHELL=bash docker run -d --name httpbin -p 80:80 kennethreitz/httpbin
|
docker pull kennethreitz/httpbin && docker run --shell=bash -d --name httpbin -p 80:80 kennethreitz/httpbin
|
||||||
sleep 1 # wait for httpbin to start
|
sleep 1 # wait for httpbin to start
|
||||||
NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /dev/null || die 'nvm_download with auth header should send correctly'
|
NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /dev/null || die 'nvm_download with auth header should send correctly'
|
||||||
|
|
||||||
# nvm_download should fail when calling without auth header
|
# nvm_download should fail when calling without auth header
|
||||||
nvm_download "http://127.0.0.1/bearer" > /dev/null && die 'nvm_download with no auth header should not send the header and should fail'
|
nvm_download "http://127.0.0.1/bearer" > /dev/null && die 'nvm_download with no auth header should not send the header and should fail'
|
||||||
|
docker stop httpbin && docker rm httpbin
|
||||||
|
|
||||||
# ensure quoted extra args remain quoted
|
# ensure quoted extra args remain quoted
|
||||||
nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" -o "; die quoted-command-not-quoted" || die 'command failed'
|
nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" -o "; die quoted-command-not-quoted" || die 'command failed'
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
# Save the PATH as it was when the test started to restore it when it
|
# Save the PATH as it was when the test started to restore it when it
|
||||||
# finishes
|
# finishes
|
||||||
ORIG_PATH="${PATH}"
|
ORIG_PATH=$PATH
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
# Restore the PATH as it was when the test started
|
# Restore the PATH as it was when the test started
|
||||||
export PATH="${ORIG_PATH}"
|
export PATH=ORIG_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
die () { cleanup; echo "$@" ; exit 1; }
|
die () { cleanup; echo "$@" ; exit 1; }
|
||||||
@ -15,23 +15,20 @@ die () { cleanup; echo "$@" ; exit 1; }
|
|||||||
|
|
||||||
# Directory where mocked binaries used by nvm_get_arch for each OS/arch are
|
# Directory where mocked binaries used by nvm_get_arch for each OS/arch are
|
||||||
# located
|
# located
|
||||||
MOCKS_DIR="$(pwd)/../../mocks"
|
MOCKS_DIR=`pwd`/../../mocks
|
||||||
# Sets the PATH for these tests to include the symlinks to the mocked
|
# Sets the PATH for these tests to include the symlinks to the mocked
|
||||||
# binaries
|
# binaries
|
||||||
export PATH=".:${PATH}"
|
export PATH=.:${PATH}
|
||||||
|
|
||||||
# Setups mock binaries for a given OS and arch that mimic
|
# Setups mock binaries for a given OS and arch that mimic
|
||||||
# the output of the real binaries used by nvm_get_arch to guess
|
# the output of the real binaries used by nvm_get_arch to guess
|
||||||
# the architecture of a given system.
|
# the architecture of a given system.
|
||||||
setup_mock_arch() {
|
setup_mock_arch() {
|
||||||
local OS
|
local OS=$1
|
||||||
OS=$1
|
local ARCH=$2
|
||||||
local ARCH
|
local OPT=$3
|
||||||
ARCH=$2
|
|
||||||
local OPT
|
|
||||||
OPT=$3
|
|
||||||
|
|
||||||
if [ "_${OS}" = '_solaris' ] || [ "_${OS}" = '_smartos' ]; then
|
if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then
|
||||||
ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo
|
ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo
|
||||||
if [ "_$OPT" != "_no_pkg_info" ]; then
|
if [ "_$OPT" != "_no_pkg_info" ]; then
|
||||||
ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info
|
ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info
|
||||||
@ -45,12 +42,10 @@ setup_mock_arch() {
|
|||||||
|
|
||||||
# Cleans up the setup done by setup_mock_arch.
|
# Cleans up the setup done by setup_mock_arch.
|
||||||
cleanup_mock_arch() {
|
cleanup_mock_arch() {
|
||||||
local OS
|
local OS=$1
|
||||||
OS=$1
|
local ARCH=$2
|
||||||
local ARCH
|
|
||||||
ARCH=$2
|
|
||||||
|
|
||||||
if [ "_${OS}" = '_solaris' ] || [ "_${OS}" = '_smartos' ]; then
|
if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then
|
||||||
rm -f ./isainfo
|
rm -f ./isainfo
|
||||||
rm -f ./pkg_info
|
rm -f ./pkg_info
|
||||||
fi
|
fi
|
||||||
@ -62,22 +57,17 @@ cleanup_mock_arch() {
|
|||||||
# expected output $EXPECTED_OUTPUT with the actual output. Does nothing
|
# expected output $EXPECTED_OUTPUT with the actual output. Does nothing
|
||||||
# and exits cleanly if they match, dies otherwise.
|
# and exits cleanly if they match, dies otherwise.
|
||||||
run_test() {
|
run_test() {
|
||||||
local ARCH
|
local ARCH=$1
|
||||||
ARCH=$1
|
local OS=$2
|
||||||
local OS
|
local EXPECTED_OUTPUT=$3
|
||||||
OS=$2
|
local OPT=$4
|
||||||
local EXPECTED_OUTPUT
|
|
||||||
EXPECTED_OUTPUT=$3
|
|
||||||
local OPT
|
|
||||||
OPT=$4
|
|
||||||
|
|
||||||
setup_mock_arch "${OS}" "${ARCH}" "${OPT}"
|
setup_mock_arch $OS $ARCH $OPT
|
||||||
local OUTPUT
|
local OUTPUT="$(nvm_get_arch)"
|
||||||
OUTPUT="$(nvm_get_arch)"
|
cleanup_mock_arch $OS $ARCH
|
||||||
cleanup_mock_arch "${OS}" "${ARCH}"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] ||
|
||||||
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] ||
|
die "nvm_get_arch for OS \"$OS\" and arch \"$ARCH\" with OPT \"$OPT\" did
|
||||||
die "nvm_get_arch for OS \"${OS}\" and arch \"${ARCH}\" with OPT \"${OPT}\" did
|
not return \"$EXPECTED_OUTPUT\"; got \"$OUTPUT\""
|
||||||
not return \"${EXPECTED_OUTPUT}\"; got \"${OUTPUT}\""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test x86 smartos x86
|
run_test x86 smartos x86
|
||||||
|
@ -2,29 +2,27 @@
|
|||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
FILE="${NVM_DIR}/default-packages"
|
FILE="$NVM_DIR/default-packages"
|
||||||
|
|
||||||
die () { echo "$@" ; cleanup ; exit 1; }
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
setup () {
|
setup () {
|
||||||
if [ -f "${FILE}" ]; then
|
if [ -f $FILE ]; then
|
||||||
ORIG_DEFAULT_PACKAGES=$(cat "${FILE}")
|
ORIG_DEFAULT_PACKAGES=$(cat $FILE)
|
||||||
mkdir -p ./tmp/ ||:
|
mkdir -p ./tmp/ ||:
|
||||||
mv "${FILE}" ./tmp/default-packages ||:
|
mv $FILE ./tmp/default-packages ||:
|
||||||
fi
|
fi
|
||||||
touch "${FILE}"
|
touch $FILE
|
||||||
}
|
}
|
||||||
cleanup () {
|
cleanup () {
|
||||||
if [ "${ORIG_DEFAULT_PACKAGES}" != "" ]; then
|
if [ "$ORIG_DEFAULT_PACKAGES" != "" ]; then
|
||||||
rm -rf ./tmp/
|
rm -rf ./tmp/
|
||||||
echo "${ORIG_DEFAULT_PACKAGES}" > "${FILE}"
|
echo "$ORIG_DEFAULT_PACKAGES" > $FILE
|
||||||
else
|
|
||||||
rm "${FILE}"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
setup
|
setup
|
||||||
|
|
||||||
cat > "${FILE}" << EOF
|
cat > $FILE << EOF
|
||||||
rimraf
|
rimraf
|
||||||
object-inspect@1.0.2
|
object-inspect@1.0.2
|
||||||
|
|
||||||
@ -41,7 +39,7 @@ cleanup
|
|||||||
|
|
||||||
setup
|
setup
|
||||||
|
|
||||||
cat > "${FILE}" << EOF
|
cat > $FILE << EOF
|
||||||
rimraf
|
rimraf
|
||||||
not~a~package~name
|
not~a~package~name
|
||||||
mkdirp
|
mkdirp
|
||||||
@ -55,12 +53,12 @@ cleanup
|
|||||||
|
|
||||||
setup
|
setup
|
||||||
|
|
||||||
cat > "${FILE}" << EOF
|
cat > $FILE << EOF
|
||||||
rimraf
|
rimraf
|
||||||
not~a~package~name
|
not~a~package~name
|
||||||
mkdirp
|
mkdirp
|
||||||
EOF
|
EOF
|
||||||
printf %s "$(cat "${FILE}")" > "${FILE}" # strip trailing newline
|
printf %s "$(cat "${FILE}")" > $FILE # strip trailing newline
|
||||||
|
|
||||||
DEFAULT_PKGS="$(nvm_get_default_packages)"
|
DEFAULT_PKGS="$(nvm_get_default_packages)"
|
||||||
EXPECTED_PKGS='rimraf not~a~package~name mkdirp'
|
EXPECTED_PKGS='rimraf not~a~package~name mkdirp'
|
||||||
@ -70,7 +68,7 @@ cleanup
|
|||||||
|
|
||||||
setup
|
setup
|
||||||
|
|
||||||
cat > "${FILE}" << EOF
|
cat > $FILE << EOF
|
||||||
object-inspect @ 1.0.2
|
object-inspect @ 1.0.2
|
||||||
rimraf
|
rimraf
|
||||||
EOF
|
EOF
|
||||||
@ -83,12 +81,12 @@ cleanup
|
|||||||
|
|
||||||
setup
|
setup
|
||||||
|
|
||||||
rm -rf "${FILE}"
|
rm -rf $FILE
|
||||||
|
|
||||||
DEFAULT_PKGS="$(nvm_get_default_packages)"
|
DEFAULT_PKGS="$(nvm_get_default_packages)"
|
||||||
EXPECTED_PKGS=''
|
EXPECTED_PKGS=''
|
||||||
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "5: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
|
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "5: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
|
||||||
|
|
||||||
touch "${FILE}"
|
touch $FILE
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
@ -1,43 +1,33 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
cleanup() {
|
cleanup () {
|
||||||
[ -d "${tmp_dir}" ] && rm -rf "${tmp_dir}"
|
[ -d "$tmp_dir" ] && rm -rf "$tmp_dir"
|
||||||
[ -d "${NVM_DIR}" ] && rm -rf "${NVM_DIR}"
|
[ -d "$NVM_DIR" ] && rm -rf "$NVM_DIR"
|
||||||
unset -f die cleanup test_archi nvm_supports_xz
|
unset -f die cleanup test_archi nvm_supports_xz
|
||||||
unset NVM_DIR tmp_dir version archi
|
unset NVM_DIR tmp_dir version archi
|
||||||
}
|
}
|
||||||
|
|
||||||
die() { echo "$@" ; cleanup ; exit 1; }
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
test_archi() {
|
test_archi(){
|
||||||
local os
|
local os="$1"
|
||||||
os="$1"
|
local version="$2"
|
||||||
local version
|
local archi="$os-$3"
|
||||||
version="$2"
|
local node="$4"
|
||||||
local archi
|
local ext="$5"
|
||||||
archi="$os-$3"
|
local command="$6"
|
||||||
local node
|
local command_option="$7"
|
||||||
node="$4"
|
local node_path="$tmp_dir/node-$version-$archi/$node"
|
||||||
local ext
|
|
||||||
ext="$5"
|
|
||||||
local command
|
|
||||||
command="$6"
|
|
||||||
local command_option
|
|
||||||
command_option="$7"
|
|
||||||
local node_dir
|
|
||||||
node_dir="${tmp_dir}/node-${version}-${archi}"
|
|
||||||
local node_path
|
|
||||||
node_path="${node_dir}/${node}"
|
|
||||||
|
|
||||||
# Create tarball
|
# Create tarball
|
||||||
mkdir -p "$(dirname "${node_path}")"
|
mkdir -p "$(dirname "$node_path")"
|
||||||
echo "node ${version}" > "${node_path}"
|
echo "node $version" > "$node_path"
|
||||||
(cd "${tmp_dir}" && "${command}" "${command_option}" "${node_dir}.${ext}" "node-${version}-${archi}")
|
(cd "$tmp_dir" && "$command" "$command_option" "$tmp_dir/node-$version-$archi.$ext" "node-$version-$archi" && rm -rf "$tmp_dir/node-$version-$archi")
|
||||||
[ -f "${node_dir}.${ext}" ] || die "Unable to create fake ${ext} file"
|
[ -f "$tmp_dir/node-$version-$archi.$ext" ] || die "Unable to create fake $ext file"
|
||||||
|
|
||||||
# Extract it
|
# Extract it
|
||||||
nvm_install_binary_extract "$os" "$version" "$(expr "${version}" : '.\(.*\)')" "${node_dir}.$ext" "${tmp_dir}/files"
|
nvm_install_binary_extract "$os" "$version" "${version:1}" "$tmp_dir/node-$version-$archi.$ext" "$tmp_dir/files"
|
||||||
[ "$(cat "${NVM_DIR}/versions/node/${version}/bin/node")" = "node ${version}" ] || die "Unable to extract ${ext} file"
|
[ "$(cat "$NVM_DIR/versions/node/$version/bin/node")" = "node $version" ] || die "Unable to extract $ext file"
|
||||||
}
|
}
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
@ -49,18 +39,17 @@ type nvm_install_binary_extract > /dev/null 2>&1 || die 'nvm_install_binary_extr
|
|||||||
|
|
||||||
NVM_DIR=$(mktemp -d)
|
NVM_DIR=$(mktemp -d)
|
||||||
tmp_dir=$(mktemp -d)
|
tmp_dir=$(mktemp -d)
|
||||||
if [ -z "${NVM_DIR}" ] || [ -z "${tmp_dir}" ]; then
|
if [ -z "$NVM_DIR" ] || [ -z "$tmp_dir" ]; then
|
||||||
die 'Unable to create temporary folder'
|
die 'Unable to create temporary folder'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Test windows zip
|
# Test windows zip
|
||||||
# TODO: enable this
|
test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'
|
||||||
# test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'
|
|
||||||
|
|
||||||
# Test linux tar.xz
|
# Test linux tar.xz
|
||||||
test_archi 'linux' 'v14.15.4' 'x64' 'bin/node' 'tar.xz' 'tar' '-cJf'
|
test_archi 'linux' 'v14.15.4' 'x64' 'bin/node' 'tar.xz' 'tar' '-cJf'
|
||||||
|
|
||||||
nvm_supports_xz() {
|
nvm_supports_xz(){
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,11 @@ die () { >&2 echo "$@" ; cleanup ; exit 1; }
|
|||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
nvm_has_colors() { return 1 ; }
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
OUTPUT="$(TERM=dumb 2>&1 nvm install --no-progress v0.12.18)"
|
OUTPUT="$(2>&1 nvm install --no-progress v0.12.18)"
|
||||||
EXPECTED_OUTPUT="Downloading and installing node v0.12.18...
|
EXPECTED_OUTPUT="Downloading and installing node v0.12.18...
|
||||||
Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...
|
Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...
|
||||||
Computing checksum with sha256sum
|
Computing checksum with sha256sum
|
||||||
@ -23,63 +25,19 @@ Checksums matched!
|
|||||||
Now using node v0.12.18 (npm v2.15.11)
|
Now using node v0.12.18 (npm v2.15.11)
|
||||||
Creating default alias: default -> v0.12.18 *"
|
Creating default alias: default -> v0.12.18 *"
|
||||||
|
|
||||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "1: expected >
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
||||||
${EXPECTED_OUTPUT}<, got >
|
|
||||||
${OUTPUT}<"
|
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
OUTPUT="$(TERM=dumb 2>&1 nvm install v0.12.18)"
|
OUTPUT="$(2>&1 nvm install v0.12.18)"
|
||||||
EXPECTED_OUTPUT="Downloading and installing node v0.12.18...
|
EXPECTED_OUTPUT="Downloading and installing node v0.12.18...
|
||||||
Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...
|
Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz...
|
||||||
######################################################################### 100.0%
|
######################################################################## 100.0%
|
||||||
Computing checksum with sha256sum
|
Computing checksum with sha256sum
|
||||||
Checksums matched!
|
Checksums matched!
|
||||||
Now using node v0.12.18 (npm v2.15.11)
|
Now using node v0.12.18 (npm v2.15.11)
|
||||||
Creating default alias: default -> v0.12.18 *"
|
Creating default alias: default -> v0.12.18 *"
|
||||||
|
|
||||||
[ "$(echo "${OUTPUT}" | wc -l)" = "$(echo "${EXPECTED_OUTPUT}" | wc -l)" ] || die "2: expected 7 lines, got $(echo "${OUTPUT}" | wc -l)"
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
||||||
|
|
||||||
# Preprocess function to handle carriage returns and extract final output
|
|
||||||
preprocess_output() {
|
|
||||||
echo "$1" | awk '
|
|
||||||
{
|
|
||||||
# For each line in the input
|
|
||||||
while (index($0, "\r") > 0) {
|
|
||||||
# If a carriage return is found, process it
|
|
||||||
pos = index($0, "\r")
|
|
||||||
before_cr = substr($0, 1, pos - 1)
|
|
||||||
after_cr = substr($0, pos + 1)
|
|
||||||
# Overwrite the line up to the carriage return with content after it
|
|
||||||
$0 = after_cr
|
|
||||||
}
|
|
||||||
print $0
|
|
||||||
}' | sed '/^$/d' # Remove any empty lines
|
|
||||||
}
|
|
||||||
|
|
||||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || {
|
|
||||||
echo "$OUTPUT" \
|
|
||||||
| while IFS= read -r output_line && IFS= read -r expected_line <&3; do
|
|
||||||
line_number=$((line_number + 1))
|
|
||||||
|
|
||||||
# Strip non-visible characters from both lines
|
|
||||||
clean_output=$(preprocess_output "$output_line")
|
|
||||||
|
|
||||||
if [ "${output_line}" != "${expected_line}" ] && ! echo "${clean_output}" | \grep -qE '^#+ 100\.0%$'; then
|
|
||||||
echo "Difference on line ${line_number}:"
|
|
||||||
echo "Output: ${output_line}"
|
|
||||||
echo "Expected: ${expected_line}"
|
|
||||||
echo "Byte-by-byte comparison:"
|
|
||||||
echo "Output: $(echo "${clean_output}" | od -An -tx1 | tr -d '\n')"
|
|
||||||
echo "Expected: $(echo "${expected_line}" | od -An -tx1 | tr -d '\n')"
|
|
||||||
|
|
||||||
die "4: expected >
|
|
||||||
${EXPECTED_OUTPUT}<, got >
|
|
||||||
${OUTPUT}<"
|
|
||||||
fi
|
|
||||||
done 3<<EOF
|
|
||||||
$EXPECTED_OUTPUT
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
0
test/installation_iojs/install from source
Normal file → Executable file
0
test/installation_iojs/install from source
Normal file → Executable file
0
test/installation_iojs/install version specified in .nvmrc from source
Normal file → Executable file
0
test/installation_iojs/install version specified in .nvmrc from source
Normal file → Executable file
@ -1,10 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
die () {
|
die () { echo "$@" ; exit 1; }
|
||||||
unset -f nvm_install_binary nvm_install_source
|
|
||||||
echo "$@"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
|
|
||||||
@ -26,28 +22,16 @@ nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $N
|
|||||||
NVM_CURRENT_DEFAULT="$(nvm_alias default)"
|
NVM_CURRENT_DEFAULT="$(nvm_alias default)"
|
||||||
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"
|
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"
|
||||||
|
|
||||||
nvm_install_binary() {
|
# Falls back to source but if -b is set fails binary download.
|
||||||
>&2 echo 'binary failed'
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# binary fails, falls back to source, but if -b is set, fails
|
|
||||||
OUTPUT="$(nvm install -b 9.0.0 2>&1)"
|
OUTPUT="$(nvm install -b 9.0.0 2>&1)"
|
||||||
EXPECTED_OUTPUT='binary failed'
|
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||||
if [ "${OUTPUT#*"${EXPECTED_OUTPUT}"}" = "${OUTPUT}" ]; then
|
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
|
||||||
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nvm_install_source() {
|
# Falls back to source but if -b is not set.
|
||||||
>&2 echo 'source intentionally failed'
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# binary fails, falls back to source if -b is not set
|
|
||||||
OUTPUT="$(nvm install 9.0.0 2>&1)"
|
OUTPUT="$(nvm install 9.0.0 2>&1)"
|
||||||
EXPECTED_OUTPUT="binary failed
|
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||||
Detected that you have 2 CPU core(s)
|
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then
|
||||||
Number of CPU core(s) less than or equal to 2, running in single-threaded mode
|
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
||||||
source intentionally failed"
|
fi
|
||||||
|
|
||||||
[ "${EXPECTED_OUTPUT}" = "${OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
|
||||||
|
0
test/slow/nvm exec/Running 'nvm exec' with help should not parse
Normal file → Executable file
0
test/slow/nvm exec/Running 'nvm exec' with help should not parse
Normal file → Executable file
0
test/slow/nvm reinstall-packages/test-npmlink/index.js
Normal file → Executable file
0
test/slow/nvm reinstall-packages/test-npmlink/index.js
Normal file → Executable file
0
test/slow/nvm reinstall-packages/test-npmlink/package.json
Normal file → Executable file
0
test/slow/nvm reinstall-packages/test-npmlink/package.json
Normal file → Executable file
0
test/slow/nvm use/Running 'nvm use' with nvmrc containing not installed version
Normal file → Executable file
0
test/slow/nvm use/Running 'nvm use' with nvmrc containing not installed version
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user