packages feed

hspec-golden 0.1.0.0 → 0.1.0.1

raw patch · 4 files changed

+58/−64 lines, 4 filesdep +optparse-applicativedep −simple-get-optPVP ok

version bump matches the API change (PVP)

Dependencies added: optparse-applicative

Dependencies removed: simple-get-opt

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for hspec-golden +## 0.1.0.1+#### Add+* CLI changed to work with optparse-applicative.+ ## 0.1.0.0 #### Add * CLI to update `actual` files to `golden`
README.md view
@@ -71,21 +71,23 @@ The CLI is called `hgold`:  ```-$ hgold+$ hgold -h -Parameters:-  DIR    The testing directory where you're dumping your results (default: .golden/)+Update your golden files -Flags:-  -u[DIR]  --update[=DIR]  Replaces `golden` files with `actual` files-  -v       --version       Displays the version of hgold-  -h       --help          Displays help information+Usage: hgold [-u|--update [DIR]] [-v|--version]++Available options:+  -u,--update [DIR]        The testing directory where you're dumping your+                           results. (default: ".golden")+  -v,--version             Show version+  -h,--help                Show this help text ```  Update the golden tests under `.golden` directory:  ```-$ hgold -u+$ hgold ```  Update the golden tests under `.myGoldenTest` directory:
app/Main.hs view
@@ -1,56 +1,43 @@-{-# LANGUAGE RecordWildCards #-}- module Main where -import           Control.Monad (forM_, when)-import           Data.Version (showVersion)-import           Paths_hspec_golden (version)-import           SimpleGetOpt-import           System.Directory (doesFileExist, listDirectory, renameFile)-import qualified Test.Hspec.Golden as G---- CLI Parameters-data Params =-  Params-    { version_     :: Bool-    , showHelp     :: Bool-    , updateDir    :: FilePath-    , shouldUpdate :: Bool-    } deriving Show+import           Control.Monad         (forM_, when)+import           Data.Version          (showVersion)+import           Paths_hspec_golden    (version)+import           Options.Applicative+import           Data.Monoid ((<>))+import           System.Directory      (doesFileExist, listDirectory,+                                        renameFile)+import qualified Test.Hspec.Golden     as G  defaultDirGoldenTest :: FilePath defaultDirGoldenTest = G.directory (G.defaultGolden "" "") -opts :: OptSpec Params-opts =-  OptSpec-    { progDefaults = Params False True defaultDirGoldenTest False-    , progOptions =-      [ Option ['u'] ["update"] "Replaces `golden` files with `actual` files"-        $ OptArg "DIR" $ \maybeDir ->-          case maybeDir of-            Nothing -> \s ->-              Right s-                { shouldUpdate = True-                , updateDir = defaultDirGoldenTest-                , showHelp = False-                }-            Just dir -> \s ->-              Right s-                { shouldUpdate = True-                , updateDir = dir-                , showHelp = False-                }-      , Option ['v'] ["version"] "Displays the version of hgold"-        $ NoArg $ \s -> Right s { version_ = True, showHelp = False }-      , Option ['h'] ["help"] "Displays help information"-        $ NoArg $ \s -> Right s-      ]-    , progParamDocs = [("DIR", "The testing directory where you're dumping your results (default: .golden/)")]-    , progParams = const Right-    }+-- CLI Params --- Update files+data Params =+    Params+      { updateDir    :: FilePath +   --   , shouldUpdate :: Bool+      } deriving Show+  +params :: Parser Params+params = Params +      <$> strOption+          (long "update"+          <> short 'u'+          <> metavar "[DIR]"+          <> value defaultDirGoldenTest+          <> showDefault+          <> help "The testing directory where you're dumping your results.")++versionOpt :: Parser (a->a)+versionOpt = infoOption (showVersion version) +              (long "version"+              <> short 'v'  +              <> help "Show version")+            ++--Update Files updateGolden :: FilePath -> IO () updateGolden dir = do   putStrLn "Replacing golden with actual..."@@ -68,11 +55,12 @@        putStrLn $ "  Replacing file: " ++ goldenFilePath ++ " with: " ++ actualFilePath        renameFile actualFilePath goldenFilePath) --- MAIN +-- Main+ main :: IO ()-main = do-  Params {..} <- getOpts opts-  when showHelp (dumpUsage opts)-  when version_ (putStrLn $ showVersion version)-  when shouldUpdate (updateGolden updateDir)+main = updateGolden =<< execParser opts+  where++  opts = info ((updateDir <$> params) <**> versionOpt <**> helper)+        ( fullDesc <> header "Update your golden files" )
hspec-golden.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.30.0.+-- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: 83cc81bf5ff29892ea3a331b29c4837fba7d68c839fa614144362ac7699e4d04+-- hash: 47827519449632063e1d3d47aaedfb8a42618dfbcf2406caefab51c360611a22  name:           hspec-golden-version:        0.1.0.0+version:        0.1.0.1 synopsis:       Golden tests for hspec description:    Please see the README on GitHub at <https://github.com/stackbuilders/hspec-golden#README> category:       Testing@@ -51,7 +51,7 @@       base >=4.6 && <5     , directory >=1.2.5.0     , hspec-golden-    , simple-get-opt+    , optparse-applicative   default-language: Haskell2010  test-suite hspec-golden-test