hspec 1.8.1.1 → 1.8.2
raw patch · 15 files changed
+54/−131 lines, 15 filesdep ~QuickCheckdep ~basedep ~transformers
Dependency ranges changed: QuickCheck, base, transformers
Files
- LICENSE +1/−1
- hspec-discover/example/Spec.hs +0/−1
- hspec-discover/integration-test/empty/Spec.hs +0/−1
- hspec-discover/integration-test/with-formatter-empty/Spec.hs +0/−1
- hspec-discover/integration-test/with-formatter/FooSpec.hs +0/−12
- hspec-discover/integration-test/with-formatter/Spec.hs +0/−1
- hspec-discover/integration-test/with-io-formatter/FooSpec.hs +0/−12
- hspec-discover/integration-test/with-io-formatter/Formatter.hs +0/−13
- hspec-discover/integration-test/with-io-formatter/Spec.hs +0/−1
- hspec-discover/src/Config.hs +13/−3
- hspec-discover/src/Run.hs +16/−3
- hspec-discover/test/ConfigSpec.hs +12/−2
- hspec.cabal +2/−79
- src/Test/Hspec.hs +3/−1
- test/Test/HspecSpec.hs +7/−0
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2011-2013 Simon Hengel <sol@typeful.net>+Copyright (c) 2011-2014 Simon Hengel <sol@typeful.net> Copyright (c) 2011-2012 Trystan Spangler <trystan.s@comcast.net> Copyright (c) 2011-2011 Greg Weber <greg@gregweber.info>
− hspec-discover/example/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
− hspec-discover/integration-test/empty/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
− hspec-discover/integration-test/with-formatter-empty/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --formatter=Test.Hspec.Formatters.progress #-}
− hspec-discover/integration-test/with-formatter/FooSpec.hs
@@ -1,12 +0,0 @@-module FooSpec (main, spec) where--import Test.Hspec--main :: IO ()-main = hspec spec--spec :: Spec-spec = do- describe "reverse" $ do- it "reverses a list" $ do- reverse [1 :: Int, 2, 3] `shouldBe` [3, 2, 1]
− hspec-discover/integration-test/with-formatter/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --formatter=Test.Hspec.Formatters.progress #-}
− hspec-discover/integration-test/with-io-formatter/FooSpec.hs
@@ -1,12 +0,0 @@-module FooSpec (main, spec) where--import Test.Hspec--main :: IO ()-main = hspec spec--spec :: Spec-spec = do- describe "reverse" $ do- it "reverses a list" $ do- reverse [1 :: Int, 2, 3] `shouldBe` [3, 2, 1]
− hspec-discover/integration-test/with-io-formatter/Formatter.hs
@@ -1,13 +0,0 @@-module Formatter (count) where--import Data.IORef-import Control.Monad.IO.Class-import Test.Hspec.Formatters--count :: IO Formatter-count = do- ref <- newIORef (0 :: Int)- return silent {- exampleSucceeded = \_ -> liftIO (modifyIORef ref succ)- , footerFormatter = liftIO (readIORef ref) >>= writeLine . show- }
− hspec-discover/integration-test/with-io-formatter/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --formatter=Formatter.count #-}
hspec-discover/src/Config.hs view
@@ -5,28 +5,38 @@ , usage ) where +import Data.Maybe import System.Console.GetOpt data Config = Config { configNested :: Bool , configFormatter :: Maybe String+, configNoMain :: Bool } deriving (Eq, Show) defaultConfig :: Config-defaultConfig = Config False Nothing+defaultConfig = Config False Nothing False options :: [OptDescr (Config -> Config)] options = [ Option [] ["nested"] (NoArg $ \c -> c {configNested = True}) "" , Option [] ["formatter"] (ReqArg (\s c -> c {configFormatter = Just s}) "FORMATTER") ""+ , Option [] ["no-main"] (NoArg $ \c -> c {configNoMain = True}) "" ] usage :: String -> String-usage prog = "\nUsage: " ++ prog ++ " SRC CUR DST [--formatter=FORMATTER]\n"+usage prog = "\nUsage: " ++ prog ++ " SRC CUR DST [--formatter=FORMATTER] [--no-main]\n" parseConfig :: String -> [String] -> Either String Config parseConfig prog args = case getOpt Permute options args of- (opts, [], []) -> Right (foldl (flip id) defaultConfig opts)+ (opts, [], []) -> let+ c = (foldl (flip id) defaultConfig opts)+ in+ if (configNoMain c && isJust (configFormatter c))+ then+ formatError "option `--formatter=<fmt>' does not make sense with `--no-main'\n"+ else+ Right c (_, _, err:_) -> formatError err (_, arg:_, _) -> formatError ("unexpected argument `" ++ arg ++ "'\n") where
hspec-discover/src/Run.hs view
@@ -15,6 +15,7 @@ import Control.Monad import Control.Applicative import Data.List+import Data.Char import Data.Maybe import Data.String import System.Environment@@ -49,7 +50,7 @@ mkSpecModule :: FilePath -> Config -> [Spec] -> String mkSpecModule src c nodes = ( "{-# LINE 1 " . shows src . " #-}"- . showString "module Main where\n"+ . showString ("module " ++ module_ ++" where\n") . importList nodes . maybe driver (driverWithFormatter (null nodes)) (configFormatter c) . formatSpecs nodes@@ -57,8 +58,20 @@ where driver = showString "import Test.Hspec\n"- . showString "main :: IO ()\n"- . showString "main = hspec $ "+ . case configNoMain c of+ False ->+ showString "main :: IO ()\n"+ . showString "main = hspec $ "+ True ->+ showString "spec :: Spec\n"+ . showString "spec = "+ module_ = if configNoMain c then pathToModule src else "Main"+ pathToModule f = let+ fileName = last $ splitDirectories f+ m:ms = takeWhile (/='.') fileName+ in+ toUpper m:ms+ driverWithFormatter :: Bool -> String -> ShowS driverWithFormatter isEmpty f =
hspec-discover/test/ConfigSpec.hs view
@@ -18,18 +18,28 @@ it "recognizes --formatter" $ do parse ["--formatter", "someFormatter"] `shouldBe` Right (defaultConfig {configFormatter = Just "someFormatter"}) + it "recognizes --no-main" $ do+ parse ["--no-main"] `shouldBe` Right (defaultConfig {configNoMain = True})+ it "returns error message on unrecognized option" $ do parse ["--foo"] `shouldBe` (Left . unlines) [ "hspec-discover: unrecognized option `--foo'" , ""- , "Usage: hspec-discover SRC CUR DST [--formatter=FORMATTER]"+ , "Usage: hspec-discover SRC CUR DST [--formatter=FORMATTER] [--no-main]" ] it "returns error message on unexpected argument" $ do parse ["foo"] `shouldBe` (Left . unlines) [ "hspec-discover: unexpected argument `foo'" , ""- , "Usage: hspec-discover SRC CUR DST [--formatter=FORMATTER]"+ , "Usage: hspec-discover SRC CUR DST [--formatter=FORMATTER] [--no-main]"+ ]++ it "returns error message on --formatter=<fmt> with --no-main" $ do+ parse ["--no-main", "--formatter=foo"] `shouldBe` (Left . unlines) [+ "hspec-discover: option `--formatter=<fmt>' does not make sense with `--no-main'"+ , ""+ , "Usage: hspec-discover SRC CUR DST [--formatter=FORMATTER] [--no-main]" ] context "when option is given multiple times" $ do
hspec.cabal view
@@ -1,8 +1,8 @@ name: hspec-version: 1.8.1.1+version: 1.8.2 license: MIT license-file: LICENSE-copyright: (c) 2011-2013 Simon Hengel,+copyright: (c) 2011-2014 Simon Hengel, (c) 2011-2012 Trystan Spangler, (c) 2011 Greg Weber maintainer: Simon Hengel <sol@typeful.net>@@ -172,80 +172,3 @@ , filepath , directory , hspec-meta--test-suite hspec-discover-example- buildable: False- type:- exitcode-stdio-1.0- ghc-options:- -Wall -Werror- hs-source-dirs:- hspec-discover/example- main-is:- Spec.hs- build-depends:- base == 4.*- , hspec- , QuickCheck--test-suite hspec-discover-integration-test-empty- buildable: False- type:- exitcode-stdio-1.0- ghc-options:- -Wall -Werror- hs-source-dirs:- hspec-discover/integration-test/empty- main-is:- Spec.hs- build-depends:- base == 4.*- , hspec--test-suite hspec-discover-integration-test-with-formatter- buildable: False- type:- exitcode-stdio-1.0- ghc-options:- -Wall -Werror- hs-source-dirs:- hspec-discover/integration-test/with-formatter- main-is:- Spec.hs- other-modules:- FooSpec- build-depends:- base == 4.*- , hspec--test-suite hspec-discover-integration-test-with-io-formatter- buildable: False- type:- exitcode-stdio-1.0- ghc-options:- -Wall -Werror- hs-source-dirs:- hspec-discover/integration-test/with-io-formatter- main-is:- Spec.hs- other-modules:- FooSpec- Formatter- build-depends:- base == 4.*- , hspec- , transformers--test-suite hspec-discover-integration-test-with-formatter-empty- buildable: False- type:- exitcode-stdio-1.0- ghc-options:- -Wall -Werror- hs-source-dirs:- hspec-discover/integration-test/with-formatter-empty- main-is:- Spec.hs- build-depends:- base == 4.*- , hspec
src/Test/Hspec.hs view
@@ -30,6 +30,8 @@ , hspec ) where +import Control.Exception (finally)+ import Test.Hspec.Core.Type hiding (describe, it) import Test.Hspec.Runner import Test.Hspec.HUnit ()@@ -84,7 +86,7 @@ -- | Run a custom action after every spec item. after :: IO () -> Spec -> Spec-after action = around (>> action)+after action = around (`finally` action) -- | Run a custom action before and/or after every spec item. around :: (IO () -> IO ()) -> Spec -> Spec
test/Test/HspecSpec.hs view
@@ -119,6 +119,13 @@ mockCounter mock `shouldReturn` 1 mockCounter mock `shouldReturn` 2 + it "guarantees that action is run" $ do+ mock <- newMock+ silence . ignoreExitCode $ H.hspec $ H.after (mockAction mock) $ do+ H.it "foo" $ do+ ioError $ userError "foo" :: IO ()+ mockCounter mock `shouldReturn` 1+ describe "around" $ do it "wraps each spec item with an action" $ do ref <- newIORef (0 :: Int)