Skip to content

Commit

Permalink
Merge pull request #227 from yut23/fix-interactive
Browse files Browse the repository at this point in the history
Fix `test/interactive` script
  • Loading branch information
andsens authored Oct 6, 2024
2 parents 9768486 + 64501b1 commit 92b2902
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 14 deletions.
63 changes: 58 additions & 5 deletions test/interactive
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [[ -z $_shell ]]; then
_shell=$SHELL
fi

# Replacement function for the run fn in bats
# Replacements for the run and load functions in bats
# Disable SC2034 for global variables
# shellcheck disable=SC2034
run() {
Expand All @@ -41,11 +41,64 @@ run() {
[ -z "$E" ] || set -E
[ -z "$T" ] || set -T
}

# extracted from bats-core/lib/bats-core/test_functions.bash
_bats_internal_load() {
# note: stripped out redundant error checking, as this is only used from our load

# shellcheck disable=SC1090
if ! source "$1"; then
printf "Error while sourcing library loader at '%s'\n" "$1" >&2
return 1
fi
return 0
}
load() {
local slug="${1:?}"
if [[ ${slug:0:1} != / ]]; then # relative paths are relative to BATS_TEST_DIRNAME
slug="$BATS_TEST_DIRNAME/$slug"
fi

if [[ -f "$slug.bash" ]]; then
_bats_internal_load "$slug.bash"
return $?
elif [[ -f "$slug" ]]; then
_bats_internal_load "$slug"
return $?
fi

# loading from PATH (retained for backwards compatibility)
if [[ ! -f "$1" ]] && type -P "$1" >/dev/null; then
# shellcheck disable=SC1090
source "$1"
return $?
fi

# No library load path can be found
printf "load: Could not find '%s'[.bash]\n" "$slug" >&2
return 1
}

# these are used in several places (most notably, load and temp_make)
export BATS_TMPDIR=${TMPDIR:-/tmp}
export BATS_TEST_DIRNAME=$SCRIPTDIR/suites
export BATS_TEST_FILENAME=$SCRIPTDIR/interactive
export BATS_TEST_NAME=interactive
export BATS_TEST_NUMBER=1

# shellcheck source=helper.sh
source "$SCRIPTDIR/helper.sh"
export_env_vars
setup_env
ln_homeshick
# a function named "setup" needs to be in the call stack for temp_make to work
setup() {
create_test_dir
setup_file

export _TMPDIR
export REPO_FIXTURES
export HOME
export NOTHOME
}
setup

setup_script="$SCRIPTDIR/setup.sh"
if [[ -f $setup_script ]]; then
Expand All @@ -56,4 +109,4 @@ fi

cd "$HOME"
/usr/bin/env "$_shell"
rm_structure
delete_test_dir
18 changes: 9 additions & 9 deletions test/setup-default.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env bash
# shellcheck disable=SC2016
printf '\nsource "$HOME/.homesick/repos/homeshick/homeshick.sh"' >> "$HOME/.bashrc"
cat > "$HOME/.bashrc" <<EOF
source "$HOME/.homesick/repos/homeshick/homeshick.sh"
source "\$HOME/.homesick/repos/homeshick/completions/homeshick-completion.bash"
printf '\nsource "$HOMESHICK_DIR/homeshick.sh"' >> "$HOME/.bashrc"
cat > "$HOME/.bashrc" <<'EOF'
source "$HOMESHICK_DIR/homeshick.sh"
source "$HOMESHICK_DIR/completions/homeshick-completion.bash"
EOF
cat > "$HOME/.zshrc" <<EOF
source "\$HOME/.homesick/repos/homeshick/homeshick.sh"
fpath=(\$HOME/.homesick/repos/homeshick/completions \$fpath)
cat > "$HOME/.zshrc" <<'EOF'
source "$HOMESHICK_DIR/homeshick.sh"
fpath=($HOMESHICK_DIR/completions $fpath)
autoload -U compinit
compinit
EOF
printf '\nalias homeshick source "$HOME/.homesick/repos/homeshick/homeshick.csh"' >> "$HOME/.cshrc"
printf '\nalias homeshick source "$HOMESHICK_DIR/homeshick.csh"' >> "$HOME/.cshrc"
mkdir -p "$HOME/.config/fish"
printf '\nsource "$HOME/.homesick/repos/homeshick/homeshick.fish"' >> "$HOME/.config/fish/config.fish"
printf '\nsource "$HOMESHICK_DIR/homeshick.fish"' >> "$HOME/.config/fish/config.fish"

0 comments on commit 92b2902

Please sign in to comment.