Use new test runner from scripts
* Create scaffold_test.sh which holds actual tests (still calls scaffold.sh) * Move rm/unregister of foobar to setup/teardown functions * run.sh now prints deprecation warning and calls ../scripts/runtests
This commit is contained in:
parent
8a615e1493
commit
62030bee5a
@ -1,97 +1,12 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash
|
||||||
#
|
|
||||||
# Runs test/scaffold.sh with a variety of inputs. Hides all output
|
|
||||||
# besides failure details.
|
|
||||||
#
|
|
||||||
###
|
|
||||||
|
|
||||||
[[ "$1" =~ -v|--verbose ]] && stdout=/dev/stdout || stdout=/dev/null
|
cat << EOF
|
||||||
|
|
||||||
tmp='/tmp'
|
You're using the deprecated ./test/run.sh. This file will be removed
|
||||||
pwd="$PWD"
|
soon in favor of ../scripts/runtests.
|
||||||
|
|
||||||
pkg=
|
Running ../scripts/runtests...
|
||||||
dir=
|
|
||||||
|
|
||||||
failures=()
|
EOF
|
||||||
n_tested=0
|
|
||||||
n_failed=0
|
|
||||||
|
|
||||||
# runs the function named by $1, silencing stdout and redirecting stderr
|
../scripts/runtests "$@"
|
||||||
# to /tmp/function.errors. failures are tracked to be reported on during
|
|
||||||
# cleanup
|
|
||||||
run_test() { # {{{
|
|
||||||
local test_function="$*"
|
|
||||||
|
|
||||||
n_tested=$((n_tested+1))
|
|
||||||
|
|
||||||
if $test_function >"$stdout" 2>"$tmp/$test_function.errors"; then
|
|
||||||
echo -n '.'
|
|
||||||
[[ -f "$tmp/$test_function.errors" ]] && rm "$tmp/$test_function.errors"
|
|
||||||
else
|
|
||||||
echo -n 'F'
|
|
||||||
failures+=( "$test_function" )
|
|
||||||
n_failed=$((n_failed+1))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
# changes back to the original directory, removes the dist file and
|
|
||||||
# outputs a report of tests and failures
|
|
||||||
cleanup() { # {{{
|
|
||||||
cd "$pwd"
|
|
||||||
[[ -d "$dir" ]] && rm -r "$dir"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo
|
|
||||||
echo "Tests: $n_tested, Failures: $n_failed."
|
|
||||||
echo
|
|
||||||
|
|
||||||
[[ $n_failed -eq 0 ]] && return 0
|
|
||||||
|
|
||||||
for test in ${failures[@]}; do
|
|
||||||
echo "Failure: $test"
|
|
||||||
echo 'details:'
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [[ -f "$tmp/$test.errors" ]]; then
|
|
||||||
cat "$tmp/$test.errors"
|
|
||||||
rm "$tmp/$test.errors"
|
|
||||||
else
|
|
||||||
echo '<no stderr captured>'
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
done
|
|
||||||
|
|
||||||
return $n_failed
|
|
||||||
}
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
# compilation is test #1, sets global variable dir. other tests are run
|
|
||||||
# from within this directory and it is removed as part of cleanup
|
|
||||||
test_compile() {
|
|
||||||
cabal clean
|
|
||||||
cabal install
|
|
||||||
cabal sdist
|
|
||||||
|
|
||||||
read -r pkg < <(find dist/ -type f -name '*.tar.gz' | sort -rV)
|
|
||||||
dir="$(basename "$pkg" .tar.gz)"
|
|
||||||
|
|
||||||
tar -xzf "$pkg" && cd "$dir"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_sqlite() { ../test/scaffold.sh < ../test/sqlite-input.txt ; }
|
|
||||||
test_postgresql() { ../test/scaffold.sh < ../test/postgresql-input.txt; }
|
|
||||||
test_mongodb() { ../test/scaffold.sh < ../test/mongodb-input.txt ; }
|
|
||||||
test_tiny() { ../test/scaffold.sh < ../test/tiny-input.txt ; }
|
|
||||||
|
|
||||||
echo 'Started'
|
|
||||||
run_test 'test_compile'
|
|
||||||
run_test 'test_sqlite'
|
|
||||||
run_test 'test_postgresql'
|
|
||||||
run_test 'test_mongodb'
|
|
||||||
run_test 'test_tiny'
|
|
||||||
cleanup
|
|
||||||
|
|
||||||
exit $?
|
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
#!/bin/bash -ex
|
#!/bin/bash -ex
|
||||||
|
|
||||||
rm -rf foobar
|
|
||||||
runghc main.hs init
|
runghc main.hs init
|
||||||
|
|
||||||
(
|
(
|
||||||
cd foobar
|
cd foobar
|
||||||
cabal install
|
cabal install
|
||||||
cabal install -fdevel
|
cabal install -fdevel
|
||||||
|
cabal install -fproduction
|
||||||
)
|
)
|
||||||
|
|
||||||
ghc-pkg unregister foobar
|
|
||||||
|
|||||||
7
yesod/test/scaffold_test.sh
Normal file
7
yesod/test/scaffold_test.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
setup() { rm -rf foobar; }
|
||||||
|
teardown() { rm -rf foobar; ghc-pkg unregister foobar &>/dev/null; }
|
||||||
|
|
||||||
|
test_sqlite() { ../test/scaffold.sh < ../test/sqlite-input.txt ; }
|
||||||
|
test_postgresql() { ../test/scaffold.sh < ../test/postgresql-input.txt; }
|
||||||
|
test_mongodb() { ../test/scaffold.sh < ../test/mongodb-input.txt ; }
|
||||||
|
test_tiny() { ../test/scaffold.sh < ../test/tiny-input.txt ; }
|
||||||
Loading…
Reference in New Issue
Block a user