packages feed

tasty-discover 4.0.0 → 4.1.0

raw patch · 7 files changed

+55/−28 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Test.Tasty.Config: [tastyOptions] :: Config -> [String]
- Test.Tasty.Config: Config :: Maybe GlobPattern -> Maybe String -> Maybe String -> Maybe GlobPattern -> [FilePath] -> [Ingredient] -> Bool -> Bool -> Bool -> Config
+ Test.Tasty.Config: Config :: Maybe GlobPattern -> Maybe String -> Maybe String -> Maybe GlobPattern -> [FilePath] -> [Ingredient] -> [String] -> Bool -> Bool -> Bool -> Config

Files

CHANGELOG.md view
@@ -8,6 +8,16 @@ [Keep a Changelog]: http://keepachangelog.com/ [Semantic Versioning]: http://semver.org/ +# 4.1.0 [2017-09-26]++## Fixed+- Find tests recursively in test directory.++## Added+- Add ability to override tasty arguments (see pull request [#120]).++[#120]: https://github.com/lwm/tasty-discover/pull/120+ # 4.0.0 [2017-09-01]  ## Changed@@ -18,7 +28,7 @@ - `tasty-hedgehog` is now a supported test library.  ## Removed-- `unit_` prefixes have been removed.+- `case_` prefixes have been removed.  [#117]: https://github.com/lwm/tasty-discover/pull/117 
README.md view
@@ -139,6 +139,12 @@   - **--generated-module**: The name of the generated test module.   - **--ingredient**: Tasty ingredients to add to your test runner. +It is also possible to override tasty arguments with `-optF`:++``` bash+{-# OPTIONS_GHC -F -pgmF tasty-discover -optF --hide-successes #-}+```+ # Example Project  See the [testing for this package] for a fully configured example.
library/Test/Tasty/Config.hs view
@@ -18,7 +18,7 @@ import           Data.Maybe            (isJust) import           System.Console.GetOpt (ArgDescr (NoArg, ReqArg),                                         ArgOrder (Permute), OptDescr (Option),-                                        getOpt)+                                        getOpt')  -- | A tasty ingredient. type Ingredient = String@@ -34,6 +34,7 @@   , ignores             :: Maybe GlobPattern -- ^ Glob pattern for ignoring modules during test discovery.   , ignoredModules      :: [FilePath]        -- ^ <<<DEPRECATED>>>: Ignored modules by full name.   , tastyIngredients    :: [Ingredient]      -- ^ Tasty ingredients to use.+  , tastyOptions        :: [String]          -- ^ Options passed to tasty   , noModuleSuffix      :: Bool              -- ^ <<<DEPRECATED>>>: suffix and look in all modules.   , debug               :: Bool              -- ^ Debug the generated module.   , treeDisplay         :: Bool              -- ^ Tree display for the test results table.@@ -41,7 +42,7 @@  -- | The default configuration defaultConfig :: Config-defaultConfig = Config Nothing Nothing Nothing Nothing [] [] False False False+defaultConfig = Config Nothing Nothing Nothing Nothing [] [] [] False False False  -- | Deprecation message for old `--[no-]module-suffix` option. moduleSuffixDeprecationMessage :: String@@ -68,9 +69,9 @@  -- | Configuration options parser. parseConfig :: String -> [String] -> Either String Config-parseConfig prog args = case getOpt Permute options args of-    (opts, [], []) ->-      let config = foldl (flip id) defaultConfig opts in+parseConfig prog args = case getOpt' Permute options args of+    (opts, rest, rest', []) ->+      let config = foldl (flip id) defaultConfig { tastyOptions = rest ++ rest' } opts in         if noModuleSuffix config || isJust (moduleSuffix config) then           error moduleSuffixDeprecationMessage         else@@ -78,8 +79,7 @@           error ignoreModuleDeprecationMessage         else         Right config-    (_, _, err:_)  -> formatError err-    (_, arg:_, _)  -> formatError ("unexpected argument `" ++ arg ++ "`\n")+    (_, _, _, err:_)  -> formatError err   where     formatError err = Left (prog ++ ": " ++ err) 
library/Test/Tasty/Discover.hs view
@@ -12,10 +12,10 @@   ) where  import           Data.List            (dropWhileEnd, intercalate, isPrefixOf,-                                       nub)+                                       nub, stripPrefix) import qualified Data.Map.Strict      as M import           Data.Maybe           (fromMaybe)-import           System.FilePath      (takeDirectory, takeFileName, (</>))+import           System.FilePath      (pathSeparator, takeDirectory) import           System.FilePath.Glob (compile, globDir1, match) import           Test.Tasty.Config    (Config (..), GlobPattern) import           Test.Tasty.Generator (Generator (..), Test (..), generators,@@ -33,6 +33,7 @@       , "{-# LANGUAGE FlexibleInstances #-}\n"       , "module " ++ modname ++ " (main, ingredients, tests) where\n"       , "import Prelude\n"+      , "import qualified System.Environment as E\n"       , "import qualified Test.Tasty as T\n"       , "import qualified Test.Tasty.Ingredients as T\n"       , unlines $ map generatorImport generators'@@ -44,24 +45,26 @@       , "  pure $ T.testGroup \"" ++ src ++ "\" ["       , intercalate "," $ showTests config tests testNumVars       , "]\n"-      , concat-        [ "ingredients :: [T.Ingredient]\n"-        , "ingredients = " ++ ingredients is ++ "\n"-        , "main :: IO ()\n"-        , "main = tests >>= T.defaultMainWithIngredients ingredients\n"-        ]+      , "ingredients :: [T.Ingredient]\n"+      , "ingredients = " ++ ingredients is ++ "\n"+      , "main :: IO ()\n"+      , "main = do\n"+      , "  args <- E.getArgs\n"+      , "  E.withArgs (" ++ show (tastyOptions config) ++ " ++ args) $"+      , "    tests >>= T.defaultMainWithIngredients ingredients\n"       ]  -- | Match files by specified glob pattern. filesByModuleGlob :: FilePath -> Maybe GlobPattern -> IO [String] filesByModuleGlob directory globPattern = do-  (fmap takeFileName) <$> globDir1 pattern directory-  where pattern = compile (fromMaybe "*.hs*" globPattern)+  globDir1 pattern directory+  where pattern = compile ("**/" ++ fromMaybe "*.hs*" globPattern)  -- | Filter and remove files by specified glob pattern. ignoreByModuleGlob :: [FilePath] -> Maybe GlobPattern -> [FilePath]-ignoreByModuleGlob directories ignoreGlob = filter (not . match pattern) directories-  where pattern = compile (fromMaybe "" ignoreGlob)+ignoreByModuleGlob filePaths Nothing = filePaths+ignoreByModuleGlob filePaths (Just ignoreGlob) = filter (not . match pattern) filePaths+  where pattern = compile ("**/" ++ ignoreGlob)  -- | Discover the tests modules. findTests :: FilePath -> Config -> IO [Test]@@ -71,8 +74,10 @@   let filtered = ignoreByModuleGlob allModules (ignores config)   concat <$> traverse (extract directory) filtered   where-    extract directory file = do-      extractTests file <$> readFile (directory </> file)+    extract directory filePath = do+      extractTests (dropDirectory directory filePath) <$> readFile filePath+    dropDirectory directory filePath = fromMaybe filePath $+      stripPrefix (directory ++ [pathSeparator]) filePath  -- | Extract the test names from discovered modules. extractTests :: FilePath -> String -> [Test]
tasty-discover.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           tasty-discover-version:        4.0.0+version:        4.1.0 synopsis:       Test discovery for the tasty framework. description:    Automatic test discovery and runner for the tasty framework.                 Prefix your test case names and tasty-discover will discover, collect and run them. All popular test libraries are covered. Configure once and then just write your tests. Avoid forgetting to add test modules to your Cabal/Hpack files. Tasty ingredients are included along with various configuration options for different use cases. Please see the `README.md` below for how to get started.@@ -83,4 +83,5 @@       DiscoverTest       SubMod.FooBaz       SubMod.PropTest+      SubMod.SubSubMod.PropTest   default-language: Haskell2010
test/ConfigTest.hs view
@@ -17,10 +17,11 @@ spec_modules =   describe "Test discovery" $   it "Discovers tests" $ do-    let expectedTest = mkTest "PropTest" "prop_additionAssociative"-        config       = defaultConfig { modules = Just "*Test.hs" }+    let expectedTests = [ mkTest "PropTest.hs" "prop_additionAssociative",+                          mkTest "SubSubMod/PropTest.hs" "prop_additionCommutative" ]+        config        = defaultConfig { modules = Just "*Test.hs" }     discoveredTests <- findTests "test/SubMod/" config-    discoveredTests `shouldBe` [expectedTest]+    discoveredTests `shouldBe` expectedTests  spec_ignores :: Spec spec_ignores =@@ -50,7 +51,7 @@   tests <- findTests "test/SubMod/" defaultConfig   let testNumVars = map (('t' :) . show) [(0::Int)..]       trees = showTests defaultConfig tests testNumVars-  length trees @?= 3+  length trees @?= 4  unit_treeDisplay :: IO () unit_treeDisplay = do@@ -58,7 +59,7 @@   tests <- findTests "test/SubMod/" config   let testNumVars = map (('t' :) . show) [(0::Int)..]       trees = showTests config tests testNumVars-  length trees @?= 2+  length trees @?= 3  prop_mkModuleTree :: ModuleTree -> Property prop_mkModuleTree mtree =
+ test/SubMod/SubSubMod/PropTest.hs view
@@ -0,0 +1,4 @@+module SubMod.SubSubMod.PropTest where++prop_additionCommutative :: Int -> Int -> Bool+prop_additionCommutative a b = a + b == b + a