Skip to content
Myr

nvm_version

This file

Path

test/fast/Unit tests/nvm_version

77 lines · 3.3 KiB

Last changed by

[Perf] `nvm_version`: resolve an exact, installed version without `nvm_ls`Cassidy Marblebefore adoptionc7ba8d2

History of this file

Take it

The walk stopped after 200 commits: lines older than 5c12680 point at it.

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

lines 1–4why, one step back
1#!/bin/sh
23die () { echo "$@" ; cleanup ; exit 1; }4cleanup () {

[Perf] `nvm_version`: resolve an exact, installed version without `nvm_ls`Cassidy Marblebefore adoptionc7ba8d2

line 5why, one step back
5 unset -f nvm_ls_current nvm_ls nvm_is_version_installed

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

lines 6–7why, one step back
6}
7

[Tests] set `$_` before sourcing `nvm.sh` in fast testsJordan Harbandbefore adoptionc451e7a

line 8why, one step back
8: nvm.sh

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

lines 9–10why, one step back
9\. ../../../nvm.sh
10

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

lines 11–12why, one step back
11\. ../../common.sh
12

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

lines 13–17why, one step back
13nvm_ls_current() {
14 echo "CURRENT!"15 return 716}17

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

line 18why, one step back
18try nvm_version current

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

line 19why, one step back
19EXPECTED_OUTPUT="CURRENT!"

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

lines 20–21why, one step back
20[ "_$CAPTURED_STDOUT" = "_$EXPECTED_OUTPUT" ] || die '"nvm_version current" did not return nvm_ls_current output'
21[ "_$CAPTURED_EXIT_CODE" = "_7" ] || die '"nvm_version current" did not return nvm_ls_current exit code'

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

line 22why, one step back
22

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

line 23why, one step back
23try nvm_version

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

line 24why, one step back
24EXPECTED_OUTPUT="CURRENT!"

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

lines 25–26why, one step back
25[ "_$CAPTURED_STDOUT" = "_$EXPECTED_OUTPUT" ] || die '"nvm_version" did not return nvm_ls_current output'
26[ "_$CAPTURED_EXIT_CODE" = "_7" ] || die '"nvm_version" did not return nvm_ls_current exit code'

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

lines 27–36why, one step back
27
28nvm_ls() {29 echo "line 1"30 echo "line 2"31 echo "pattern: $1"32}33[ "_$(nvm_version foo)" = "_pattern: foo" ] || die '"nvm_version foo" did not pass the pattern to "nvm_ls", or return the last line'34[ "_$(nvm_version node)" = "_pattern: stable" ] || die '"nvm_version node" did not pass "stable" to "nvm_ls"'35[ "_$(nvm_version node-)" = "_pattern: stable" ] || die '"nvm_version node-" did not pass "stable" to "nvm_ls"'36

[patch] show system Node.js version in nvm lsPeter Dave Hellobefore adoption29a652f

lines 37–39why, one step back
37nvm_ls() { echo "system v20.0.0"; }
38[ "_$(nvm_version system)" = "_system" ] || die '"nvm_version system" did not return "system" when "nvm_ls" returns extra columns'39

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

line 40why, one step back
40nvm_ls() { echo "N/A"; }

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

line 41why, one step back
41try nvm_version foo

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

line 42why, one step back
42EXPECTED_OUTPUT="N/A"

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

lines 43–44why, one step back
43[ "_$CAPTURED_STDOUT" = "_$EXPECTED_OUTPUT" ] || die '"nvm_version" did not return N/A when nvm_ls returns N/A'
44[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die '"nvm_version" returning N/A did not exit code with code 3'

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

lines 45–46why, one step back
45
46nvm_ls() { echo; }

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

line 47why, one step back
47try nvm_version foo

[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680

line 48why, one step back
48EXPECTED_OUTPUT="N/A"

[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6

lines 49–50why, one step back
49[ "_$CAPTURED_STDOUT" = "_$EXPECTED_OUTPUT" ] || die '"nvm_version" did not return N/A when nvm_ls returns nothing'
50[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die '"nvm_version" returning N/A did not exit code with code 3'

[Perf] `nvm_version`: resolve an exact, installed version without `nvm_ls`Cassidy Marblebefore adoptionc7ba8d2

lines 51–77why, one step back
51
52# an exact installed version resolves without forking "nvm_ls"53nvm_is_version_installed() { return 0; }54nvm_ls() { die '"nvm_version" must not call "nvm_ls" for an exact installed version'; }55try nvm_version v1.2.356EXPECTED_OUTPUT="v1.2.3"57[ "_$CAPTURED_STDOUT" = "_$EXPECTED_OUTPUT" ] || die '"nvm_version v1.2.3" did not return the version itself; got '"$CAPTURED_STDOUT"58[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die '"nvm_version v1.2.3" did not exit 0; got '"$CAPTURED_EXIT_CODE"5960# an exact version that is not installed still falls back to "nvm_ls"61nvm_is_version_installed() { return 1; }62nvm_ls() { echo "pattern: $1"; }63try nvm_version v1.2.364EXPECTED_OUTPUT="pattern: v1.2.3"65[ "_$CAPTURED_STDOUT" = "_$EXPECTED_OUTPUT" ] || die '"nvm_version v1.2.3" did not fall back to "nvm_ls"; got '"$CAPTURED_STDOUT"66[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die '"nvm_version v1.2.3" did not exit 0; got '"$CAPTURED_EXIT_CODE"6768# only exact, fully-qualified versions take the fast path69nvm_is_version_installed() { die '"nvm_version" must not call "nvm_is_version_installed" for non-exact versions'; }70nvm_ls() { echo "pattern: $1"; }71for PATTERN in v1.2 v1 1.2.3 v1.2.3-rc.1 v1.2.3.4 v1.2.3.; do72 try nvm_version "$PATTERN"73 EXPECTED_OUTPUT="pattern: $PATTERN"74 [ "_$CAPTURED_STDOUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_version $PATTERN did not fall back to nvm_ls; got $CAPTURED_STDOUT"75 [ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_version $PATTERN did not exit 0; got $CAPTURED_EXIT_CODE"76done77unset -f nvm_is_version_installed