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 fileTake 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 back1#!/bin/sh23die () { echo "$@" ; cleanup ; exit 1; }4cleanup () {[Perf] `nvm_version`: resolve an exact, installed version without `nvm_ls`Cassidy Marblebefore adoptionc7ba8d2
line 5why, one step back5 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 back6}7[Tests] set `$_` before sourcing `nvm.sh` in fast testsJordan Harbandbefore adoptionc451e7a
line 8why, one step back8: nvm.sh[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
lines 9–10why, one step back9\. ../../../nvm.sh10[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
lines 11–12why, one step back11\. ../../common.sh12[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
lines 13–17why, one step back13nvm_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 back18try nvm_version current[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
line 19why, one step back19EXPECTED_OUTPUT="CURRENT!"[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
lines 20–21why, one step back20[ "_$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 back22[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
line 23why, one step back23try nvm_version[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
line 24why, one step back24EXPECTED_OUTPUT="CURRENT!"[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
lines 25–26why, one step back25[ "_$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 back2728nvm_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 back37nvm_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 back40nvm_ls() { echo "N/A"; }[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
line 41why, one step back41try nvm_version foo[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
line 42why, one step back42EXPECTED_OUTPUT="N/A"[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
lines 43–44why, one step back43[ "_$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 back4546nvm_ls() { echo; }[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
line 47why, one step back47try nvm_version foo[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
line 48why, one step back48EXPECTED_OUTPUT="N/A"[Tests] add `try`/`try_err` helpers; convert tests to use themJordan Harbandbefore adoption14d01c6
lines 49–50why, one step back49[ "_$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 back5152# 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