Skip to content
Permalink
Browse files

Eliminate $NO_SHCOMP env var

I introduced the `$NO_SHCOMP` env var long ago as a means of skipping
shcomp unit test variants when running the tests on my local systems. I
recently, in commit 0d76ee4, introduced a better mechanism that uses
`meson -Dbuild-shcomp-tests=false` at config time to supress those tests.
So simplify the script that runs unit tests.

This includes related cleanups involving the exit status if the test
runner fails for various reasons or explicitly skips a test for
compatibility reasons.
  • Loading branch information
krader1961 committed Dec 29, 2019
1 parent db20aab commit 5abcbd06612d28d2070e6e9d06e8ebe834a72a1d
Showing with 14 additions and 33 deletions.
  1. +2 −3 scripts/build-on-macos.sh
  2. +12 −30 src/cmd/ksh93/tests/util/run_test.sh
@@ -3,10 +3,9 @@ set -e

echo ==== Installing prereqs
brew list
# Note that python3 is already installed. As it python2. We need to unlink
# python2 and force python3 links in /usr/local to be created.
# Note that python3 is already installed. As is python2. We need to unlink
# python2 to avoid conflicts when meson is installed.
brew unlink python@2
brew link --overwrite python
brew install meson
brew install sphinx

@@ -17,8 +17,8 @@
#
# TODO: Eliminate as many of these exceptions as possible. Some of them, especially the Cygwin
# exceptions, will probably never be removed because they involve obscure features that will never
# be made to work on a particular platform. But others should be fixed so they tests do pass and
# the exclusion entry in the table below removed.
# be made to work on a particular platform. But others should be fixed so the tests do pass and the
# exclusion entry in the table below removed.
tests_to_skip=(
'cygwin b_jobs.exp'
'cygwin b_time.exp'
@@ -88,18 +88,7 @@ shcomp=false
if [[ $1 == shcomp ]]
then
# Run a ksh script test after compiling it.
#
# The presence of a NO_SHCOMP env var causes the shcomp variant to be skipped. This is useful,
# for example, when running tests under ASAN or Valgrind where we want to minimize the total
# test run time. Not to mention that the shcomp variants should be, and always are as I write
# this, redundant. That is, they always pass or fail for the same reasons as the non-shcomp
# variant.
if [[ -z "$NO_SHCOMP" || "$NO_SHCOMP" == 0 ]]
then
shcomp=true
else
shcomp=skip
fi
shcomp=true
shift 1
elif [[ $1 == api ]]
then
@@ -115,17 +104,16 @@ fi
if [[ $# -ne 1 ]]
then
log_error "Expected one arg (the test name) possibly preceded by 'shcomp' or 'api', got $#: $*"
exit 99
exit 1
fi

# If the test should be skipped do so.
readonly test_name=$1
[[ $shcomp == skip && $test_name == *.exp ]] && exit $MESON_SKIPPED_TEST
for test in "${tests_to_skip[@]}"
do
system=${test% *}
test_to_skip=${test#* }
[[ $shcomp == true && $system == shcomp && $test_to_skip == "$test_name" ]] && \
[[ $system == shcomp && $test_to_skip == "$test_name" ]] && \
exit $MESON_SKIPPED_TEST
[[ $system == "$MESON_SYSTEM" && $test_to_skip == "$test_name" ]] && \
exit $MESON_SKIPPED_TEST
@@ -197,9 +185,9 @@ fi
# our purposes that doesn't matter. It simply means the temp file name will contain the X's on a BSD
# system.
#
TEST_DIR=$(mktemp -dt "ksh.${test_name}.XXXXXX") || { log_error "mktemp -dt failed"; exit 99; }
TEST_DIR=$(mktemp -dt "ksh.${test_name}.XXXXXX") || { log_error "mktemp -dt failed"; exit 1; }
export TEST_DIR
cd "$TEST_DIR" || { print -u2 "<E> 'cd $TEST_DIR' failed with status $?"; exit 99; }
cd "$TEST_DIR" || { print -u2 "<E> 'cd $TEST_DIR' failed with status $?"; exit 1; }
log_info "TEST_DIR=$TEST_DIR"

#
@@ -294,7 +282,7 @@ function run_api {
then
# We only remove the temp test dir if the test is successful. Otherwise we leave it since
# it may contain useful clues about why the test failed.
cd /tmp || exit 99
cd /tmp || exit 1
rm -rf "$TEST_DIR"
fi

@@ -371,7 +359,7 @@ function run_interactive {
then
# We only remove the temp test dir if the test is successful. Otherwise we leave it since
# it may contain useful clues about why the test failed.
cd /tmp || exit 99
cd /tmp || exit 1
rm -rf "$TEST_DIR"
else
# The final `.*` is because there may be a [ctrl-M] present (@#%! windows line endings).
@@ -436,12 +424,6 @@ then
exit $MESON_SKIPPED_TEST
fi

if [[ $shcomp == true ]]
then
log_error "Interactive tests cannot be run via shcomp"
exit $MESON_SKIPPED_TEST
fi

# Interactive tests are flakey. Especially on CI test environments like Travis. So make several
# attempts before giving up and reporting failure.
set +o errexit
@@ -496,17 +478,17 @@ else
$SHELL -p "$TEST_DIR/$test_script" "$test_name" < /dev/null
exit_status=$?
else
# The SHCOMP env var must be exported by Meson. If it isn't something is seriously wrong.
# shellcheck disable=SC2153
# SHCOMP should be exported by the test framework.
[[ -n $SHCOMP ]] || exit 99
[[ -n "$SHCOMP" ]] || exit 1
"$SHCOMP" "$test_script" > "$test_script.shcomp" || exit
"$SHELL" -p "$TEST_DIR/$test_script.shcomp" "$test_name" < /dev/null
exit_status=$?
fi

if (( exit_status == 0 || exit_status == MESON_SKIPPED_TEST ))
then
cd /tmp || exit 99
cd /tmp || exit 1
rm -rf "$TEST_DIR"
fi
exit $exit_status

0 comments on commit 5abcbd0

Please sign in to comment.
You can’t perform that action at this time.