mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-07-18 12:58:21 +08:00
[Refactor] nvm_alias: use [[:space:]] instead of literal tab
[Tests] `nvm_alias`: add edge-case tests for hostile file content
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
export NVM_DIR="$(cd ../../.. && pwd)"
|
||||
|
||||
: nvm.sh
|
||||
\. "${NVM_DIR}/nvm.sh"
|
||||
|
||||
# Create an alias file where the first line has a valid version
|
||||
# followed by a second line of binary-like data
|
||||
printf 'v22.1.0\n' > ../../../alias/test-edge-binary
|
||||
printf '\001\002\003\377\n' >> ../../../alias/test-edge-binary
|
||||
ACTUAL="$(nvm_alias test-edge-binary)"
|
||||
# nvm_alias emits every non-blank, non-comment line — first line should be the version
|
||||
FIRST_LINE="$(nvm_echo "${ACTUAL}" | command head -n 1)"
|
||||
EXPECTED='v22.1.0'
|
||||
[ "${FIRST_LINE}" = "${EXPECTED}" ] || die "expected first line >${EXPECTED}<, got >${FIRST_LINE}<"
|
||||
|
||||
rm -f ../../../alias/test-edge-binary
|
||||
Reference in New Issue
Block a user