2013-06-19 02:46:31 -04:00
|
|
|
#!/bin/sh
|
2012-10-04 07:24:03 -04:00
|
|
|
|
2016-02-28 23:11:37 -05:00
|
|
|
# ----------------------------------------------------------------------
|
2016-02-28 23:09:46 -05:00
|
|
|
# Copyright (c) 2013, 2014, 2015, 2016 Thomas Levine
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-02-28 23:11:37 -05:00
|
|
|
# ----------------------------------------------------------------------
|
2016-02-08 11:09:00 -05:00
|
|
|
|
2016-02-28 23:09:46 -05:00
|
|
|
|
2016-02-28 23:11:37 -05:00
|
|
|
# ----------------------------------------------------------------------
|
2016-02-28 23:09:46 -05:00
|
|
|
# Copyright (c) 2014, Michael Klement
|
|
|
|
# Copyright (c) 2012, ScraperWiki Limited
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# Redistributions of source code must retain the above copyright notice, this
|
|
|
|
# list of conditions and the following disclaimer.
|
|
|
|
#
|
|
|
|
# Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions and the following disclaimer in the documentation
|
|
|
|
# and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
2016-02-28 23:11:37 -05:00
|
|
|
# ----------------------------------------------------------------------
|
2016-02-08 11:02:00 -05:00
|
|
|
|
2016-02-27 20:18:55 -05:00
|
|
|
set -e
|
2016-02-08 11:09:00 -05:00
|
|
|
|
2016-03-06 09:19:04 -05:00
|
|
|
# Kill subprocesses on interrupt.
|
2016-03-06 09:23:04 -05:00
|
|
|
trap "kill -$$; exit" HUP INT TERM
|
2016-03-06 09:19:04 -05:00
|
|
|
|
2016-02-28 21:32:58 -05:00
|
|
|
DEFAULT_SHELLS='sh bash dash mksh zsh'
|
2016-03-02 15:19:33 -05:00
|
|
|
if [ -n "${ZSH_VERSION}" ]; then
|
2016-02-28 21:32:58 -05:00
|
|
|
# avoid "no matches found: *" error when directories are empty
|
|
|
|
setopt NULL_GLOB
|
|
|
|
emulate sh
|
|
|
|
fi
|
|
|
|
|
2016-03-06 09:19:04 -05:00
|
|
|
validate_test_arg() {
|
|
|
|
# Must be a file or directory
|
|
|
|
if [ ! -e "${1}" ]; then
|
|
|
|
echo "No such file or directory: '${1}'" >&2
|
|
|
|
echo "${USAGE}" >&2
|
|
|
|
urchin_exit 11
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Molly guard
|
|
|
|
root="$(urchin_root "${1}")"
|
|
|
|
if ! {
|
|
|
|
basename "$(fullpath "${root}")" |
|
2016-03-29 12:57:21 -04:00
|
|
|
grep -qi 'test' || "${force}"
|
2016-03-06 09:19:04 -05:00
|
|
|
}; then
|
|
|
|
echo 'The root directory of the tests that you are running urchin on
|
|
|
|
does not contain the word "test", so I am not running,
|
|
|
|
in case that was an accident. Use the -f flag if you really
|
|
|
|
want to run urchin on that directory.' >&2
|
|
|
|
urchin_exit 1
|
|
|
|
fi
|
|
|
|
}
|
2016-02-28 09:01:17 -05:00
|
|
|
|
2016-02-28 04:08:20 -05:00
|
|
|
# All temporary files go here
|
2016-02-28 14:18:54 -05:00
|
|
|
urchin_tmp=$(mktemp -d)
|
2016-03-02 15:19:33 -05:00
|
|
|
> "${urchin_tmp}/log"
|
2016-02-28 04:08:20 -05:00
|
|
|
urchin_exit() {
|
2016-03-02 15:19:33 -05:00
|
|
|
rm -Rf "${urchin_tmp}"
|
2016-02-28 04:08:20 -05:00
|
|
|
exit "$@"
|
|
|
|
}
|
|
|
|
|
2016-02-28 08:12:55 -05:00
|
|
|
stdout_file() {
|
2016-03-02 15:19:33 -05:00
|
|
|
the_test="${1}"
|
|
|
|
the_shell="${2}"
|
2016-02-28 15:31:17 -05:00
|
|
|
|
2016-03-02 15:19:33 -05:00
|
|
|
x="${urchin_tmp}/stdout$(fullpath "$the_test")"
|
|
|
|
mkdir -p "${x}"
|
|
|
|
echo "${x}/$(echo "${the_shell}" | md5sum | cut -d\ -f1)"
|
2016-02-28 08:12:55 -05:00
|
|
|
}
|
|
|
|
|
2016-02-28 04:12:57 -05:00
|
|
|
# Expand relative paths
|
2016-02-28 15:58:52 -05:00
|
|
|
fullpath() {
|
2016-03-02 15:19:33 -05:00
|
|
|
readlink -f -- "${1}"
|
2016-02-28 15:58:52 -05:00
|
|
|
}
|
2016-02-28 04:12:57 -05:00
|
|
|
|
2016-02-28 06:22:51 -05:00
|
|
|
remove_trailing_slash() {
|
|
|
|
echo "$1" | sed s/\\/$//
|
|
|
|
}
|
|
|
|
|
2016-02-28 06:18:39 -05:00
|
|
|
urchin_root() {
|
2016-02-28 06:22:51 -05:00
|
|
|
# Call recursively but remember the original argument.
|
2016-03-02 15:19:33 -05:00
|
|
|
current="$(remove_trailing_slash "${1}")"
|
|
|
|
if test -n "${2}"; then
|
|
|
|
orig="${2}"
|
2016-02-28 06:22:51 -05:00
|
|
|
else
|
2016-03-02 15:19:33 -05:00
|
|
|
orig="${1}"
|
2016-02-28 06:22:51 -05:00
|
|
|
fi
|
2016-02-28 06:18:39 -05:00
|
|
|
|
2016-03-02 15:19:33 -05:00
|
|
|
abscurrent="$(fullpath "${1}")"
|
|
|
|
if test "${abscurrent}" = / ||
|
2016-03-29 12:57:21 -04:00
|
|
|
basename "${abscurrent}" | grep -q '^\.' ; then
|
2016-02-28 17:49:57 -05:00
|
|
|
# Stop traversing upwards at / and at hidden directories.
|
2016-03-02 15:19:33 -05:00
|
|
|
if test -d "${orig}"; then
|
|
|
|
echo "${orig}"
|
2016-02-28 06:22:51 -05:00
|
|
|
else
|
2016-03-02 15:19:33 -05:00
|
|
|
dirname -- "${orig}"
|
2016-02-28 06:22:51 -05:00
|
|
|
fi
|
2016-03-02 15:19:33 -05:00
|
|
|
elif ! test -e "${current}"; then
|
|
|
|
echo "${current}: No such file or directory">&2
|
2016-02-28 06:22:51 -05:00
|
|
|
return 1
|
2016-03-02 15:19:33 -05:00
|
|
|
elif test -f "${current}"; then
|
|
|
|
urchin_root "$(dirname -- "${current}")" "${orig}"
|
2016-03-06 09:38:56 -05:00
|
|
|
elif test -f "${current}"/.urchin_root; then
|
2016-03-02 15:19:33 -05:00
|
|
|
remove_trailing_slash "${current}"
|
2016-02-28 06:22:51 -05:00
|
|
|
else
|
2016-03-02 15:19:33 -05:00
|
|
|
urchin_root "${current}"/.. "${orig}"
|
2016-02-28 06:22:51 -05:00
|
|
|
fi
|
2016-02-28 06:18:39 -05:00
|
|
|
}
|
|
|
|
|
2016-01-29 12:17:31 -05:00
|
|
|
# Urchin version number
|
2016-03-31 18:25:49 -04:00
|
|
|
VERSION=0.1.0-rc2
|
2012-10-11 14:50:03 -04:00
|
|
|
|
2012-10-10 20:43:13 -04:00
|
|
|
indent() {
|
2016-03-02 15:19:33 -05:00
|
|
|
level="${1}"
|
|
|
|
if test "${level}" -gt 0; then
|
2016-02-08 10:14:22 -05:00
|
|
|
printf "%$((2 * ${level}))s"
|
|
|
|
fi
|
2012-10-10 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
2012-10-04 07:29:34 -04:00
|
|
|
recurse() {
|
2016-03-02 15:19:33 -05:00
|
|
|
requested_path="${1}"
|
|
|
|
potential_test="$(fullpath "${2}")"
|
|
|
|
cycle_shell="${3}"
|
|
|
|
TEST_SHELL="${4}"
|
2016-02-28 05:27:49 -05:00
|
|
|
|
2016-04-01 15:52:34 -04:00
|
|
|
if $print_debug; then
|
|
|
|
echo Entered directory "${PWD}"
|
|
|
|
fi
|
|
|
|
|
2016-02-28 05:00:53 -05:00
|
|
|
for ignore in setup_dir teardown_dir setup teardown; do
|
2016-03-02 15:19:33 -05:00
|
|
|
if test "$(basename "${potential_test}")" = "${ignore}"; then
|
2016-02-28 05:00:53 -05:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
2012-10-10 14:40:49 -04:00
|
|
|
|
2016-03-29 12:57:21 -04:00
|
|
|
if echo "${requested_path}" | grep -q "^${potential_test}" ||
|
|
|
|
echo "${potential_test}" | grep -q "^${requested_path}" ; then
|
2016-03-06 05:22:15 -05:00
|
|
|
if test "$(dirname "${potential_test}")" = \
|
|
|
|
"$(dirname "${requested_path}")" &&
|
|
|
|
test "${potential_test}" != "${requested_path}"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
else
|
2016-02-28 07:14:16 -05:00
|
|
|
return 0
|
2016-03-06 05:22:15 -05:00
|
|
|
fi
|
2016-02-28 07:02:57 -05:00
|
|
|
|
2016-03-02 15:19:33 -05:00
|
|
|
validate_strings "${potential_test}" 'Test file names'
|
2016-02-28 07:02:57 -05:00
|
|
|
|
2016-03-02 17:02:21 -05:00
|
|
|
if [ -x "${potential_test}" ]; then
|
|
|
|
if [ -d "${potential_test}" ]; then
|
2016-01-27 05:14:21 -05:00
|
|
|
(
|
2016-03-02 16:46:11 -05:00
|
|
|
cd -- "${potential_test}"
|
2016-03-29 12:57:21 -04:00
|
|
|
if test -f .urchin_dir && grep -q series .urchin_dir ; then
|
2016-03-06 09:44:39 -05:00
|
|
|
run_in_series_dir=true
|
|
|
|
else
|
|
|
|
run_in_series_dir=false
|
|
|
|
fi
|
|
|
|
|
2016-04-01 15:52:34 -04:00
|
|
|
if test -f setup_dir; then
|
2016-04-03 20:42:08 -04:00
|
|
|
if $print_debug; then
|
|
|
|
echo Sourcing "${PWD}/setup_dir"
|
|
|
|
. ./setup_dir
|
|
|
|
fi
|
2016-04-01 15:52:34 -04:00
|
|
|
fi
|
2014-11-05 12:38:22 -05:00
|
|
|
|
2016-02-27 20:18:55 -05:00
|
|
|
for test in *; do
|
2016-03-02 15:19:33 -05:00
|
|
|
if test "${test}" = '*' && ! test -e "${test}"; then
|
2016-02-28 07:35:27 -05:00
|
|
|
# The directory is empty.
|
|
|
|
break
|
|
|
|
fi
|
2012-10-10 20:43:13 -04:00
|
|
|
|
2016-03-06 09:54:42 -05:00
|
|
|
recurse "${requested_path}" "${test}" "${cycle_shell}" \
|
|
|
|
"${TEST_SHELL}" &
|
2016-02-28 11:05:03 -05:00
|
|
|
|
2016-03-06 09:44:39 -05:00
|
|
|
if "${run_in_series}" || "${run_in_series_dir}"; then
|
2016-03-02 15:19:33 -05:00
|
|
|
if wait "${!}"; then exit_code=0; else exit_code="${?}"; fi
|
|
|
|
if "${exit_on_not_ok}" && test "${exit_code}" -ne 0; then
|
2016-04-01 15:52:34 -04:00
|
|
|
if test -f teardown_dir; then
|
|
|
|
if $print_debug; then
|
|
|
|
echo Sourcing "${PWD}/teardown_dir"
|
|
|
|
fi
|
|
|
|
. ./teardown_dir
|
|
|
|
fi
|
2016-02-28 20:03:17 -05:00
|
|
|
return 1
|
2016-02-28 11:05:03 -05:00
|
|
|
fi
|
2016-01-25 09:35:54 -05:00
|
|
|
fi
|
2012-10-08 08:50:48 -04:00
|
|
|
done
|
2016-02-28 11:12:13 -05:00
|
|
|
wait
|
2016-04-01 15:52:34 -04:00
|
|
|
if test -f teardown_dir; then
|
|
|
|
if $print_debug; then
|
|
|
|
echo Sourcing "${PWD}/teardown_dir"
|
|
|
|
fi
|
|
|
|
. ./teardown_dir
|
|
|
|
fi
|
2016-02-28 05:00:53 -05:00
|
|
|
)
|
2016-03-02 17:02:21 -05:00
|
|
|
elif [ -f "${potential_test}" ]; then
|
2016-03-02 15:19:33 -05:00
|
|
|
cd -- "$(dirname -- "${potential_test}")"
|
2016-02-28 09:01:17 -05:00
|
|
|
|
2016-04-01 15:52:34 -04:00
|
|
|
if $print_debug; then
|
|
|
|
echo Running "${potential_test}"
|
|
|
|
fi
|
|
|
|
|
2016-02-28 09:01:17 -05:00
|
|
|
# Determine the environment variable to define for test scripts
|
|
|
|
# that reflects the specified or implied shell to use for shell-code tests.
|
2016-02-28 11:32:06 -05:00
|
|
|
while read the_test_shell; do
|
|
|
|
(
|
2016-04-01 15:52:34 -04:00
|
|
|
if test -f setup; then
|
|
|
|
if $print_debug; then
|
|
|
|
echo Sourcing "${PWD}/setup"
|
|
|
|
fi
|
|
|
|
. ./setup
|
|
|
|
fi
|
2016-02-28 11:32:06 -05:00
|
|
|
|
|
|
|
# Run the test
|
|
|
|
start=$(date +%s)
|
|
|
|
set +e
|
2016-02-28 11:53:49 -05:00
|
|
|
{
|
2016-03-02 15:19:33 -05:00
|
|
|
if "${cycle_shell}"; then
|
|
|
|
if has_shebang_line "${potential_test}"; then
|
|
|
|
TEST_SHELL="${the_test_shell}" $TIMEOUT "${potential_test}"
|
2016-02-29 07:29:47 -05:00
|
|
|
else
|
2016-03-02 15:19:33 -05:00
|
|
|
TEST_SHELL="${the_test_shell}" $TIMEOUT \
|
|
|
|
"${the_test_shell}" "${potential_test}"
|
2016-02-29 07:29:47 -05:00
|
|
|
fi
|
2016-02-28 11:53:49 -05:00
|
|
|
else
|
2016-02-28 21:13:40 -05:00
|
|
|
# Shell cycling is disabled with -n; use the present value of
|
|
|
|
# TEST_SHELL or default to /bin/sh
|
2016-03-02 15:19:33 -05:00
|
|
|
if [ -n "${TEST_SHELL}" ]; then
|
|
|
|
$TIMEOUT "${potential_test}"
|
2016-02-28 21:13:40 -05:00
|
|
|
else
|
2016-03-02 15:19:33 -05:00
|
|
|
TEST_SHELL=/bin/sh $TIMEOUT "${potential_test}"
|
2016-02-28 21:13:40 -05:00
|
|
|
fi
|
2016-02-28 11:53:49 -05:00
|
|
|
fi
|
2016-03-02 15:19:33 -05:00
|
|
|
} > "$(stdout_file "${potential_test}" "${the_test_shell}")" 2>&1
|
|
|
|
exit_code="${?}"
|
2016-02-28 11:32:06 -05:00
|
|
|
set -e
|
|
|
|
finish=$(date +%s)
|
|
|
|
|
2016-04-01 15:52:34 -04:00
|
|
|
if test -f teardown; then
|
2016-04-03 20:42:08 -04:00
|
|
|
if $print_debug; then
|
|
|
|
echo Sourcing "${PWD}/teardown"
|
|
|
|
. ./teardown
|
|
|
|
fi
|
2016-04-01 15:52:34 -04:00
|
|
|
fi
|
2016-02-28 11:32:06 -05:00
|
|
|
|
2016-03-02 15:19:33 -05:00
|
|
|
if [ "${exit_code}" -eq 0 ]; then
|
2016-02-28 11:32:06 -05:00
|
|
|
result=ok
|
2016-03-02 15:19:33 -05:00
|
|
|
elif [ "${exit_code}" -eq 3 ]; then
|
2016-02-28 11:32:06 -05:00
|
|
|
result=skip
|
|
|
|
else
|
|
|
|
result=not_ok
|
|
|
|
fi
|
|
|
|
|
2016-03-02 15:29:33 -05:00
|
|
|
elapsed=$(($finish - $start))
|
2016-02-28 11:32:06 -05:00
|
|
|
printf "${potential_test}\t${the_test_shell}\t${result}\t${elapsed}\n" \
|
2016-03-02 15:19:33 -05:00
|
|
|
>> "${urchin_tmp}"/log
|
|
|
|
exit "${exit_code}"
|
2016-02-28 11:32:06 -05:00
|
|
|
) &
|
|
|
|
|
2016-03-02 15:19:33 -05:00
|
|
|
if "${run_in_series}"; then
|
|
|
|
if wait "${!}"; then exit_code=0; else exit_code="${?}"; fi
|
|
|
|
if "${exit_on_not_ok}" && test "${exit_code}" -ne 0; then
|
2016-04-01 15:52:34 -04:00
|
|
|
if test -f teardown_dir; then
|
|
|
|
if $print_debug; then
|
|
|
|
echo Sourcing "${PWD}/teardown_dir"
|
|
|
|
fi
|
|
|
|
. ./teardown_dir
|
|
|
|
fi
|
2016-02-28 11:32:06 -05:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
2016-03-02 15:19:33 -05:00
|
|
|
done < "${shell_list}"
|
2016-02-28 11:32:06 -05:00
|
|
|
wait
|
2012-10-04 07:29:34 -04:00
|
|
|
else
|
2016-03-02 17:02:21 -05:00
|
|
|
echo "${potential_test}: Neither file nor directory!?" > /dev/stderr
|
2016-01-27 05:14:21 -05:00
|
|
|
fi
|
2016-03-02 17:02:21 -05:00
|
|
|
else
|
|
|
|
# Shell is ''
|
|
|
|
printf "${potential_test}\t\tskip\t0\n" >> "${urchin_tmp}"/log
|
2016-02-28 04:08:20 -05:00
|
|
|
fi
|
|
|
|
}
|
2016-01-27 05:14:21 -05:00
|
|
|
|
2016-02-28 04:08:20 -05:00
|
|
|
report_outcome() {
|
2016-03-02 15:19:33 -05:00
|
|
|
root="${1}"
|
|
|
|
tap_format="${2}"
|
|
|
|
log_file="${3}"
|
|
|
|
start="${4}"
|
|
|
|
finish="${5}"
|
2016-02-28 07:41:39 -05:00
|
|
|
|
2016-03-02 15:19:33 -05:00
|
|
|
escaped_root="$(fullpath "${root}" | sed 's/\//\\\//g')"
|
2016-03-02 15:29:33 -05:00
|
|
|
elapsed=$(($finish - $start))
|
2016-02-28 05:07:55 -05:00
|
|
|
|
2016-03-02 15:19:33 -05:00
|
|
|
if "${tap_format}"; then
|
2016-02-28 07:53:26 -05:00
|
|
|
printf \#\
|
|
|
|
fi
|
2016-03-06 05:45:40 -05:00
|
|
|
if "${print_margins}" || "${tap_format}"; then
|
|
|
|
echo Running tests at $(date +%Y-%m-%dT%H:%M:%S)
|
|
|
|
fi
|
2016-02-28 04:25:21 -05:00
|
|
|
|
2016-02-28 05:57:27 -05:00
|
|
|
for number in n oks skips not_oks; do
|
2016-03-02 15:19:33 -05:00
|
|
|
eval "${number}=0"
|
2016-02-28 05:57:27 -05:00
|
|
|
done
|
2016-02-28 06:14:23 -05:00
|
|
|
|
|
|
|
# Use a temporary file rather than a pipe because a pipe starts a sub-shell
|
|
|
|
# and thus makes the above variables local.
|
2016-03-02 15:29:33 -05:00
|
|
|
sorted_log_file=$(mktemp)
|
2016-03-31 14:46:26 -04:00
|
|
|
cat "${log_file}" | LC_ALL=POSIX sort > "${sorted_log_file}"
|
2016-02-28 19:41:03 -05:00
|
|
|
|
2016-02-28 06:14:23 -05:00
|
|
|
while read line; do
|
2016-03-02 15:19:33 -05:00
|
|
|
abspath=$(echo "${line}" | cut -f1)
|
2016-03-02 15:29:33 -05:00
|
|
|
path=$(echo "${abspath}" | sed "s/$escaped_root\/\?//")
|
2016-03-02 15:19:33 -05:00
|
|
|
the_shell=$(echo "${line}" | cut -f2)
|
|
|
|
result=$(echo "${line}" | cut -f3)
|
2016-02-28 09:32:33 -05:00
|
|
|
file_elapsed=$(echo "$line" | cut -f4)
|
2016-02-28 06:06:54 -05:00
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
prevdir="${currentdir}"
|
|
|
|
currentdir="$(dirname -- "${path}")"
|
2016-02-28 07:53:26 -05:00
|
|
|
|
2016-02-28 06:06:54 -05:00
|
|
|
# Number of files that have run, including this one
|
2016-02-28 05:27:49 -05:00
|
|
|
n=$(($n + 1))
|
2016-02-28 06:06:54 -05:00
|
|
|
|
|
|
|
# Number of files that have been ok, not ok, and skipped
|
|
|
|
eval "old_count=${result}s"
|
|
|
|
eval "${result}s=$(($old_count+1))"
|
2016-02-28 04:12:57 -05:00
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
if "${tap_format}"; then
|
|
|
|
if [ "${result}" = not_ok ]; then
|
2016-02-28 05:27:49 -05:00
|
|
|
not='not '
|
|
|
|
else
|
|
|
|
not=''
|
|
|
|
fi
|
2016-03-02 15:39:31 -05:00
|
|
|
if [ "${result}" = skip ]; then
|
2016-02-28 05:49:40 -05:00
|
|
|
skip='# SKIP'
|
2016-02-28 05:27:49 -05:00
|
|
|
else
|
|
|
|
skip=''
|
|
|
|
fi
|
2016-02-28 10:50:53 -05:00
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
if test -z "${the_shell}"; then
|
2016-02-28 10:50:53 -05:00
|
|
|
the_shell='File is not executable.'
|
|
|
|
fi
|
2016-03-02 15:39:31 -05:00
|
|
|
echo "${not}ok $n - ${path} (${the_shell}) ${skip}"
|
2016-03-06 04:37:08 -05:00
|
|
|
if { test "${result}" = not_ok && "${print_not_ok_stdout}"; } ||
|
|
|
|
{ test "${result}" = ok && "${print_ok_stdout}"; }; then
|
2016-02-28 05:27:49 -05:00
|
|
|
echo '# ------------ Begin output ------------'
|
2016-03-02 15:39:31 -05:00
|
|
|
sed 's/^/# /' "$(stdout_file "${abspath}" "${the_shell}")"
|
2016-02-28 05:27:49 -05:00
|
|
|
echo '# ------------ End output ------------'
|
|
|
|
fi
|
2016-03-02 15:39:31 -05:00
|
|
|
echo "# Previous test took ${file_elapsed} seconds."
|
2016-02-28 07:45:38 -05:00
|
|
|
else
|
2016-03-06 05:39:40 -05:00
|
|
|
header() {
|
|
|
|
if test "${prevdir}" != "${currentdir}"; then
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
if test "${prevpath}" != "${path}"; then
|
|
|
|
printf "$(dirname -- "${path}")/\n> $(basename -- "${path}")\n"
|
|
|
|
fi
|
|
|
|
}
|
2016-03-31 15:54:27 -04:00
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
case "${result}" in
|
2016-02-28 07:45:38 -05:00
|
|
|
ok)
|
2016-03-06 05:39:40 -05:00
|
|
|
if "${print_ok}"; then
|
|
|
|
header
|
|
|
|
if "${print_in_color}"; then
|
2016-03-31 15:54:27 -04:00
|
|
|
printf "\033[32m${success_mark} \033[0m"
|
2016-03-06 05:39:40 -05:00
|
|
|
else
|
2016-03-31 15:54:27 -04:00
|
|
|
printf "${success_mark} "
|
2016-03-06 05:39:40 -05:00
|
|
|
fi
|
|
|
|
echo "${the_shell} ("${file_elapsed}" $(plural second $file_elapsed))"
|
2016-03-06 04:44:10 -05:00
|
|
|
fi
|
2016-02-28 07:45:38 -05:00
|
|
|
;;
|
|
|
|
not_ok)
|
2016-03-06 05:39:40 -05:00
|
|
|
if "${print_not_ok}"; then
|
|
|
|
header
|
|
|
|
if "${print_in_color}"; then
|
2016-03-31 15:54:27 -04:00
|
|
|
printf "\033[31m${fail_mark} \033[0m"
|
2016-03-06 05:39:40 -05:00
|
|
|
else
|
2016-03-31 15:54:27 -04:00
|
|
|
printf "${fail_mark} "
|
2016-03-06 05:39:40 -05:00
|
|
|
fi
|
|
|
|
echo "${the_shell} ("${file_elapsed}" $(plural second $file_elapsed))"
|
2016-03-06 04:44:10 -05:00
|
|
|
fi
|
2016-02-28 07:45:38 -05:00
|
|
|
;;
|
|
|
|
skip)
|
2016-03-06 05:39:40 -05:00
|
|
|
if "${print_ok}"; then
|
|
|
|
header
|
|
|
|
if test -z "${the_shell}"; then
|
|
|
|
echo ' (File is not executable.)'
|
|
|
|
else
|
|
|
|
echo " ${the_shell} ("${file_elapsed}" $(plural second $file_elapsed))"
|
|
|
|
fi
|
2016-02-28 10:50:53 -05:00
|
|
|
fi
|
2016-02-28 07:45:38 -05:00
|
|
|
;;
|
|
|
|
esac
|
2016-03-06 04:37:08 -05:00
|
|
|
if { test "${result}" = not_ok && "${print_not_ok_stdout}"; } ||
|
|
|
|
{ test "${result}" = ok && "${print_ok_stdout}"; }; then
|
2016-03-31 15:43:04 -04:00
|
|
|
sed 's/^/ | /' "$(stdout_file "${abspath}" "${the_shell}")"
|
2016-02-28 17:41:13 -05:00
|
|
|
fi
|
2016-02-28 05:27:49 -05:00
|
|
|
fi
|
2016-02-28 04:17:16 -05:00
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
prevpath="${path}"
|
|
|
|
done < "${sorted_log_file}"
|
|
|
|
rm "${sorted_log_file}"
|
2016-02-28 04:17:16 -05:00
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
if "${tap_format}"; then
|
|
|
|
echo "# Full test suite took ${elapsed} $(plural second ${elapsed})."
|
|
|
|
echo 1.."${n}"
|
2016-03-06 05:45:40 -05:00
|
|
|
elif "${print_margins}"; then
|
2016-02-28 07:53:26 -05:00
|
|
|
echo
|
2016-03-02 15:39:31 -05:00
|
|
|
echo "Done, took ${elapsed} $(plural second ${elapsed})."
|
|
|
|
printf '%s\n' "${oks} $(plural test "${oks}") passed."
|
|
|
|
printf '%s\n' "${skips} $(plural test "${skips}") skipped."
|
2016-02-28 04:17:16 -05:00
|
|
|
|
2016-02-28 05:57:27 -05:00
|
|
|
# If any tests are not ok, print the message in red.
|
2016-03-06 04:44:10 -05:00
|
|
|
if [ "${not_oks}" -gt 0 ] && "${print_in_color}"; then
|
2016-02-28 05:57:27 -05:00
|
|
|
printf '\033[31m'
|
|
|
|
fi
|
2016-03-02 15:39:31 -05:00
|
|
|
printf '%s\n' "${not_oks} $(plural test "${not_oks}") failed."
|
2016-03-06 04:44:10 -05:00
|
|
|
if "${print_in_color}"; then
|
|
|
|
printf '\033[m\n'
|
|
|
|
fi
|
2016-02-28 04:17:16 -05:00
|
|
|
fi
|
2016-03-02 15:39:31 -05:00
|
|
|
test "${not_oks}" -eq '0'
|
2012-10-04 07:29:34 -04:00
|
|
|
}
|
2012-10-04 12:43:49 -04:00
|
|
|
|
2016-02-29 00:10:53 -05:00
|
|
|
has_shebang_line() {
|
2016-03-31 15:26:11 -04:00
|
|
|
head -n 1 "${1}" | grep -v '^#!/bin/sh$' | grep -q '^#!'
|
2014-10-17 17:16:12 -04:00
|
|
|
}
|
|
|
|
|
2016-03-10 06:12:17 -05:00
|
|
|
USAGE="usage: $0 [options]... [test file or directory]..."
|
2012-10-11 01:46:02 -04:00
|
|
|
|
2012-10-11 02:21:05 -04:00
|
|
|
urchin_help() {
|
2014-11-06 22:21:05 -05:00
|
|
|
cat <<EOF
|
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
${USAGE}
|
2014-11-06 22:21:05 -05:00
|
|
|
|
2016-02-28 09:01:17 -05:00
|
|
|
By default, Urchin checks for the following shells and runs every
|
|
|
|
particular test file once per shell.
|
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
$(echo "${DEFAULT_SHELLS}" | sed 's/ /\n /g')
|
2016-02-28 09:01:17 -05:00
|
|
|
|
|
|
|
On each run,
|
|
|
|
|
|
|
|
1. The TEST_SHELL environment variable is set to the particular shell.
|
2016-03-29 12:54:40 -04:00
|
|
|
2. If the test file lacks a shebang line or has a shebang line of
|
|
|
|
"#!/bin/sh", the test script is also executed in that shell.
|
2016-02-28 09:01:17 -05:00
|
|
|
|
2016-02-28 09:12:21 -05:00
|
|
|
The following flags affect how this multiple-shell testing is handled.
|
|
|
|
|
|
|
|
-s, --shell <shell> Tell Urchin to use a different list of shells.
|
|
|
|
(You can pass this flag multiple times.)
|
|
|
|
|
2016-02-29 08:29:51 -05:00
|
|
|
-n, --disable-cycling Disable the cycling of shells; Urchin will
|
|
|
|
execute test files ordinarily, implicitly using
|
|
|
|
sh for files that lack shebang lines. It will
|
|
|
|
set the TEST_SHELL variable to "/bin/sh" if and
|
|
|
|
only if TEST_SHELL is empty or undefined.
|
2016-02-28 09:12:21 -05:00
|
|
|
|
2016-02-28 10:15:09 -05:00
|
|
|
The following flags affect how Urchin processes tests.
|
2016-02-28 09:12:21 -05:00
|
|
|
|
2016-02-28 11:00:07 -05:00
|
|
|
-b, --run-in-series Run tests in series. The default is to run tests
|
|
|
|
in parallel where possible.
|
2016-02-28 09:12:21 -05:00
|
|
|
-e, --exit-on-fail Stop running if any single test fails.
|
2016-04-01 15:43:02 -04:00
|
|
|
This can be useful if you are running something
|
|
|
|
other than test files with Urchin.
|
2016-02-28 10:15:09 -05:00
|
|
|
-T, --timeout <seconds> Kill a test if it runs for longer than the
|
|
|
|
specified duration. The default is no timeout.
|
2016-02-28 09:12:21 -05:00
|
|
|
-f, --force Force running even if the test directory's name
|
|
|
|
does not contain the word "test".
|
|
|
|
|
2016-03-06 05:39:40 -05:00
|
|
|
These options affect how results are formatted. Options -q, and -v
|
|
|
|
have no effect when combined with --tap. -vv, -vvv, and -vvvv do have
|
|
|
|
effect when combined with --tap.
|
2016-02-28 09:12:21 -05:00
|
|
|
|
2016-03-31 15:56:12 -04:00
|
|
|
-p, --pretty Print results in color and with fancy symbols.
|
2016-02-28 09:12:21 -05:00
|
|
|
-t, --tap Format output in Test Anything Protocol (TAP)
|
2016-03-06 05:39:40 -05:00
|
|
|
|
2016-04-01 15:43:02 -04:00
|
|
|
And these options affect how much is printed.
|
|
|
|
|
2016-03-06 05:46:24 -05:00
|
|
|
-q, --quiet Print nothing to stdout;
|
|
|
|
the only output is the exit code.
|
|
|
|
(default verbosity) Print names of failed tests and counts
|
|
|
|
of passed, failed, and skipped tests.
|
2016-03-06 08:54:10 -05:00
|
|
|
-v Print stdout from failing tests.
|
|
|
|
-vv Print names of passed tests.
|
|
|
|
-vvv, --verbose Print stdout from all tests.
|
2016-04-01 15:52:34 -04:00
|
|
|
-vvvv, --debug Print debugging messages.
|
2016-02-28 09:12:21 -05:00
|
|
|
|
|
|
|
The remaining flags provide information about urchin.
|
|
|
|
|
|
|
|
-h, --help Display this help.
|
|
|
|
--version Display the version number.
|
2014-11-06 22:21:05 -05:00
|
|
|
|
2016-04-01 15:43:02 -04:00
|
|
|
Go to https://thomaslevine.com/!/urchin/ for documentation on writing tests.
|
2014-11-06 22:21:05 -05:00
|
|
|
|
|
|
|
EOF
|
2012-10-11 02:21:05 -04:00
|
|
|
}
|
2012-10-11 01:46:02 -04:00
|
|
|
|
2013-06-20 13:56:29 -04:00
|
|
|
plural () {
|
|
|
|
# Make $1 a plural according to the number $2.
|
|
|
|
# If $3 is supplied, use that instead of "${1}s".
|
|
|
|
# Result is written to stdout.
|
2016-03-02 15:39:31 -05:00
|
|
|
if [ "${2}" = 1 ]
|
2013-06-20 13:56:29 -04:00
|
|
|
then
|
2016-03-02 15:39:31 -05:00
|
|
|
printf '%s\n' "${1}"
|
2013-06-20 13:56:29 -04:00
|
|
|
else
|
|
|
|
printf '%s\n' "${3-${1}s}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-02-28 09:32:33 -05:00
|
|
|
validate_strings() {
|
2016-03-02 15:39:31 -05:00
|
|
|
test $(echo "${1}" | wc -l) -eq 1 || {
|
2016-02-28 09:32:33 -05:00
|
|
|
echo '$1 may not contain tab or newline characters.' >&2
|
|
|
|
echo 'If this is really a problem, tell me, and I may fix it.' >&2
|
|
|
|
urchin_exit 11
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 16:18:40 -05:00
|
|
|
main() {
|
|
|
|
cycle_shell=true
|
|
|
|
shell_list="${urchin_tmp}"/shell_list
|
2016-03-06 09:23:04 -05:00
|
|
|
test_arg_list="${urchin_tmp}"/test_list
|
2016-03-02 16:18:40 -05:00
|
|
|
run_in_series=false
|
|
|
|
force=false
|
|
|
|
exit_on_not_ok=false
|
|
|
|
tap_format=false
|
2016-03-06 04:44:10 -05:00
|
|
|
print_in_color=false
|
2016-03-06 05:39:40 -05:00
|
|
|
|
2016-03-06 05:45:40 -05:00
|
|
|
print_margins=true
|
2016-03-06 05:39:40 -05:00
|
|
|
print_ok=false
|
|
|
|
print_not_ok=true
|
2016-03-06 04:37:08 -05:00
|
|
|
print_ok_stdout=false
|
|
|
|
print_not_ok_stdout=false
|
2016-04-01 15:52:34 -04:00
|
|
|
print_debug=false
|
2016-03-02 16:18:40 -05:00
|
|
|
while [ "${#}" -gt 0 ]
|
|
|
|
do
|
|
|
|
case "${1}" in
|
|
|
|
-b|--run-in-series) run_in_series=true;;
|
|
|
|
-e|--exit-on-fail) exit_on_not_ok=true;;
|
|
|
|
-f|--force) force=true;;
|
|
|
|
-s|--shell)
|
|
|
|
shift
|
|
|
|
shell_for_sh_tests="${1}"
|
|
|
|
|
|
|
|
which "${shell_for_sh_tests}" > /dev/null || {
|
|
|
|
echo "Cannot find specified shell: '${shell_for_sh_tests}'" >&2
|
|
|
|
urchin_help >&2
|
|
|
|
urchin_exit 11
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_strings "${shell_for_sh_tests}" 'Shell paths'
|
2016-03-29 12:57:21 -04:00
|
|
|
if echo "${shell_for_sh_tests}" | grep -q \ ; then
|
2016-03-02 16:18:40 -05:00
|
|
|
echo "Warning: It is best if shell paths contain no spaces so that
|
|
|
|
you don't need to quote the TEST_SHELL variable." > /dev/stderr
|
|
|
|
fi
|
2016-02-28 09:01:17 -05:00
|
|
|
|
2016-03-02 16:18:40 -05:00
|
|
|
echo "${shell_for_sh_tests}" >> "${shell_list}"
|
|
|
|
;;
|
|
|
|
-n|--disable-cycling) cycle_shell=false;;
|
|
|
|
-t|--tap) tap_format=true;;
|
|
|
|
-T|--timeout) shift; urchin_timeout="${1}" ;;
|
2016-03-31 15:56:12 -04:00
|
|
|
-p|--pretty) print_in_color=true;;
|
2016-03-06 05:42:34 -05:00
|
|
|
|
2016-03-06 05:45:40 -05:00
|
|
|
-q|--quiet) print_not_ok=false
|
|
|
|
print_margins=false;;
|
2016-03-06 08:54:10 -05:00
|
|
|
-v) print_not_ok_stdout=true;;
|
|
|
|
-vv) print_not_ok_stdout=true
|
|
|
|
print_ok=true;;
|
|
|
|
-vvv|--verbose)print_not_ok_stdout=true
|
|
|
|
print_ok=true;
|
2016-03-06 05:42:34 -05:00
|
|
|
print_ok_stdout=true;;
|
2016-04-01 15:52:34 -04:00
|
|
|
-vvvv|--debug) print_not_ok_stdout=true
|
|
|
|
print_ok=true;
|
|
|
|
print_ok_stdout=true
|
|
|
|
print_debug=true;;
|
2016-03-06 05:42:34 -05:00
|
|
|
|
2016-03-02 16:18:40 -05:00
|
|
|
-h|--help) urchin_help
|
|
|
|
urchin_exit 0;;
|
|
|
|
--version) echo "${VERSION}"
|
|
|
|
urchin_exit;;
|
|
|
|
-*) urchin_help >&2
|
|
|
|
urchin_exit 11;;
|
2016-03-06 09:19:04 -05:00
|
|
|
*) validate_strings "${1}" 'Test file names'
|
|
|
|
validate_test_arg "${1}"
|
2016-03-06 09:23:04 -05:00
|
|
|
echo "${1}" >> "${test_arg_list}" ;;
|
2016-03-02 16:18:40 -05:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
2016-02-28 11:53:49 -05:00
|
|
|
|
2016-03-31 15:54:27 -04:00
|
|
|
if $print_in_color; then
|
|
|
|
success_mark=✓
|
|
|
|
fail_mark=✗
|
|
|
|
else
|
|
|
|
success_mark=.
|
|
|
|
fail_mark=F
|
|
|
|
fi
|
|
|
|
|
2016-03-02 16:18:40 -05:00
|
|
|
# -------------------- VALIDATE INPUT -------------------- #
|
|
|
|
if ! "${cycle_shell}" && test -f "${shell_list}"; then
|
|
|
|
echo "The -n/--disable-cycling and -s/--shell options clash with each other." >&2
|
|
|
|
urchin_exit 11
|
2016-02-28 11:53:49 -05:00
|
|
|
fi
|
2016-02-28 09:14:55 -05:00
|
|
|
|
2016-03-02 16:18:40 -05:00
|
|
|
# If -s was not passed, use the available default shells.
|
|
|
|
if ! test -f "${shell_list}"; then
|
|
|
|
if $cycle_shell; then
|
|
|
|
for shell in $DEFAULT_SHELLS; do
|
|
|
|
if which $shell > /dev/null; then
|
|
|
|
echo $shell >> "$shell_list"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo > "$shell_list"
|
|
|
|
fi
|
2016-02-28 07:02:57 -05:00
|
|
|
fi
|
2012-10-11 02:21:05 -04:00
|
|
|
|
2016-04-01 15:52:34 -04:00
|
|
|
if $print_debug; then
|
|
|
|
echo Cycling with the following shells:
|
|
|
|
cat "${shell_list}"
|
|
|
|
fi
|
|
|
|
|
2016-03-02 16:18:40 -05:00
|
|
|
if test -n "${urchin_timeout}"; then
|
|
|
|
# Choose the timeout command
|
2016-04-03 21:04:04 -04:00
|
|
|
if timeout -t 0 true 2> /dev/null; then
|
2016-03-02 16:18:40 -05:00
|
|
|
TIMEOUT="timeout -t ${urchin_timeout}"
|
2016-04-03 21:04:04 -04:00
|
|
|
elif timeout 0 true 2> /dev/null; then
|
2016-03-02 16:18:40 -05:00
|
|
|
TIMEOUT="timeout ${urchin_timeout}"
|
|
|
|
else
|
2016-03-21 16:28:59 -04:00
|
|
|
echo I couldn\'t figure out how to use your version of timeout >&2
|
2016-03-02 16:18:40 -05:00
|
|
|
urchin_exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2016-02-28 11:12:13 -05:00
|
|
|
|
2016-03-02 16:18:40 -05:00
|
|
|
if "${exit_on_not_ok}" && ! "${run_in_series}"; then
|
|
|
|
echo 'You must also pass -b/--series in order to use -e/--exit-on-fail.' >&2
|
|
|
|
urchin_exit 11
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -------------------- REALLY RUN -------------------- #
|
2016-02-28 05:39:32 -05:00
|
|
|
start=$(date +%s)
|
|
|
|
|
2016-02-28 07:14:16 -05:00
|
|
|
# 1 test file or folder to run
|
|
|
|
# 2 urchin root
|
2016-02-28 09:01:17 -05:00
|
|
|
# 3 Should we cycle shells?
|
2016-02-28 07:14:16 -05:00
|
|
|
# 4 TEST_SHELL
|
2016-03-06 09:19:04 -05:00
|
|
|
while read seed; do
|
|
|
|
recurse "$(fullpath "${seed}")" "${root}" "${cycle_shell}" \
|
|
|
|
"${TEST_SHELL}" || break
|
2016-03-06 09:23:04 -05:00
|
|
|
done < "${test_arg_list}"
|
2016-02-28 05:39:32 -05:00
|
|
|
finish=$(date +%s)
|
2016-02-28 05:18:06 -05:00
|
|
|
|
2016-03-02 16:46:11 -05:00
|
|
|
test $(cat "${urchin_tmp}"/log | wc -l) -gt 0 || {
|
|
|
|
echo 'No tests found' > /dev/stderr
|
|
|
|
urchin_exit 1
|
|
|
|
}
|
|
|
|
|
2016-03-02 15:39:31 -05:00
|
|
|
report_outcome "${root}" "${tap_format}" "${urchin_tmp}"/log "${start}" \
|
|
|
|
"${finish}"
|
|
|
|
urchin_exit "${?}"
|
2016-03-02 16:18:40 -05:00
|
|
|
}
|
|
|
|
|
2016-03-06 08:39:29 -05:00
|
|
|
test -n "${TESTING_URCHIN_INTERNALS}" || main "$@"
|