This commit is contained in:
Thomas Levine 2016-02-27 15:59:17 +00:00
parent 97faea610c
commit 3efcf0aa33

48
urchin
View File

@ -8,6 +8,9 @@
# or distributed except according to the terms contained in the COPYING file. # or distributed except according to the terms contained in the COPYING file.
logfile=/tmp/log # sloppy for now
set -e
# Make sure that CDPATH isn't set, as it causes `cd` to behave unpredictably - # Make sure that CDPATH isn't set, as it causes `cd` to behave unpredictably -
# notably, it can produce output, which breaks fullpath(). # notably, it can produce output, which breaks fullpath().
@ -35,12 +38,16 @@ urchin_root() {
urchin_root $(dirname "$current") "$orig" urchin_root $(dirname "$current") "$orig"
elif test -d "$current"/.urchin; then elif test -d "$current"/.urchin; then
echo "$current" echo "$current"
elif test "$(readlink -f $current)" = /; then elif test "$(readlink -f "$current")" = /; then
guess=$(readlink -f "$orig"|sed s+\(/tests?/\).*+/tests/+) if test -d "$orig"; then
origdir="$orig"
else
origdir=$(dirname "$orig")
fi
echo "You need to create the .urchin directory in the root of your tests, echo "You need to create the .urchin directory in the root of your tests,
maybe like this: maybe like this:
mkdir '$guess/.urchin' mkdir '$origdir/.urchin'
" >&2 " >&2
else else
urchin_root "$current"/.. "$orig" urchin_root "$current"/.. "$orig"
@ -48,13 +55,6 @@ maybe like this:
) )
} }
fullpath() {
(
cd -- "$1"
pwd
)
}
indent() { indent() {
level="$1" level="$1"
if test "$level" -gt 0; then if test "$level" -gt 0; then
@ -62,6 +62,22 @@ indent() {
fi fi
} }
escape_slashes() {
echo "$1" | sed s+/+\\\\/+g
}
get_stdout_file() {
root=$(readlink -f $(urchin_root "$1"))
test_file=$(readlink -f "$1")
eroot=$(escape_slashes "$root")
base=$(echo "$test_file" | sed "s/^$eroot/$eroot\/.urchin/")
if test -d "$1"; then
echo "$base"/.index
else
echo "$base"
fi
}
recurse() { recurse() {
potential_test="$1" potential_test="$1"
indent_level="$2" indent_level="$2"
@ -72,6 +88,9 @@ recurse() {
[ "$potential_test" = 'setup' ] && return [ "$potential_test" = 'setup' ] && return
[ "$potential_test" = 'teardown' ] && return [ "$potential_test" = 'teardown' ] && return
stdout_file="$(get_stdout_file "$potential_test")"
mkdir -p "$(dirname "$stdout_file")"
[ $indent_level -eq 0 ] && : > "$stdout_file" [ $indent_level -eq 0 ] && : > "$stdout_file"
if [ -d "$potential_test" ] if [ -d "$potential_test" ]
@ -193,7 +212,6 @@ recurse() {
return 1 return 1
fi fi
fi fi
[ $indent_level -eq 0 ] && rm "$stdout_file"
} }
has_sh_or_no_shebang_line() { has_sh_or_no_shebang_line() {
@ -343,13 +361,9 @@ if [ "$#" != '1' ] || [ ! -d "$1" ]
exit 11 exit 11
fi fi
# Constants
logfile=$(fullpath "$1")/.urchin.log
stdout_file=$(fullpath "$1")/.urchin_stdout
# Run or present the Molly guard. # Run or present the Molly guard.
if fullpath "$1" | grep -Fi 'test' > /dev/null || $force if dirname $(readlink -f $(urchin_root "$1")) |
then grep -Fi 'test' > /dev/null || $force; then
urchin_go "$1" "$shell_for_sh_tests" urchin_go "$1" "$shell_for_sh_tests"
else else
urchin_molly_guard urchin_molly_guard