Skip to content
Myr

[Fix] `set -E`: Add test for `node install` on Bash with an ERR trap and `set -E`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Luke Arms · committed by Jordan Harband · parent fb4538b · Browse files · 2 files+59 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+59 added−0 removed

  • tests:+50 added−0 removed
  • other:+9 added−0 removed

2 files+59 added−0 removed

added:test/installation_node/install on bash with ERR trap and set -E+50 added
1#!/bin/sh23set -e45cleanup() {6 nvm cache clear7 nvm deactivate8 rm -rf "${NVM_DIR}"/v*9 nvm unalias default10}1112die() {13 echo "$@"14 cleanup || true15 exit 116}1718\. ../../nvm.sh1920if [ -z "${BASH-}" ]; then21 echo "This test only applies to Bash; skipping"22 exit23fi2425cleanup || true26trap 'echo "==> EXIT signal received (status: $?)"; cleanup' EXIT2728# shellcheck disable=SC304729trap 'echo "==> ERR signal received"; exit 1' ERR30# shellcheck disable=SC304131set -E3233# shellcheck disable=SC3045,SC304734ERR_TRAP_EXPECTED="$(trap -p ERR)"3536# Adding ` || die 'install failed'` implicitly disables error handling and37# prevents ERR trap execution, so for the purposes of this test, `nvm install`38# can't be part of another command or statement39nvm install node4041case "$-" in42*E*)43 # shellcheck disable=SC3045,SC304744 [ "$(trap -p ERR)" = "$ERR_TRAP_EXPECTED" ] ||45 die "ERR trap not restored after \"nvm install $VERSION\""46 ;;47*)48 die "errtrace not restored after \"nvm install $VERSION\""49 ;;50esac
modified:nvm.sh+9 added
2740 unmodified lines
2741 IFS="${DEFAULT_IFS}" nvm "$@"2742 EXIT_CODE="$?"2743 set -a2744 return "$EXIT_CODE"2745 elif [ -n "${BASH-}" ] && [ "${-#*E}" != "$-" ]; then2746 # shellcheck disable=SC30412747 set +E2748 local EXIT_CODE2749 IFS="${DEFAULT_IFS}" nvm "$@"2750 EXIT_CODE="$?"2751 # shellcheck disable=SC30412752 set -E2753 return "$EXIT_CODE"2754 elif [ "${IFS}" != "${DEFAULT_IFS}" ]; then2755 IFS="${DEFAULT_IFS}" nvm "$@"2756 return "$?"2757 fi
1594 unmodified lines