hspec-core 2.4.2 → 2.4.3
raw patch · 6 files changed
+61/−32 lines, 6 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- hspec-core.cabal +1/−1
- src/Test/Hspec/Core/Compat.hs +1/−1
- src/Test/Hspec/Core/Config.hs +5/−2
- src/Test/Hspec/Core/Options.hs +24/−8
- test/Test/Hspec/Core/OptionsSpec.hs +26/−16
- test/Test/Hspec/Core/RunnerSpec.hs +4/−4
hspec-core.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: hspec-core-version: 2.4.2+version: 2.4.3 license: MIT license-file: LICENSE copyright: (c) 2011-2017 Simon Hengel,
src/Test/Hspec/Core/Compat.hs view
@@ -51,7 +51,7 @@ import Data.IORef import System.Environment -import Data.Typeable.Internal (tyConModule, tyConName)+import Data.Typeable (tyConModule, tyConName) import Control.Concurrent #if !MIN_VERSION_base(4,6,0)
src/Test/Hspec/Core/Config.hs view
@@ -11,7 +11,8 @@ #endif ) where -import Control.Applicative+import Prelude ()+ import Control.Exception import Control.Monad import Data.Maybe@@ -23,6 +24,7 @@ import qualified Test.QuickCheck as QC import Test.Hspec.Core.Util+import Test.Hspec.Core.Compat import Test.Hspec.Core.Options import Test.Hspec.Core.FailureReport import Test.Hspec.Core.QuickCheckUtil (mkGen)@@ -85,7 +87,8 @@ case ignore of True -> return [] False -> readConfigFiles- case parseOptions opts_ prog configFiles args of+ envVar <- fmap words <$> lookupEnv envVarName+ case parseOptions opts_ prog configFiles envVar args of Left (err, msg) -> exitWithMessage err msg Right opts -> do r <- if configRerun opts then readFailureReport opts else return Nothing
src/Test/Hspec/Core/Options.hs view
@@ -6,6 +6,7 @@ , parseOptions , ConfigFile , ignoreConfigFile+, envVarName ) where import Prelude ()@@ -20,9 +21,15 @@ import Test.Hspec.Core.Util import Test.Hspec.Core.Example (Params(..), defaultParams) import Data.Functor.Identity+import Data.Maybe type ConfigFile = (FilePath, [String]) +type EnvVar = [String]++envVarName :: String+envVarName = "HSPEC_OPTIONS"+ data Config = Config { configIgnoreConfigFile :: Bool , configDryRun :: Bool@@ -225,9 +232,11 @@ recognizedOptions :: [OptDescr (Result Maybe -> Result Maybe)] recognizedOptions = documentedOptions ++ undocumentedOptions -parseOptions :: Config -> String -> [ConfigFile] -> [String] -> Either (ExitCode, String) Config-parseOptions config prog configFiles args = do- foldM (parseFileOptions prog) config configFiles >>= parseCommandLineOptions prog args+parseOptions :: Config -> String -> [ConfigFile] -> Maybe EnvVar -> [String] -> Either (ExitCode, String) Config+parseOptions config prog configFiles envVar args = do+ foldM (parseFileOptions prog) config configFiles+ >>= parseEnvVarOptions prog envVar+ >>= parseCommandLineOptions prog args parseCommandLineOptions :: String -> [String] -> Config -> Either (ExitCode, String) Config parseCommandLineOptions prog args config = case parse recognizedOptions config args of@@ -238,21 +247,28 @@ failure err = Left (ExitFailure 1, prog ++ ": " ++ err ++ "\nTry `" ++ prog ++ " --help' for more information.\n") parseFileOptions :: String -> Config -> ConfigFile -> Either (ExitCode, String) Config-parseFileOptions prog config (name, args) = case parse configFileOptions config args of+parseFileOptions prog config (name, args) =+ parseOtherOptions prog ("in config file " ++ name) args config++parseEnvVarOptions :: String -> (Maybe EnvVar) -> Config -> Either (ExitCode, String) Config+parseEnvVarOptions prog args =+ parseOtherOptions prog ("from environment variable " ++ envVarName) (fromMaybe [] args)++parseOtherOptions :: String -> String -> [String] -> Config -> Either (ExitCode, String) Config+parseOtherOptions prog source args config = case parse configFileOptions config args of Right (Identity c) -> Right c Left err -> failure err where failure err = Left (ExitFailure 1, prog ++ ": " ++ message) where message = unlines $ case lines err of- [x] -> [x ++ " " ++ inFile]- xs -> xs ++ [inFile]- inFile = "in config file " ++ name+ [x] -> [x ++ " " ++ source]+ xs -> xs ++ [source] parse :: Monad m => [OptDescr (Result m -> Result m)] -> Config -> [String] -> Either String (m Config) parse options config args = case getOpt Permute options args of (opts, [], []) -> case foldl' (flip id) (Right $ return config) opts of- Left (InvalidArgument flag value) -> Left ("invalid argument `" ++ value ++ "' for `--" ++ flag ++ "'")+ Left (InvalidArgument name value) -> Left ("invalid argument `" ++ value ++ "' for `--" ++ name ++ "'") Right x -> Right x (_, _, err:_) -> Left (init err) (_, arg:_, _) -> Left ("unexpected argument `" ++ arg ++ "'")
test/Test/Hspec/Core/OptionsSpec.hs view
@@ -18,58 +18,58 @@ let parseOptions = Options.parseOptions defaultConfig "my-spec" it "rejects unexpected arguments" $ do- fromLeft (parseOptions [] ["foo"]) `shouldBe` (ExitFailure 1, "my-spec: unexpected argument `foo'\nTry `my-spec --help' for more information.\n")+ fromLeft (parseOptions [] Nothing ["foo"]) `shouldBe` (ExitFailure 1, "my-spec: unexpected argument `foo'\nTry `my-spec --help' for more information.\n") it "rejects unrecognized options" $ do- fromLeft (parseOptions [] ["--foo"]) `shouldBe` (ExitFailure 1, "my-spec: unrecognized option `--foo'\nTry `my-spec --help' for more information.\n")+ fromLeft (parseOptions [] Nothing ["--foo"]) `shouldBe` (ExitFailure 1, "my-spec: unrecognized option `--foo'\nTry `my-spec --help' for more information.\n") it "sets configColorMode to ColorAuto" $ do- configColorMode <$> parseOptions [] [] `shouldBe` Right ColorAuto+ configColorMode <$> parseOptions [] Nothing [] `shouldBe` Right ColorAuto context "with --no-color" $ do it "sets configColorMode to ColorNever" $ do- configColorMode <$> parseOptions [] ["--no-color"] `shouldBe` Right ColorNever+ configColorMode <$> parseOptions [] Nothing ["--no-color"] `shouldBe` Right ColorNever context "with --color" $ do it "sets configColorMode to ColorAlways" $ do- configColorMode <$> parseOptions [] ["--color"] `shouldBe` Right ColorAlways+ configColorMode <$> parseOptions [] Nothing ["--color"] `shouldBe` Right ColorAlways context "with --out" $ do it "sets configOutputFile" $ do- either (const Nothing) Just . configOutputFile <$> parseOptions [] ["--out", "foo"] `shouldBe` Right (Just "foo")+ either (const Nothing) Just . configOutputFile <$> parseOptions [] Nothing ["--out", "foo"] `shouldBe` Right (Just "foo") context "with --qc-max-success" $ do context "when given an invalid argument" $ do it "returns an error message" $ do- fromLeft (parseOptions [] ["--qc-max-success", "foo"]) `shouldBe` (ExitFailure 1, "my-spec: invalid argument `foo' for `--qc-max-success'\nTry `my-spec --help' for more information.\n")+ fromLeft (parseOptions [] Nothing ["--qc-max-success", "foo"]) `shouldBe` (ExitFailure 1, "my-spec: invalid argument `foo' for `--qc-max-success'\nTry `my-spec --help' for more information.\n") context "with --depth" $ do it "sets depth parameter for SmallCheck" $ do- configSmallCheckDepth <$> parseOptions [] ["--depth", "23"] `shouldBe` Right 23+ configSmallCheckDepth <$> parseOptions [] Nothing ["--depth", "23"] `shouldBe` Right 23 context "with --jobs" $ do it "sets number of concurrent jobs" $ do- configConcurrentJobs <$> parseOptions [] ["--jobs=23"] `shouldBe` Right (Just 23)+ configConcurrentJobs <$> parseOptions [] Nothing ["--jobs=23"] `shouldBe` Right (Just 23) it "rejects values < 1" $ do let msg = "my-spec: invalid argument `0' for `--jobs'\nTry `my-spec --help' for more information.\n"- void (parseOptions [] ["--jobs=0"]) `shouldBe` Left (ExitFailure 1, msg)+ void (parseOptions [] Nothing ["--jobs=0"]) `shouldBe` Left (ExitFailure 1, msg) context "when given a config file" $ do it "uses options from config file" $ do- configColorMode <$> parseOptions [("~/.hspec", ["--no-color"])] [] `shouldBe` Right ColorNever+ configColorMode <$> parseOptions [("~/.hspec", ["--no-color"])] Nothing [] `shouldBe` Right ColorNever it "gives command-line options precedence" $ do- configColorMode <$> parseOptions [("~/.hspec", ["--no-color"])] ["--color"] `shouldBe` Right ColorAlways+ configColorMode <$> parseOptions [("~/.hspec", ["--no-color"])] Nothing ["--color"] `shouldBe` Right ColorAlways it "rejects --help" $ do- fromLeft (parseOptions [("~/.hspec", ["--help"])] []) `shouldBe` (ExitFailure 1, "my-spec: unrecognized option `--help' in config file ~/.hspec\n")+ fromLeft (parseOptions [("~/.hspec", ["--help"])] Nothing []) `shouldBe` (ExitFailure 1, "my-spec: unrecognized option `--help' in config file ~/.hspec\n") it "rejects unrecognized options" $ do- fromLeft (parseOptions [("~/.hspec", ["--invalid"])] []) `shouldBe` (ExitFailure 1, "my-spec: unrecognized option `--invalid' in config file ~/.hspec\n")+ fromLeft (parseOptions [("~/.hspec", ["--invalid"])] Nothing []) `shouldBe` (ExitFailure 1, "my-spec: unrecognized option `--invalid' in config file ~/.hspec\n") it "rejects ambiguous options" $ do- fromLeft (parseOptions [("~/.hspec", ["--qc-max-s"])] []) `shouldBe` (ExitFailure 1,+ fromLeft (parseOptions [("~/.hspec", ["--qc-max-s"])] Nothing []) `shouldBe` (ExitFailure 1, unlines [ "my-spec: option `--qc-max-s' is ambiguous; could be one of:" , " -a N --qc-max-success=N maximum number of successful tests"@@ -81,7 +81,17 @@ context "when given multiple config files" $ do it "gives later config files precedence" $ do- configColorMode <$> parseOptions [("~/.hspec", ["--no-color"]), (".hspec", ["--color"])] [] `shouldBe` Right ColorAlways+ configColorMode <$> parseOptions [("~/.hspec", ["--no-color"]), (".hspec", ["--color"])] Nothing [] `shouldBe` Right ColorAlways++ context "when given an environment variable" $ do+ it "uses options from environment variable" $ do+ configColorMode <$> parseOptions [] (Just ["--no-color"]) [] `shouldBe` Right ColorNever++ it "gives command-line options precedence" $ do+ configColorMode <$> parseOptions [] (Just ["--no-color"]) ["--color"] `shouldBe` Right ColorAlways++ it "rejects unrecognized options" $ do+ fromLeft (parseOptions [] (Just ["--invalid"]) []) `shouldBe` (ExitFailure 1, "my-spec: unrecognized option `--invalid' from environment variable HSPEC_OPTIONS\n") describe "ignoreConfigFile" $ around_ (withEnvironment []) $ do context "by default" $ do
test/Test/Hspec/Core/RunnerSpec.hs view
@@ -103,9 +103,9 @@ r <- runPropFoo ["--seed", "42"] runPropFoo ["--rerun"] `shouldReturn` r - forM_ quickCheckOptions $ \(flag, accessor) -> do- it ("reuses same " ++ flag) $ do- [flag, "23"] `shouldUseArgs` ((== 23) . accessor)+ forM_ quickCheckOptions $ \(name, accessor) -> do+ it ("reuses same " ++ name) $ do+ [name, "23"] `shouldUseArgs` ((== 23) . accessor) ["--rerun"] `shouldUseArgs` ((== 23) . accessor) context "when no examples failed previously" $ do@@ -144,7 +144,7 @@ r `shouldBe` "WARNING: Could not read environment variable HSPEC_FAILURES; `--rerun' is ignored!\n" - it "does not leak command-line flags to examples" $ do+ it "does not leak command-line options to examples" $ do silence . withArgs ["--verbose"] $ do H.hspec $ do H.it "foobar" $ do