hspec-discover 0.1.0.1 → 0.2.0
raw patch · 7 files changed
+5/−282 lines, 7 filesdep −basedep −directorydep −filepathdep ~hspec
Dependencies removed: base, directory, filepath, hspec-discover, hspec-shouldbe
Dependency ranges changed: hspec
Files
- example/Spec.hs +0/−1
- hspec-discover.cabal +5/−73
- integration-test/empty/Spec.hs +0/−1
- src/Main.hs +0/−8
- src/Run.hs +0/−161
- src/Test/Hspec/Discover.hs +0/−37
- test/Spec.hs +0/−1
− example/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
hspec-discover.cabal view
@@ -1,84 +1,16 @@ name: hspec-discover-version: 0.1.0.1+version: 0.2.0 license: MIT license-file: LICENSE-copyright: (c) 2012 Simon Hengel+copyright: (c) 2012-2013 Simon Hengel author: Simon Hengel <sol@typeful.net> maintainer: Simon Hengel <sol@typeful.net> build-type: Simple cabal-version: >= 1.8 category: Testing synopsis: Automatically discover and run Hspec tests-description: Documentation is here: <https://github.com/hspec/hspec/blob/master/hspec-discover/README.markdown>--source-repository head- type: git- location: https://github.com/hspec/hspec+description: This has been integrated into hspec. There is no need to use+ this package anymore! library- ghc-options:- -Wall- hs-source-dirs:- src- exposed-modules:- Test.Hspec.Discover- build-depends:- base >= 4 && <= 5- , hspec == 1.2.*--executable hspec-discover- ghc-options:- -Wall- hs-source-dirs:- src- main-is:- Main.hs- other-modules:- Run- build-depends:- base >= 4 && <= 5- , filepath- , directory--test-suite spec- type:- exitcode-stdio-1.0- ghc-options:- -Wall -Werror- hs-source-dirs:- src, test- main-is:- Spec.hs- build-depends:- base >= 4 && <= 5- , filepath- , directory- , hspec- , hspec-shouldbe--test-suite example- type:- exitcode-stdio-1.0- ghc-options:- -Wall -Werror- hs-source-dirs:- example- main-is:- Spec.hs- build-depends:- base >= 4 && <= 5- , hspec-shouldbe- , hspec-discover--test-suite integration-test-empty- type:- exitcode-stdio-1.0- ghc-options:- -Wall -Werror- hs-source-dirs:- integration-test/empty- main-is:- Spec.hs- build-depends:- base >= 4 && <= 5- , hspec-discover+ build-depends: hspec >= 1.3
− integration-test/empty/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
− src/Main.hs
@@ -1,8 +0,0 @@-module Main (main) where--import System.Environment--import Run (run)--main :: IO ()-main = getArgs >>= run
− src/Run.hs
@@ -1,161 +0,0 @@-{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, OverloadedStrings #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}--- | A preprocessor that finds and combines specs.-module Run where-import Control.Monad-import Control.Applicative-import Data.List-import Data.String-import Data.Function-import System.Environment-import System.Exit-import System.IO-import System.Directory-import System.FilePath hiding (combine)--instance IsString ShowS where- fromString = showString--run :: [String] -> IO ()-run args_ = case args_ of- src : _ : dst : args -> do- nested <- case args of- [] -> return False- ["--nested"] -> return True- _ -> exit- specs <- findSpecs src- writeFile dst (mkSpecModule src nested specs)- _ -> exit- where- exit = do- name <- getProgName- hPutStrLn stderr ("usage: " ++ name ++ " SRC CUR DST [--nested]")- exitFailure--mkSpecModule :: FilePath -> Bool -> [SpecNode] -> String-mkSpecModule src nested nodes =- ( "{-# LINE 1 " . shows src . " #-}"- . showString "module Main where\n"- . showString "import Test.Hspec.Discover\n"- . importList nodes- . showString "main :: IO ()\n"- . showString "main = hspec $ "- . format nodes- ) "\n"- where- format- | nested = formatSpecsNested- | otherwise = formatSpecs---- | Generate imports for a list of specs.-importList :: [SpecNode] -> ShowS-importList = go ""- where- go :: ShowS -> [SpecNode] -> ShowS- go current = foldr (.) "" . map (f current)- f current (SpecNode name inhabited children) = this . go (current . showString name . ".") children- where- this- | inhabited = "import qualified " . current . showString name . "Spec\n"- | otherwise = id---- | Combine a list of strings with (>>).-sequenceS :: [ShowS] -> ShowS-sequenceS = foldr (.) "" . intersperse " >> "---- | Convert a list of specs to code.-formatSpecs :: [SpecNode] -> ShowS-formatSpecs xs- | null xs = "return ()"- | otherwise = sequenceS (map formatSpec xs)---- | Convert a spec to code.-formatSpec :: SpecNode -> ShowS-formatSpec = sequenceS . go ""- where- go :: String -> SpecNode -> [ShowS]- go current (SpecNode name inhabited children) = addThis $ concatMap (go (current ++ name ++ ".")) children- where- addThis :: [ShowS] -> [ShowS]- addThis- | inhabited = ("describe " . shows (current ++ name) . " " . showString (current ++ name ++ "Spec.spec") :)- | otherwise = id---- | Convert a list of specs to code.------ Hierarchical modules are mapped to nested specs.-formatSpecsNested :: [SpecNode] -> ShowS-formatSpecsNested xs- | null xs = "return ()"- | otherwise = sequenceS (map formatSpecNested xs)---- | Convert a spec to code.------ Hierarchical modules are mapped to nested specs.-formatSpecNested :: SpecNode -> ShowS-formatSpecNested = go ""- where- go current (SpecNode name inhabited children) = "describe " . shows name . " (" . specs . ")"- where- specs :: ShowS- specs = (sequenceS . addThis . map (go (current . showString name . "."))) children- addThis- | inhabited = ((current . showString name . "Spec.spec") :)- | otherwise = id--data SpecNode = SpecNode String Bool [SpecNode]- deriving (Eq, Show)--specNodeName :: SpecNode -> String-specNodeName (SpecNode name _ _) = name--specNodeInhabited :: SpecNode -> Bool-specNodeInhabited (SpecNode _ inhabited _) = inhabited--specNodeChildren :: SpecNode -> [SpecNode]-specNodeChildren (SpecNode _ _ children) = children--getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])-getFilesAndDirectories dir = do- c <- filter (`notElem` ["..", "."]) <$> getDirectoryContents dir- dirs <- filterM (doesDirectoryExist . (dir </>)) c- files <- filterM (doesFileExist . (dir </>)) c- return (dirs, files)---- | Find specs relative to given source file.------ The source file itself is not considered.-findSpecs :: FilePath -> IO [SpecNode]-findSpecs src = do- let (dir, file) = splitFileName src- (dirs, files) <- getFilesAndDirectories dir- go dir (dirs, filter (/= file) files)- where- go :: FilePath -> ([FilePath], [FilePath]) -> IO [SpecNode]- go base (dirs, files) = do- nestedSpecs <- forM dirs $ \d -> do- let dir = base </> d- SpecNode d False <$> (getFilesAndDirectories dir >>= go dir)- (return . filterSpecs . combineSpecs) (specsFromFiles files ++ nestedSpecs)- where- specsFromFiles = map (\x -> SpecNode (stripSuffix x) True []) . filter (isSuffixOf suffix)- where- suffix = "Spec.hs"- stripSuffix = reverse . drop (length suffix) . reverse-- -- remove empty leafs- filterSpecs :: [SpecNode] -> [SpecNode]- filterSpecs = filter (\x -> specNodeInhabited x || (not . null . specNodeChildren) x)-- -- sort specs, and merge nodes with the same name- combineSpecs :: [SpecNode] -> [SpecNode]- combineSpecs = foldr f [] . sortBy (compare `on` specNodeName)- where- f x@(SpecNode n1 _ _) (y@(SpecNode n2 _ _):acc) | n1 == n2 = x `combine` y : acc- f x acc = x : acc-- x `combine` y = SpecNode name inhabited children- where- name = specNodeName x- inhabited = specNodeInhabited x || specNodeInhabited y- children = specNodeChildren x ++ specNodeChildren y
− src/Test/Hspec/Discover.hs
@@ -1,37 +0,0 @@-{-# OPTIONS_HADDOCK prune #-}--- |--- Say you have a driver module for your test suite.------ > module Main where--- >--- > import Test.Hspec.Monadic--- >--- > import qualified FooSpec--- > import qualified Foo.BarSpec--- > import qualified BazSpec--- >--- > main :: IO ()--- > main = hspec $ do--- > describe "Foo" FooSpec.spec--- > describe "Foo.Bar" Foo.BarSpec.spec--- > describe "Baz" BazSpec.spec------ Then you can replace it with the following.------ > {-# OPTIONS_GHC -F -pgmF hspec-discover #-}------ All files with a name that ends in @Spec.hs@ are include in the generated--- test suite. And it is assumed, that they export a @spec@ of type--- `Test.Hspec.Monadic.Specs`.------ Full documentation is here: <https://github.com/hspec/hspec/blob/master/hspec-discover/README.markdown>-module Test.Hspec.Discover (hspec, describe) where--import Test.Hspec.Monadic (Spec)-import qualified Test.Hspec.Monadic as Hspec--hspec :: Spec -> IO ()-hspec = Hspec.hspec--describe :: String -> Spec -> Spec-describe = Hspec.describe
− test/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}