hspec 1.8.2 → 1.8.3
raw patch · 10 files changed
+34/−31 lines, 10 files
Files
- hspec.cabal +1/−1
- src/Test/Hspec/Compat.hs +9/−1
- src/Test/Hspec/Core/Type.hs +1/−0
- src/Test/Hspec/FailureReport.hs +3/−2
- src/Test/Hspec/Options.hs +1/−0
- src/Test/Hspec/Runner.hs +7/−3
- src/Test/Hspec/Util.hs +0/−12
- test/Test/Hspec/CompatSpec.hs +10/−0
- test/Test/Hspec/RunnerSpec.hs +2/−2
- test/Test/Hspec/UtilSpec.hs +0/−10
hspec.cabal view
@@ -1,5 +1,5 @@ name: hspec-version: 1.8.2+version: 1.8.3 license: MIT license-file: LICENSE copyright: (c) 2011-2014 Simon Hengel,
src/Test/Hspec/Compat.hs view
@@ -3,6 +3,7 @@ showType , showFullType , readMaybe+, lookupEnv , module Data.IORef #if !MIN_VERSION_base(4,6,0) , modifyIORef'@@ -12,6 +13,7 @@ import Data.Typeable (Typeable, typeOf, typeRepTyCon) import Text.Read import Data.IORef+import System.Environment #if MIN_VERSION_base(4,4,0) import Data.Typeable.Internal (tyConModule, tyConName)@@ -19,7 +21,6 @@ #if !MIN_VERSION_base(4,6,0) import qualified Text.ParserCombinators.ReadP as P-import Prelude #endif #if !MIN_VERSION_base(4,6,0)@@ -51,6 +52,13 @@ readMaybe s = case readEither s of Left _ -> Nothing Right a -> Just a++-- | Return the value of the environment variable @var@, or @Nothing@ if+-- there is no such value.+--+-- For POSIX users, this is equivalent to 'System.Posix.Env.getEnv'.+lookupEnv :: String -> IO (Maybe String)+lookupEnv k = lookup k `fmap` getEnvironment #endif showType :: Typeable a => a -> String
src/Test/Hspec/Core/Type.hs view
@@ -27,6 +27,7 @@ import Data.List (isPrefixOf) import Data.Maybe (fromMaybe) +import Test.Hspec.Compat import Test.Hspec.Util import Test.Hspec.Expectations import Test.HUnit.Lang (HUnitFailure(..))
src/Test/Hspec/FailureReport.hs view
@@ -6,7 +6,8 @@ import System.IO import System.SetEnv-import Test.Hspec.Util (Path, safeTry, readMaybe, getEnv)+import Test.Hspec.Compat+import Test.Hspec.Util (Path, safeTry) data FailureReport = FailureReport { failureReportSeed :: Integer@@ -27,7 +28,7 @@ readFailureReport :: IO (Maybe FailureReport) readFailureReport = do- mx <- getEnv "HSPEC_FAILURES"+ mx <- lookupEnv "HSPEC_FAILURES" case mx >>= readMaybe of Nothing -> do hPutStrLn stderr "WARNING: Could not read environment variable HSPEC_FAILURES; `--rerun' is ignored!"
src/Test/Hspec/Options.hs view
@@ -13,6 +13,7 @@ import System.Console.GetOpt import Test.Hspec.Formatters +import Test.Hspec.Compat import Test.Hspec.Util -- for Monad (Either e) when base < 4.3
src/Test/Hspec/Runner.hs view
@@ -23,7 +23,7 @@ import Data.Monoid import Data.Maybe import System.IO-import System.Environment+import System.Environment (getProgName, getArgs, withArgs) import System.Exit import qualified Control.Exception as E @@ -32,7 +32,8 @@ import System.Random (newStdGen) import Control.Monad.IO.Class (liftIO) -import Test.Hspec.Util+import Test.Hspec.Compat (lookupEnv)+import Test.Hspec.Util (Path, stdGenToInteger) import Test.Hspec.Core.Type import Test.Hspec.Config import Test.Hspec.Formatters@@ -139,7 +140,7 @@ doesUseColor :: Handle -> Config -> IO Bool doesUseColor h c = case configColorMode c of- ColorAuto -> hIsTerminalDevice h+ ColorAuto -> (&&) <$> hIsTerminalDevice h <*> (not <$> isDumb) ColorNever -> return False ColorAlways -> return True @@ -147,6 +148,9 @@ withHandle c action = case configHandle c of Left h -> action h Right path -> withFile path WriteMode action++isDumb :: IO Bool+isDumb = maybe False (== "dumb") <$> lookupEnv "TERM" -- | Summary of a test run. data Summary = Summary {
src/Test/Hspec/Util.hs view
@@ -5,8 +5,6 @@ , Path , filterPredicate , formatRequirement-, readMaybe-, getEnv , strip , stdGenToInteger , stdGenFromInteger@@ -14,11 +12,9 @@ import Data.Int (Int32) import Data.List-import Data.Maybe import Data.Char (isSpace) import Control.Applicative import qualified Control.Exception as E-import qualified System.Environment as Environment import System.Random (StdGen) -- | Create a more readable display of a quantity of something.@@ -76,14 +72,6 @@ join xs = case xs of [x] -> x ++ " " ys -> concatMap (++ ", ") ys---- NOTE: base-4.6.0.0 provides a function with that name and type. For--- compatibility with earlier versions, we define our own version here.-readMaybe :: Read a => String -> Maybe a-readMaybe = fmap fst . listToMaybe . reads--getEnv :: String -> IO (Maybe String)-getEnv key = either (const Nothing) Just <$> safeTry (Environment.getEnv key) -- ensure that lines are not longer then given `n`, insert line breaks at word -- boundaries
test/Test/Hspec/CompatSpec.hs view
@@ -2,6 +2,7 @@ module Test.Hspec.CompatSpec (main, spec) where import Helper+import System.SetEnv import Test.Hspec.Compat import Data.Typeable@@ -21,3 +22,12 @@ describe "showFullType (currently unused)" $ do it "shows fully qualified name of type" $ do showFullType SomeType `shouldBe` "Test.Hspec.CompatSpec.SomeType"++ describe "lookupEnv" $ do+ it "returns value of specified environment variable" $ do+ setEnv "FOO" "bar"+ lookupEnv "FOO" `shouldReturn` Just "bar"++ it "returns Nothing if specified environment variable is not set" $ do+ unsetEnv "FOO"+ lookupEnv "FOO" `shouldReturn` Nothing
test/Test/Hspec/RunnerSpec.hs view
@@ -8,7 +8,7 @@ import qualified Control.Exception as E import Mock import System.SetEnv-import Test.Hspec.Util (getEnv)+import Test.Hspec.Compat import Test.Hspec.FailureReport (FailureReport(..)) import qualified Test.Hspec as H@@ -59,7 +59,7 @@ H.it "example 2" False H.describe "baz" $ do H.it "example 3" False- getEnv "HSPEC_FAILURES" `shouldReturn` (Just . show) FailureReport {+ lookupEnv "HSPEC_FAILURES" `shouldReturn` (Just . show) FailureReport { failureReportSeed = 23 , failureReportMaxSuccess = 100 , failureReportMaxSize = 100
test/Test/Hspec/UtilSpec.hs view
@@ -5,7 +5,6 @@ import Data.Int (Int32) import System.Random (StdGen) import qualified Control.Exception as E-import System.SetEnv import Test.Hspec.Util @@ -91,15 +90,6 @@ it "properly handles context after a subject that consists of several components" $ do formatRequirement (["Data", "List", "reverse", "when applied twice"], "reverses a list") `shouldBe` "Data.List.reverse, when applied twice, reverses a list"-- describe "getEnv" $ do- it "returns value of specified environment variable" $ do- setEnv "FOO" "bar"- getEnv "FOO" `shouldReturn` Just "bar"-- it "returns Nothing if specified environment variable is not set" $ do- unsetEnv "FOO"- getEnv "FOO" `shouldReturn` Nothing describe "stdGenToInteger" $ do it "is inverse to stdGenFromInteger" $ property $