diff --git a/yesod/test/run.sh b/yesod/test/run.sh index 3b81e612..7095acda 100755 --- a/yesod/test/run.sh +++ b/yesod/test/run.sh @@ -1,97 +1,12 @@ -#!/bin/bash -e -# -# Runs test/scaffold.sh with a variety of inputs. Hides all output -# besides failure details. -# -### +#!/bin/bash -[[ "$1" =~ -v|--verbose ]] && stdout=/dev/stdout || stdout=/dev/null +cat << EOF -tmp='/tmp' -pwd="$PWD" +You're using the deprecated ./test/run.sh. This file will be removed +soon in favor of ../scripts/runtests. -pkg= -dir= +Running ../scripts/runtests... -failures=() -n_tested=0 -n_failed=0 +EOF -# runs the function named by $1, silencing stdout and redirecting stderr -# 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 '' - 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 $? +../scripts/runtests "$@" diff --git a/yesod/test/scaffold.sh b/yesod/test/scaffold.sh index 303a9656..303fc363 100755 --- a/yesod/test/scaffold.sh +++ b/yesod/test/scaffold.sh @@ -1,12 +1,10 @@ #!/bin/bash -ex -rm -rf foobar runghc main.hs init ( cd foobar cabal install cabal install -fdevel + cabal install -fproduction ) - -ghc-pkg unregister foobar diff --git a/yesod/test/scaffold_test.sh b/yesod/test/scaffold_test.sh new file mode 100644 index 00000000..d12ea1ea --- /dev/null +++ b/yesod/test/scaffold_test.sh @@ -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 ; }