nvm_detect_profile
This file
Path
test/install_script/nvm_detect_profile
151 lines · 5.0 KiB
Last changed by
Not known.
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–151why, one step back1#!/bin/sh23setup () {4 HOME="."5 NVM_ENV=testing \. ../../install.sh6 ZDOTDIR="$HOME/zdotdir"7 mkdir -p zdotdir8 touch ".bashrc"9 touch ".bash_profile"10 touch ".zprofile"11 touch ".zshrc"12 touch ".profile"13 touch "test_profile"14 touch "zdotdir/.zshrc"15 touch "zdotdir/.zprofile"16}1718cleanup () {19 unset HOME20 unset NVM_ENV21 unset NVM_DETECT_PROFILE22 unset SHELL23 unset -f setup cleanup die24 unset ZDOTDIR25 rm -f ".bashrc" ".bash_profile" ".zprofile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&126 rm -rf zdotdir 2>&127}2829die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }3031setup3233#34# Confirm profile detection via $SHELL works and that $PROFILE overrides profile detection35#3637# setting $PROFILE to /dev/null should return no detected profile38NVM_DETECT_PROFILE="$(PROFILE='/dev/null' nvm_detect_profile)"39if [ -n "$NVM_DETECT_PROFILE" ]; then40 die "nvm_detect_profile still detected a profile even though PROFILE=/dev/null"41fi4243# .bashrc should be detected for bash44NVM_DETECT_PROFILE="$(SHELL="/bin/bash" PROFILE= nvm_detect_profile)"45if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then46 die "nvm_detect_profile didn't pick \$HOME/.bashrc for bash"47fi4849# $PROFILE should override .bashrc profile detection50NVM_DETECT_PROFILE="$(SHELL="/bin/bash" PROFILE="test_profile" nvm_detect_profile)"51if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then52 die "nvm_detect_profile ignored \$PROFILE"53fi5455# zdotdir/.zshrc should be detected for zsh56NVM_DETECT_PROFILE="$(SHELL="/bin/zsh" PROFILE= nvm_detect_profile)"57if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zshrc" ]; then58 die "nvm_detect_profile didn't pick \$ZDOTDIR/.zshrc for zsh"59fi6061# .zshrc should be detected for zsh62NVM_DETECT_PROFILE="$(SHELL="/bin/zsh" PROFILE= ZDOTDIR= nvm_detect_profile)"63if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then64 die "nvm_detect_profile didn't pick \$HOME/.zshrc for zsh"65fi6667# $PROFILE should override .zshrc profile detection68NVM_DETECT_PROFILE="$(SHELL="/usr/bin/zsh" PROFILE="test_profile" nvm_detect_profile)"69if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then70 die "nvm_detect_profile ignored \$PROFILE"71fi7273#74# Confirm $PROFILE is only returned when it points to a valid file75#7677# $PROFILE is a valid file78NVM_DETECT_PROFILE="$(PROFILE="test_profile" SHELL= nvm_detect_profile)"79if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then80 die "nvm_detect_profile didn't pick \$PROFILE when it was a valid file"81fi8283# $PROFILE is not a valid file84rm "test_profile"85NVM_DETECT_PROFILE="$(PROFILE="test_profile" nvm_detect_profile)"86if [ "$NVM_DETECT_PROFILE" = "test_profile" ]; then87 die "nvm_detect_profile picked \$PROFILE when it was an invalid file"88fi8990#91# When profile detection fails via both $PROFILE and $SHELL, profile detection should select based on the existence of92# one of the following files is the following order: .profile, .bashrc, .bash_profile, .zprofile, .zshrc and93# return an empty value if everything fails94#9596# It should favor .profile if file exists97NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)"98if [ "$NVM_DETECT_PROFILE" != "$HOME/.profile" ]; then99 die "nvm_detect_profile should have selected .profile; got $NVM_DETECT_PROFILE"100fi101102# Otherwise, it should favor .bashrc if file exists103rm ".profile"104NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)"105if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then106 die "nvm_detect_profile should have selected .bashrc; got $NVM_DETECT_PROFILE"107fi108109# Otherwise, it should favor .bash_profile if file exists110rm ".bashrc"111NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)"112if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then113 die "nvm_detect_profile should have selected .bash_profile; got $NVM_DETECT_PROFILE"114fi115116# Otherwise, it should favor zdotdir/.zprofile if file exists117rm ".bash_profile"118NVM_DETECT_PROFILE="$(SHELL= nvm_detect_profile)"119if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zprofile" ]; then120 die "nvm_detect_profile should have selected zdotdir/.zprofile; got $NVM_DETECT_PROFILE"121fi122123# Otherwise, it should favor .zprofile if file exists124rm "zdotdir/.zprofile"125NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)"126if [ "$NVM_DETECT_PROFILE" != "$HOME/.zprofile" ]; then127 die "nvm_detect_profile should have selected .zprofile; got $NVM_DETECT_PROFILE"128fi129130# Otherwise, it should favor zdotdir/.zshrc if file exists131rm ".zprofile"132NVM_DETECT_PROFILE="$(SHELL= nvm_detect_profile)"133if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zshrc" ]; then134 die "nvm_detect_profile should have selected zdotdir/.zshrc; got $NVM_DETECT_PROFILE"135fi136137# Otherwise, it should favor .zshrc if file exists138rm "zdotdir/.zshrc"139NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)"140if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then141 die "nvm_detect_profile should have selected .zshrc; got $NVM_DETECT_PROFILE"142fi143144# It should be empty if none is found145rm ".zshrc"146NVM_DETECT_PROFILE="$(SHELL= nvm_detect_profile)"147if [ ! -z "$NVM_DETECT_PROFILE" ]; then148 die "nvm_detect_profile should have returned an empty value; got $NVM_DETECT_PROFILE"149fi150151cleanup