From ab98799e8d8dd960b9fdb3c93c893ca3ac232793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Buckwalter?= Date: Thu, 22 Sep 2011 22:23:41 +0800 Subject: [PATCH 1/4] Alter nonce terminology in tests too. --- yesod-core/test/Test/InternalRequest.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yesod-core/test/Test/InternalRequest.hs b/yesod-core/test/Test/InternalRequest.hs index ba510cb5..97e90b98 100644 --- a/yesod-core/test/Test/InternalRequest.hs +++ b/yesod-core/test/Test/InternalRequest.hs @@ -30,16 +30,16 @@ g = undefined nonceSpecs :: [Spec] nonceSpecs = describe "Yesod.Internal.Request.parseWaiRequest (reqNonce)" - [ it "is Nothing for unsecure sessions" noUnsecureNonce - , it "ignores pre-existing nonce for unsecure sessions" ignoreUnsecureNonce - , it "uses preexisting nonce for secure sessions" useOldNonce - , it "generates a new nonce for secure sessions without nonce" generateNonce + [ it "is Nothing if sessions are disabled" noDisabledNonce + , it "ignores pre-existing nonce if sessions are disabled" ignoreDisabledNonce + , it "uses preexisting nonce in session" useOldNonce + , it "generates a new nonce for sessions without nonce" generateNonce ] -noUnsecureNonce = reqNonce r == Nothing where +noDisabledNonce = reqNonce r == Nothing where r = parseWaiRequest' defaultRequest [] Nothing g -ignoreUnsecureNonce = reqNonce r == Nothing where +ignoreDisabledNonce = reqNonce r == Nothing where r = parseWaiRequest' defaultRequest [("_NONCE", "old")] Nothing g useOldNonce = reqNonce r == Just "old" where From 8a615e14938b7a22681e523a0597fb9aaa79f725 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Thu, 22 Sep 2011 13:53:57 -0400 Subject: [PATCH 2/4] update scripts --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index e791ced0..2fc59a85 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit e791ced0395245e30d37b5098a27bba5e818ecb7 +Subproject commit 2fc59a850bdc49e01f7a5e062b813df321ce5c78 From 62030bee5a22091b190861dd7124b0a3f6bb907f Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Thu, 22 Sep 2011 13:54:32 -0400 Subject: [PATCH 3/4] 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 --- yesod/test/run.sh | 99 +++---------------------------------- yesod/test/scaffold.sh | 4 +- yesod/test/scaffold_test.sh | 7 +++ 3 files changed, 15 insertions(+), 95 deletions(-) create mode 100644 yesod/test/scaffold_test.sh 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 ; } From 33e0f37400ead55119fe4e4d995add1ca2812bd1 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Thu, 22 Sep 2011 22:38:51 -0400 Subject: [PATCH 4/4] Add defaultRunner (not scaffold not updated) --- yesod-default/Yesod/Default/Main.hs | 38 +++++++++++++++++++++++++++++ yesod-default/yesod-default.cabal | 6 +++++ 2 files changed, 44 insertions(+) diff --git a/yesod-default/Yesod/Default/Main.hs b/yesod-default/Yesod/Default/Main.hs index f19e5d41..9cb36d8d 100644 --- a/yesod-default/Yesod/Default/Main.hs +++ b/yesod-default/Yesod/Default/Main.hs @@ -1,16 +1,25 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} module Yesod.Default.Main ( defaultMain + , defaultRunner , defaultDevelApp , defaultDevelAppWith ) where +import Yesod.Core import Yesod.Default.Config import Yesod.Logger (Logger, makeLogger, logString, logLazyText, flushLogger) import Network.Wai (Application) import Network.Wai.Handler.Warp (run) import Network.Wai.Middleware.Debug (debugHandle) +#ifndef WINDOWS +import qualified System.Posix.Signals as Signal +import Control.Concurrent (forkIO, killThread) +import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar) +#endif + -- | Run your app, taking environment and port settings from the -- commandline. -- @@ -31,6 +40,35 @@ defaultMain load withSite = do logger <- makeLogger withSite config logger $ run (appPort config) +-- | Run your application continously, listening for SIGINT and exiting +-- when recieved +-- +-- > withYourSite :: AppConfig DefaultEnv -> Logger -> (Application -> IO a) -> IO () +-- > withYourSite conf logger f = do +-- > Settings.withConnectionPool conf $ \p -> do +-- > runConnectionPool (runMigration yourMigration) p +-- > defaultRunner f $ YourSite conf logger p +-- +-- TODO: ifdef WINDOWS +-- +defaultRunner :: (YesodDispatch y y, Yesod y) + => (Application -> IO a) + -> y -- ^ your foundation type + -> IO () +defaultRunner f h = +#ifdef WINDOWS + toWaiApp h >>= f >> return () +#else + do + tid <- forkIO $ toWaiApp h >>= f >> return () + flag <- newEmptyMVar + _ <- Signal.installHandler Signal.sigINT (Signal.CatchOnce $ do + putStrLn "Caught an interrupt" + killThread tid + putMVar flag ()) Nothing + takeMVar flag +#endif + -- | Run your development app using the provided @'DefaultEnv'@ type -- -- > withDevelAppPort :: Dynamic diff --git a/yesod-default/yesod-default.cabal b/yesod-default/yesod-default.cabal index 8eea3d63..6e346480 100644 --- a/yesod-default/yesod-default.cabal +++ b/yesod-default/yesod-default.cabal @@ -14,6 +14,9 @@ description: Convenient wrappers for your the configuration and execution of your yesod application library + if os(windows) + cpp-options: -DWINDOWS + build-depends: base >= 4 && < 5 , yesod-core >= 0.9 && < 0.10 , cmdargs >= 0.8 && < 0.9 @@ -25,6 +28,9 @@ library , text >= 0.9 && < 1.0 , directory >= 1.0 && < 1.2 + if !os(windows) + build-depends: unix + exposed-modules: Yesod.Default.Config , Yesod.Default.Main , Yesod.Default.Util