Skip to content

Commit

Permalink
Deal with PATH being unset when running unit tests
Browse files Browse the repository at this point in the history
This is nowhere close to optimal. It is a clumsy fix for when the
user's environment has $PATH unset when running unit tests. The primary
reason for this change is to replace the unnecessary invocation of
the external `basename` command with an equivalent ksh builtin when
running src/cmd/ksh93/data/config.ksh. A secondary reason is to work
around whatever is causing `$PATH` to be unset for the person who opened
issue #1453.

Long term we might want to augment the *config.ksh* script to also
explicitly deal with an empty/unset `$PATH`.

Fixes #1453
  • Loading branch information
krader1961 committed Dec 27, 2019
1 parent 0d76ee4 commit 2950ede
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/cmd/ksh93/data/config.ksh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ksh
#
# This script is sourced first when the shell starts. It's purpose is to perform basic setup of the
# shell state. For example, where to find autoloaded functions that ship with the shell and arrange
Expand All @@ -10,6 +11,7 @@
# already set isn't technically necessary since empty path components are guaranteed not to be
# equivalent to `.` (the CWD). But I prefer to be paranoid since doing so is cheap.
#
# shellcheck disable=SC2154 # this var is builtin to ksh
__fpath="${.sh.install_prefix}/share/ksh/functions"
if [[ -z ${FPATH:-''} ]]
then
Expand All @@ -18,15 +20,17 @@ else
FPATH="$__fpath:$FPATH"
fi

# Arrange for these function names to be autoloaded by declaring them to be undefined.
# Arrange for these functions to be autoloaded by declaring them to be undefined if the
# corresponding file is found in FPATH.
for f in "$__fpath"/*
do
typeset -fu $(basename $f)
typeset -fu "${f##*/}" # this is `basename` but faster
done

# Global vars for the `_cd`, `mcd`, `pushd`, `popd`, `dirs` functions.
integer _push_max=${CDSTACK:-32}
integer _push_top=${CDSTACK:-32}
integer _push_max="${CDSTACK:-32}"
integer _push_top="${CDSTACK:-32}"
# shellcheck disable=SC2034 # this var is used by autoloaded functions
typeset -a _push_stack

# Prefer the `cd` function to the `cd` builtin as the function is needed for functions like
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/ksh93/tests/util/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ function log_error {
}
alias log_error='log_error $LINENO'

# See https://github.com/att/ast/issues/1453. Make sure we have a minimal $PATH.
if [[ -z "$PATH" ]]
then
log_warning "PATH is empty/unset -- using \$(getconf PATH)"
PATH=/bin:/usr/bin:/usr/local/bin # getconf should be in /usr/bin but also check other dirs
PATH=$(getconf PATH)
log_warning "PATH is now $PATH"
fi

api_test=false
api_binary=false
shcomp=false
Expand Down

0 comments on commit 2950ede

Please sign in to comment.