2013-06-19 02:46:31 -04:00
|
|
|
#!/bin/sh
|
2012-10-04 07:24:03 -04:00
|
|
|
|
2016-02-08 11:02:00 -05:00
|
|
|
# This file is part of urchin. It is subject to the license terms in the
|
2016-02-08 11:09:00 -05:00
|
|
|
# COPYING file found in the top-level directory of this distribution or at
|
|
|
|
# https://raw.githubusercontent.com/tlevine/urchin/master/COPYING
|
|
|
|
|
2016-02-08 11:02:00 -05:00
|
|
|
# No part of urchin, including this file, may be copied, modified, propagated,
|
|
|
|
# or distributed except according to the terms contained in the COPYING file.
|
|
|
|
|
2016-02-27 20:18:55 -05:00
|
|
|
set -e
|
2016-02-08 11:09:00 -05:00
|
|
|
|
2016-02-28 10:16:57 -05:00
|
|
|
DEFAULT_SHELLS='sh bash dash mksh zsh'
|
2016-02-28 09:01:17 -05:00
|
|
|
|
2016-02-08 11:05:56 -05:00
|
|
|
# Make sure that CDPATH isn't set, as it causes `cd` to behave unpredictably -
|
2016-02-27 20:18:55 -05:00
|
|
|
# notably, it can produce output.
|
Make sure that CDPATH isn't set, as it causes `cd` to behave unpredictably - notably, it can produce output, which breaks fullpath().
Also: Improved CLI help, updated URLs in read-me, cleaned up package.json:
I've tried to clarify the intent of `-x` in the CLI help, but I haven't touched the read-me in that respect.
I don't see any benefit to `-x`:
* Just using `#/bin/sh` as the shebang line in combination with `-s <shell>` gives you the same functionality,
* When it comes to invoking scripts from _within_ test scripts, nothing can do the work for you: you consciously have to mark the invocation with _something_ to indicate that it should be controlled from the outside; it won't get any easier than `$TEST_SHELL ...`
* Finally, using a shebang line such as `#!/usr/bin/env urchin -x` is problematic for two reasons:
* Some platforms can handle only *1* argument in a shebang line.
* In a _package-local_ installation, `#!/usr/bin/env` may not find the Urchin executable.
I'm also not sure how the following (from `readme.md`) fits in the picture:
> It might make sense if you do this.
export TEST_SHELL=zsh && urchin -x
export TEST_SHELL=bash && urchin -x
(As an aside: To achieve the same thing, you don't need `export`; `TEST_SHELL=zsh urchin -x` and `TEST_SHELL=bash urchin -x` is the better choice.)
How does this relate to use in a _shebang line_?
`urchin_help()` now uses a here-doc: easier to maintain, and should work in all Bourne-like shells.
`readmeFilename` removed from `package.json`:
> "The readmeFilename does not need to ever be in your actual package.json file" - npm/npm#3573
2014-12-03 09:48:49 -05:00
|
|
|
unset CDPATH
|
|
|
|
|
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)
|
|
|
|
> $urchin_tmp/log
|
2016-02-28 04:08:20 -05:00
|
|
|
urchin_exit() {
|
2016-02-28 14:18:54 -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-02-28 14:18:54 -05:00
|
|
|
x="$urchin_tmp/stdout$(fullpath "$1")"
|
2016-02-28 08:12:55 -05:00
|
|
|
mkdir -p "$(dirname -- "$x")"
|
|
|
|
echo "$x"
|
|
|
|
}
|
|
|
|
|
2016-02-28 04:12:57 -05:00
|
|
|
# Expand relative paths
|
|
|
|
alias fullpath='readlink -f --'
|
|
|
|
|
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.
|
|
|
|
current="$(remove_trailing_slash "$1")"
|
|
|
|
if test -n "$2"; then
|
|
|
|
orig="$2"
|
|
|
|
else
|
|
|
|
orig="$1"
|
|
|
|
fi
|
2016-02-28 06:18:39 -05:00
|
|
|
|
2016-02-28 06:22:51 -05:00
|
|
|
if test "$(readlink -f -- "$1")" = /; then
|
|
|
|
# Stop traversing upwards at /
|
|
|
|
if test -d "$orig"; then
|
|
|
|
echo "$orig"
|
|
|
|
else
|
2016-02-28 07:59:36 -05:00
|
|
|
dirname -- "$orig"
|
2016-02-28 06:22:51 -05:00
|
|
|
fi
|
|
|
|
elif ! test -e "$current"; then
|
|
|
|
echo "$current: No such file or directory">&2
|
|
|
|
return 1
|
|
|
|
elif test -f "$current"; then
|
2016-02-28 07:59:36 -05:00
|
|
|
urchin_root "$(dirname -- "$current")" "$orig"
|
2016-02-28 06:27:55 -05:00
|
|
|
elif test -f "$current"/.urchin; then
|
2016-02-28 06:22:51 -05:00
|
|
|
remove_trailing_slash "$current"
|
|
|
|
else
|
|
|
|
urchin_root "$current"/.. "$orig"
|
|
|
|
fi
|
2016-02-28 06:18:39 -05:00
|
|
|
}
|
|
|
|
|
2016-01-29 12:17:31 -05:00
|
|
|
# Urchin version number
|
2016-02-27 20:18:55 -05:00
|
|
|
VERSION=0.1.0-rc1
|
2012-10-11 14:50:03 -04:00
|
|
|
|
2012-10-10 20:43:13 -04:00
|
|
|
indent() {
|
|
|
|
level="$1"
|
2016-02-08 10:14:22 -05:00
|
|
|
if test "$level" -gt 0; then
|
|
|
|
printf "%$((2 * ${level}))s"
|
|
|
|
fi
|
2012-10-10 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
2012-10-04 07:29:34 -04:00
|
|
|
recurse() {
|
2016-02-28 05:00:53 -05:00
|
|
|
set -e
|
2016-02-28 07:14:16 -05:00
|
|
|
requested_path="$1"
|
|
|
|
potential_test="$(fullpath "$2")"
|
2016-02-28 09:01:17 -05:00
|
|
|
cycle_shell="$3"
|
2016-02-28 07:14:16 -05:00
|
|
|
TEST_SHELL="$4"
|
2016-02-28 05:27:49 -05:00
|
|
|
|
2016-02-28 05:00:53 -05:00
|
|
|
for ignore in setup_dir teardown_dir setup teardown; do
|
2016-02-28 13:41:00 -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-02-28 07:15:42 -05:00
|
|
|
echo "$requested_path" | grep "^$potential_test" > /dev/null ||
|
|
|
|
echo "$potential_test" | grep "^$requested_path" > /dev/null ||
|
2016-02-28 07:14:16 -05:00
|
|
|
return 0
|
2016-02-28 07:02:57 -05:00
|
|
|
|
2016-02-28 09:32:33 -05:00
|
|
|
validate_strings "$potential_test" 'Test file names'
|
2016-02-28 07:02:57 -05:00
|
|
|
|
2016-02-27 20:18:55 -05:00
|
|
|
if [ -d "$potential_test" ]; then
|
2016-01-27 05:14:21 -05:00
|
|
|
(
|
2016-02-28 04:36:48 -05:00
|
|
|
cd -- "$potential_test" > /dev/null
|
2016-02-28 14:18:54 -05:00
|
|
|
if test -f setup_dir; then . ./setup_dir; fi
|
2014-11-05 12:38:22 -05:00
|
|
|
|
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
|
|
|
# avoid "no matches found: *" error when directories are empty
|
|
|
|
setopt NULL_GLOB
|
|
|
|
fi
|
|
|
|
|
2016-02-27 20:18:55 -05:00
|
|
|
for test in *; do
|
2016-02-28 07:35:27 -05:00
|
|
|
if test "$test" = '*' && ! test -e $test; then
|
|
|
|
# The directory is empty.
|
|
|
|
break
|
|
|
|
fi
|
2012-10-10 20:43:13 -04:00
|
|
|
|
2016-02-28 11:05:03 -05:00
|
|
|
(
|
2016-02-28 14:18:54 -05:00
|
|
|
if test -f setup; then . ./setup; fi
|
2016-02-28 11:05:03 -05:00
|
|
|
set +e
|
|
|
|
recurse "$requested_path" "$test" "$cycle_shell" "$TEST_SHELL"
|
|
|
|
exit_code=$?
|
|
|
|
set -e
|
2016-02-28 14:18:54 -05:00
|
|
|
if test -f teardown; then . ./teardown; fi
|
2016-02-28 11:05:03 -05:00
|
|
|
exit $exit_code
|
|
|
|
) &
|
|
|
|
|
2016-02-28 11:19:42 -05:00
|
|
|
if $run_in_series; then
|
2016-02-28 11:05:03 -05:00
|
|
|
wait $!
|
|
|
|
exit_code=$?
|
|
|
|
if $exit_on_not_ok && test $exit_code -ne 0; then
|
2016-02-28 14:18:54 -05:00
|
|
|
if test -f teardown_dir; then . ./teardown_dir; fi
|
2016-02-28 11:05:03 -05:00
|
|
|
urchin_exit 1
|
|
|
|
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-02-28 14:18:54 -05:00
|
|
|
if test -f teardown_dir; then . ./teardown_dir; fi
|
2016-02-28 05:00:53 -05:00
|
|
|
)
|
2016-01-27 05:14:21 -05:00
|
|
|
else
|
2016-02-27 20:25:36 -05:00
|
|
|
if [ -x "$potential_test" ]; then
|
2016-02-28 07:59:36 -05:00
|
|
|
cd -- "$(dirname -- "$potential_test")"
|
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-02-28 11:53:49 -05:00
|
|
|
if test -z "$the_test_shell"; then
|
2016-02-28 11:32:06 -05:00
|
|
|
# Shell cycling is disabled with -n; use the present value of
|
|
|
|
# TEST_SHELL or default to /bin/sh
|
|
|
|
if [ -n "$TEST_SHELL" ]; then
|
|
|
|
the_test_shell="$TEST_SHELL"
|
|
|
|
else
|
2016-02-28 11:53:49 -05:00
|
|
|
the_test_shell=/bin/sh
|
2016-02-28 11:32:06 -05:00
|
|
|
fi
|
2016-02-28 09:01:17 -05:00
|
|
|
fi
|
2016-02-28 11:32:06 -05:00
|
|
|
(
|
2016-02-28 14:18:54 -05:00
|
|
|
if test -f setup; then . ./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
|
|
|
{
|
|
|
|
if $cycle_shell &&
|
|
|
|
has_sh_or_no_shebang_line "$potential_test"; then
|
|
|
|
TEST_SHELL="$the_test_shell" "$the_test_shell" \
|
|
|
|
"$potential_test"
|
|
|
|
else
|
|
|
|
TEST_SHELL="$the_test_shell" "$potential_test"
|
|
|
|
fi
|
|
|
|
} > "$(stdout_file "$potential_test")" 2>&1
|
2016-02-28 11:32:06 -05:00
|
|
|
exit_code="$?"
|
|
|
|
set -e
|
|
|
|
finish=$(date +%s)
|
|
|
|
|
2016-02-28 14:18:54 -05:00
|
|
|
if test -f teardown; then . ./setup; fi
|
2016-02-28 11:32:06 -05:00
|
|
|
|
|
|
|
if [ $exit_code -eq 0 ]; then
|
|
|
|
result=ok
|
|
|
|
elif [ $exit_code -eq 3 ]; then
|
|
|
|
result=skip
|
|
|
|
else
|
|
|
|
result=not_ok
|
|
|
|
fi
|
|
|
|
|
|
|
|
elapsed=$(($finish - $start))
|
|
|
|
printf "${potential_test}\t${the_test_shell}\t${result}\t${elapsed}\n" \
|
2016-02-28 14:18:54 -05:00
|
|
|
>> $urchin_tmp/log
|
2016-02-28 11:32:06 -05:00
|
|
|
exit "$exit_code"
|
|
|
|
) &
|
|
|
|
|
|
|
|
if $run_in_series; then
|
|
|
|
wait $!
|
|
|
|
exit_code=$?
|
|
|
|
if $exit_on_not_ok && test $exit_code -ne 0; then
|
2016-02-28 14:18:54 -05:00
|
|
|
if test -f teardown_dir; then . ./teardown_dir; fi
|
2016-02-28 11:32:06 -05:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done < $shell_list
|
|
|
|
wait
|
2012-10-04 07:29:34 -04:00
|
|
|
else
|
2016-02-28 10:50:53 -05:00
|
|
|
# Shell is ''
|
2016-02-28 14:18:54 -05:00
|
|
|
printf "${potential_test}\t\tskip\t0\n" >> $urchin_tmp/log
|
2016-01-27 05:14:21 -05:00
|
|
|
fi
|
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-02-28 07:41:39 -05:00
|
|
|
root="$1"
|
|
|
|
tap_format="$2"
|
|
|
|
log_file="$3"
|
|
|
|
start="$4"
|
|
|
|
finish="$5"
|
|
|
|
|
|
|
|
escaped_root="$(fullpath "$root" | sed 's/\//\\\//g')"
|
2016-02-28 05:39:32 -05:00
|
|
|
elapsed=$(($finish - $start))
|
2016-02-28 05:07:55 -05:00
|
|
|
|
2016-02-28 07:53:26 -05:00
|
|
|
if "$tap_format"; then
|
|
|
|
printf \#\
|
|
|
|
fi
|
|
|
|
echo Running tests at $(date +%Y-%m-%dT%H:%M:%S)
|
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
|
|
|
|
eval "$number=0"
|
|
|
|
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.
|
|
|
|
sorted_log_file=$(mktemp)
|
|
|
|
sort "$log_file" > $sorted_log_file
|
|
|
|
while read line; do
|
2016-02-28 09:32:33 -05:00
|
|
|
abspath=$(echo "$line" | cut -f1)
|
2016-02-28 08:12:55 -05:00
|
|
|
path=$(echo "$abspath" | sed "s/$escaped_root\/\?//")
|
2016-02-28 09:32:33 -05:00
|
|
|
the_shell=$(echo "$line" | cut -f2)
|
|
|
|
result=$(echo "$line" | cut -f3)
|
|
|
|
file_elapsed=$(echo "$line" | cut -f4)
|
2016-02-28 06:06:54 -05:00
|
|
|
|
2016-02-28 07:53:26 -05:00
|
|
|
prevdir=$currentdir
|
2016-02-28 07:59:36 -05:00
|
|
|
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-02-28 05:27:49 -05:00
|
|
|
if $tap_format; then
|
2016-02-28 05:57:27 -05:00
|
|
|
if [ "$result" == not_ok ]; then
|
2016-02-28 05:27:49 -05:00
|
|
|
not='not '
|
|
|
|
else
|
|
|
|
not=''
|
|
|
|
fi
|
|
|
|
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
|
|
|
|
|
|
|
if test -z "$the_shell"; then
|
|
|
|
the_shell='File is not executable.'
|
|
|
|
fi
|
|
|
|
echo "${not}ok $n - ${path} ($the_shell) ${skip}"
|
2016-02-28 05:57:27 -05:00
|
|
|
if [ "$result" == not_ok ]; then
|
2016-02-28 05:27:49 -05:00
|
|
|
echo '# ------------ Begin output ------------'
|
2016-02-28 08:12:55 -05:00
|
|
|
sed 's/^/# /' "$(stdout_file "$abspath")"
|
2016-02-28 05:27:49 -05:00
|
|
|
echo '# ------------ End output ------------'
|
|
|
|
fi
|
2016-02-28 05:39:32 -05:00
|
|
|
echo "# Previous test took $file_elapsed seconds."
|
2016-02-28 07:45:38 -05:00
|
|
|
else
|
2016-02-28 07:53:26 -05:00
|
|
|
if test "$prevdir" != "$currentdir"; then
|
|
|
|
echo
|
|
|
|
fi
|
2016-02-28 10:28:56 -05:00
|
|
|
if test "$prevpath" != "$path"; then
|
|
|
|
printf "$(dirname -- "$path")/\n> $(basename -- "$path")\n"
|
|
|
|
fi
|
2016-02-28 07:45:38 -05:00
|
|
|
case "$result" in
|
|
|
|
ok)
|
|
|
|
# On success, print a green '✓'
|
|
|
|
printf '\033[32m✓ \033[0m'
|
2016-02-28 11:12:13 -05:00
|
|
|
echo "${the_shell} ($file_elapsed $(plural second $file_elapsed))"
|
2016-02-28 07:45:38 -05:00
|
|
|
;;
|
|
|
|
not_ok)
|
|
|
|
# On not_ok, print a red '✗'
|
|
|
|
printf '\033[31m✗ \033[0m'
|
2016-02-28 11:12:13 -05:00
|
|
|
echo "${the_shell} ($file_elapsed $(plural second $file_elapsed))"
|
2016-02-28 07:45:38 -05:00
|
|
|
|
2016-02-28 08:13:17 -05:00
|
|
|
# Print output captured from not_ok test in red.
|
2016-02-28 07:45:38 -05:00
|
|
|
printf '\033[31m'
|
|
|
|
|
2016-02-28 10:28:56 -05:00
|
|
|
sed 's/^/ # /' "$(stdout_file "$abspath")"
|
2016-02-28 07:45:38 -05:00
|
|
|
printf '\033[0m'
|
|
|
|
;;
|
|
|
|
skip)
|
2016-02-28 10:50:53 -05:00
|
|
|
if test -z "$the_shell"; then
|
2016-02-28 13:41:00 -05:00
|
|
|
echo ' (File is not executable.)'
|
|
|
|
else
|
|
|
|
echo " ${the_shell} ($file_elapsed $(plural second $file_elapsed))"
|
2016-02-28 10:50:53 -05:00
|
|
|
fi
|
2016-02-28 07:45:38 -05:00
|
|
|
;;
|
|
|
|
esac
|
2016-02-28 05:27:49 -05:00
|
|
|
fi
|
2016-02-28 04:17:16 -05:00
|
|
|
|
2016-02-28 10:28:56 -05:00
|
|
|
prevpath="$path"
|
2016-02-28 06:14:23 -05:00
|
|
|
done < $sorted_log_file
|
|
|
|
rm $sorted_log_file
|
2016-02-28 04:17:16 -05:00
|
|
|
|
|
|
|
set +e
|
|
|
|
if $tap_format; then
|
2016-02-28 06:14:23 -05:00
|
|
|
echo "# Full test suite took $elapsed $(plural second $elapsed)."
|
|
|
|
echo 1..$n
|
2016-02-28 04:17:16 -05:00
|
|
|
else
|
2016-02-28 07:53:26 -05:00
|
|
|
echo
|
2016-02-28 04:17:16 -05:00
|
|
|
echo "Done, took $elapsed $(plural second $elapsed)."
|
2016-02-28 07:45:38 -05:00
|
|
|
printf '%s\n' "$oks $(plural test "$oks") passed."
|
2016-02-28 07:59:36 -05:00
|
|
|
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.
|
|
|
|
if [ $not_oks -gt 0 ] ; then
|
|
|
|
printf '\033[31m'
|
|
|
|
fi
|
2016-02-28 07:45:38 -05:00
|
|
|
printf '%s\n' "$not_oks $(plural test "$not_oks") failed."
|
2016-02-28 04:17:16 -05:00
|
|
|
printf '\033[m'
|
|
|
|
fi
|
2016-02-28 05:57:27 -05:00
|
|
|
test "$not_oks" -eq '0'
|
2012-10-04 07:29:34 -04:00
|
|
|
}
|
2012-10-04 12:43:49 -04:00
|
|
|
|
2014-10-17 17:16:12 -04:00
|
|
|
has_sh_or_no_shebang_line() {
|
2016-02-08 11:05:56 -05:00
|
|
|
# no shebang line at all
|
|
|
|
head -n 1 "$1" | grep -vqE '^#!' && return 0
|
|
|
|
|
|
|
|
# shebang line is '#!/bin/sh' or legal variations thereof
|
|
|
|
head -n 1 "$1" | grep -qE '^#![[:blank:]]*/bin/sh($|[[:blank:]])' &&
|
|
|
|
return 0
|
|
|
|
|
2014-10-17 17:16:12 -04:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
USAGE="usage: $0 [<options>] <test 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
|
|
|
|
|
|
|
|
$USAGE
|
|
|
|
|
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-02-28 10:16:57 -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.
|
|
|
|
2. If the test file has a shebang line of "#!/bin/sh" or no shebang
|
|
|
|
line at all, the test script is also executed in that shell.
|
|
|
|
|
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.)
|
|
|
|
|
|
|
|
-n, --disable-cycling Disable the cycling of shells; Urchin will execute
|
|
|
|
test files directly, and it will not manipulate the
|
|
|
|
TEST_SHELL environment variable.
|
|
|
|
|
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-02-28 10:15:09 -05:00
|
|
|
This is useful if you are running something
|
|
|
|
configuration files with Urchin.
|
|
|
|
-T, --timeout <seconds> Kill a test if it runs for longer than the
|
|
|
|
specified duration. The default is no timeout.
|
2016-02-28 10:19:15 -05:00
|
|
|
XXX Not yet implemented
|
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".
|
|
|
|
|
|
|
|
These options affect how results are formatted.
|
|
|
|
|
|
|
|
-t, --tap Format output in Test Anything Protocol (TAP)
|
|
|
|
-v, --verbose Print stdout from all tests, not just failed tests.
|
|
|
|
XXX Not yet implemented
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Go to https://github.com/tlevine/urchin for documentation on writing tests.
|
|
|
|
|
|
|
|
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.
|
|
|
|
if [ "$2" = 1 ]
|
|
|
|
then
|
|
|
|
printf '%s\n' "$1"
|
|
|
|
else
|
|
|
|
printf '%s\n' "${3-${1}s}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-10-11 02:21:05 -04:00
|
|
|
urchin_molly_guard() {
|
2014-10-16 16:37:51 -04:00
|
|
|
{
|
|
|
|
echo
|
|
|
|
echo 'The name of the directory on which you are running urchin'
|
|
|
|
echo 'does not contain the word "test", so I am not running,'
|
|
|
|
echo 'in case that was an accident. Use the -f flag if you really'
|
|
|
|
echo 'want to run urchin on that directory.'
|
|
|
|
echo
|
|
|
|
} >&2
|
2016-02-28 04:08:20 -05:00
|
|
|
urchin_exit 1
|
2012-10-11 02:21:05 -04:00
|
|
|
}
|
|
|
|
|
2016-02-28 09:32:33 -05:00
|
|
|
validate_strings() {
|
|
|
|
test $(echo "$1" | wc -l) -eq 1 || {
|
|
|
|
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-02-28 09:01:17 -05:00
|
|
|
cycle_shell=true
|
2016-02-28 14:18:54 -05:00
|
|
|
shell_list=$urchin_tmp/shell_list
|
2016-02-28 11:00:07 -05:00
|
|
|
run_in_series=false
|
2014-10-16 16:37:51 -04:00
|
|
|
force=false
|
2016-02-28 05:57:27 -05:00
|
|
|
exit_on_not_ok=false
|
2016-01-26 19:32:51 -05:00
|
|
|
tap_format=false
|
2012-10-11 02:21:05 -04:00
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case "$1" in
|
2016-02-28 14:45:18 -05:00
|
|
|
-b|--run-in-series) run_in_series=true;;
|
|
|
|
-e|--exit-on-fail) exit_on_not_ok=true;;
|
2014-10-16 16:37:51 -04:00
|
|
|
-f) force=true;;
|
2014-10-17 17:16:12 -04:00
|
|
|
-s)
|
|
|
|
shift
|
|
|
|
shell_for_sh_tests=$1
|
2016-02-28 09:01:17 -05:00
|
|
|
|
2016-02-08 11:05:56 -05:00
|
|
|
which "$shell_for_sh_tests" > /dev/null || {
|
|
|
|
echo "Cannot find specified shell: '$shell_for_sh_tests'" >&2
|
|
|
|
urchin_help >&2
|
2016-02-28 04:08:20 -05:00
|
|
|
urchin_exit 11
|
2016-02-28 09:01:17 -05:00
|
|
|
}
|
|
|
|
|
2016-02-28 09:32:33 -05:00
|
|
|
validate_strings "$shell_for_sh_tests" 'Shell paths'
|
2016-02-28 09:01:17 -05:00
|
|
|
|
2016-02-28 09:14:55 -05:00
|
|
|
echo "$shell_for_sh_tests" >> "$shell_list"
|
2016-02-28 09:01:17 -05:00
|
|
|
;;
|
|
|
|
-n) cycle_shell=false;;
|
2016-01-26 19:32:51 -05:00
|
|
|
-t) tap_format=true;;
|
2013-06-18 17:21:31 -04:00
|
|
|
-h|--help) urchin_help
|
|
|
|
exit 0;;
|
2016-02-28 09:12:21 -05:00
|
|
|
--version) echo "$VERSION"
|
2016-02-28 04:08:20 -05:00
|
|
|
urchin_exit;;
|
2014-10-17 17:16:12 -04:00
|
|
|
-*) urchin_help >&2
|
2012-10-11 02:21:05 -04:00
|
|
|
exit 1;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2016-02-28 11:53:49 -05:00
|
|
|
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
|
|
|
|
fi
|
|
|
|
|
2016-02-28 10:19:15 -05:00
|
|
|
# If -s was not passed, use the available default shells.
|
2016-02-28 09:14:55 -05:00
|
|
|
if ! test -f "$shell_list"; then
|
2016-02-28 11:53:49 -05:00
|
|
|
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 09:14:55 -05:00
|
|
|
fi
|
|
|
|
|
2012-10-11 02:21:05 -04:00
|
|
|
# Verify argument for main stuff
|
2016-02-28 07:02:57 -05:00
|
|
|
if [ "$#" != '1' ] || [ ! -e "$1" ]; then
|
|
|
|
if [ -n "$1" ] && [ ! -e "$1" ]; then
|
|
|
|
echo "No such file or directory: '$1'" >&2
|
|
|
|
fi
|
2014-10-16 16:37:51 -04:00
|
|
|
echo "$USAGE" >&2
|
2016-02-28 04:08:20 -05:00
|
|
|
urchin_exit 11
|
2012-10-11 15:47:08 -04:00
|
|
|
fi
|
2012-10-11 02:21:05 -04:00
|
|
|
|
2016-02-28 11:19:42 -05:00
|
|
|
if $exit_on_not_ok && ! $run_in_series; then
|
2016-02-28 11:12:13 -05:00
|
|
|
echo 'You must also pass -b/--series in order to use -e/--exit-on-fail.' >&2
|
|
|
|
urchin_exit 11
|
|
|
|
fi
|
|
|
|
|
2012-10-11 02:21:05 -04:00
|
|
|
# Run or present the Molly guard.
|
2016-02-28 07:02:57 -05:00
|
|
|
root="$(urchin_root "$1")"
|
|
|
|
if basename "$(fullpath "$root")" |
|
2016-02-28 14:43:32 -05:00
|
|
|
grep -i 'test' > /dev/null || $force; then
|
2016-02-28 04:25:21 -05:00
|
|
|
|
2016-02-28 05:39:32 -05:00
|
|
|
start=$(date +%s)
|
|
|
|
set +e
|
|
|
|
|
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-02-28 09:01:17 -05:00
|
|
|
recurse "$(fullpath "$1")" "$root" "$cycle_shell" "$TEST_SHELL"
|
2016-02-28 05:00:53 -05:00
|
|
|
exit_code=$?
|
2016-02-28 05:39:32 -05:00
|
|
|
|
2016-02-28 05:00:53 -05:00
|
|
|
set -e
|
2016-02-28 05:39:32 -05:00
|
|
|
finish=$(date +%s)
|
2016-02-28 05:18:06 -05:00
|
|
|
|
2016-02-28 14:18:54 -05:00
|
|
|
report_outcome "$root" $tap_format $urchin_tmp/log $start $finish
|
2016-02-28 05:18:06 -05:00
|
|
|
|
2016-02-28 04:36:48 -05:00
|
|
|
urchin_exit $exit_code
|
2012-10-11 02:21:05 -04:00
|
|
|
else
|
|
|
|
urchin_molly_guard
|
2012-10-08 10:43:14 -04:00
|
|
|
fi
|