packages feed

tasty-auto 0.1.0.2 → 0.2.0.0

raw patch · 5 files changed

+57/−27 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Test.Tasty.Auto: showTestDriver :: [String] -> FilePath -> [Test] -> ShowS
+ Test.Tasty.Auto: showTestDriver :: String -> [String] -> FilePath -> [Test] -> ShowS

Files

README.md view
@@ -93,15 +93,22 @@   pure $ map (\s -> testCase s $ pure ()) inputs ``` -## Support for additional ingredients+## Configuration options  You can add tasty ingredients with the `-optF` option:  ``` haskell -- test/test.hs-{-# OPTIONS_GHC -F -pgmF tasty-auto -optF Test.Tasty.Runners.Html.htmlRunner -optF Test.Tasty.Runners.AntXML.antXMLRunner #-}+{-# OPTIONS_GHC -F -pgmF tasty-auto -optF --ingredient=Test.Tasty.Runners.Html.htmlRunner -optF --ingredient=Test.Tasty.Runners.AntXML.antXMLRunner #-} ``` +It is possible to configure the name of the generated module, if you want to import the module somewhere.++``` haskell+-- test/AutoTests.hs+{-# OPTIONS_GHC -F -pgmF tasty-auto -optF --module=AutoTests #-}+```+ ## Generated code  The generated code of the preprocessor looks like this:@@ -109,9 +116,10 @@ ``` haskell {-# LINE 1 "test/test.hs" #-} {-# LANGUAGE FlexibleInstances #-}-module Main where+module Main (main, ingredients, tests) where import Prelude import qualified Test.Tasty as T+import qualified Test.Tasty.Ingredients as T import qualified Test.Tasty.HUnit as HU import qualified Test.Tasty.QuickCheck as QC import qualified Test.Tasty.SmallCheck as SC@@ -131,8 +139,8 @@ instance TestGroup [T.TestTree]      where testGroup n a = pure $ T.testGroup n a instance TestGroup (IO T.TestTree)   where testGroup _ a = a instance TestGroup (IO [T.TestTree]) where testGroup n a = T.testGroup n <$> a-main :: IO ()-main = do+tests :: IO T.TestTree+tests = do   t0 <- testCase "List comparison with different length" CaseTest.case_List_comparison_with_different_length   t1 <- pure $ SC.testProperty "sort reverse" SCPropTest.scprop_sort_reverse   t2 <- testGroup "Addition" TreeTest.test_Addition@@ -142,5 +150,9 @@   t6 <- pure $ QC.testProperty "Addition is commutative" PropTest.prop_Addition_is_commutative   t7 <- HS.testSpec "Prelude" TestSpec.spec_Prelude   t8 <- pure $ QC.testProperty "Addition is associative" SubMod.PropTest.prop_Addition_is_associative-  T.defaultMain $ T.testGroup "test/test.hs" [t0,t1,t2,t3,t4,t5,t6,t7,t8]+  pure $ T.testGroup "test/test.hs" [t0,t1,t2,t3,t4,t5,t6,t7,t8]+ingredients :: [T.Ingredient]+ingredients = T.defaultIngredients+main :: IO ()+main = tests >>= T.defaultMainWithIngredients ingredients ```
src/Test/Tasty/Auto.hs view
@@ -1,7 +1,7 @@ module Test.Tasty.Auto (findTests, showTestDriver) where  import Data.Function (on)-import Data.List (find, isPrefixOf, isSuffixOf, nub, intersperse, groupBy, sortOn)+import Data.List (find, isPrefixOf, isSuffixOf, nub, intersperse, groupBy, sortOn, dropWhileEnd) import Data.Maybe (fromJust) import System.Directory (getDirectoryContents, doesDirectoryExist) import Data.Traversable (for)@@ -79,29 +79,33 @@ foldEndo = appEndo . fold . fmap Endo  ingredientImport :: String -> String-ingredientImport = reverse . tail . dropWhile (/= '.') . reverse+ingredientImport = init . dropWhileEnd (/= '.') -mainFunction :: [String] -> ShowS-mainFunction [] = str "  T.defaultMain"-mainFunction ingredients = str "  T.defaultMainWithIngredients ("-  . foldEndo (map (\i -> str i . (':':)) ingredients) . str "T.defaultIngredients)"+ingredients :: [String] -> ShowS+ingredients is = foldEndo (map (\i -> str i . (':':)) is) . str "T.defaultIngredients" -showTestDriver :: [String] -> FilePath -> [Test] -> ShowS-showTestDriver ingredients src ts = let gs = getGenerators ts; vars = map (str . ('t':) . show) [(0::Int)..] in+showTestDriver :: String -> [String] -> FilePath -> [Test] -> ShowS+showTestDriver modname is src ts =+  let gs = getGenerators ts; vars = map (str . ('t':) . show) [(0::Int)..] in     str "{-# LINE 1 " . shows src . str " #-}\n\         \{-# LANGUAGE FlexibleInstances #-}\n\-        \module Main where\n\+        \module " . str modname . str " (main, ingredients, tests) where\n\         \import Prelude\n\-        \import qualified Test.Tasty as T\n"+        \import qualified Test.Tasty as T\n\+        \import qualified Test.Tasty.Ingredients as T\n"   . foldEndo (map genImport gs)-  . showImports (map ingredientImport ingredients ++ map testModule ts)+  . showImports (map ingredientImport is ++ map testModule ts)   . foldEndo (map genClass gs)-  . str "main :: IO ()\n\-        \main = do\n"+  . str "tests :: IO T.TestTree\n\+        \tests = do\n"   . foldEndo (zipWith showSetup ts vars)-  . mainFunction ingredients . str " $ T.testGroup " . shows src . str " ["+  . str "  pure $ T.testGroup " . shows src . str " ["   . foldEndo (intersperse (',':) $ zipWith (curry snd) ts vars)   . str "]\n"+  . str "ingredients :: [T.Ingredient]\n\+        \ingredients = " . ingredients is . str "\n\+        \main :: IO ()\n\+        \main = tests >>= T.defaultMainWithIngredients ingredients\n"  filesBySuffix :: FilePath -> [String] -> IO [FilePath] filesBySuffix dir suffixes = do
tasty-auto.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           tasty-auto-version:        0.1.0.2+version:        0.2.0.0 synopsis:       Auto discovery for Tasty with support for ingredients and test tree generation description:    Auto discovery for Tasty with support for ingredients and test tree generation category:       Testing
tasty-auto.hs view
@@ -1,15 +1,29 @@-import System.Exit (exitFailure)+import Control.Monad (when)+import Data.List (foldl')+import System.Console.GetOpt (getOpt, usageInfo, ArgDescr(..), ArgOrder(..), OptDescr(..)) import System.Environment (getArgs)+import System.Exit (exitFailure) import System.IO (hPutStrLn, stderr) import Test.Tasty.Auto +options :: [OptDescr ((String, [String], Bool) -> (String, [String], Bool))]+options =+  [ Option [] ["module"]     (ReqArg (\x (_, b, c) -> (x, b, c))        "MODULE")     "Qualified module name"+  , Option [] ["ingredient"] (ReqArg (\x (a, b, c) -> (a, b ++ [x], c)) "INGREDIENT") "Qualified ingredient name"+  , Option [] ["debug"]      (NoArg  (\   (a, b, _) -> (a, b, True)))                 "Debug output"+  ]+ main :: IO () main = do   args <- getArgs   case args of-    src : _ : dst : ingredients -> do-      tests <- findTests src-      writeFile dst $ showTestDriver ingredients src tests ""+    src : _ : dst : optargs+      | (opts, [], []) <- getOpt Permute options optargs -> do+          tests <- findTests src+          let output = showTestDriver modname ingredients src tests ""+              (modname, ingredients, debug) = foldl' (flip id) ("Main", [], False) opts+          when debug $ hPutStrLn stderr output+          writeFile dst output     _ -> do-      hPutStrLn stderr "tasty-auto: Expected source and destination arguments"+      hPutStrLn stderr $ usageInfo "Usage: tasty-auto src _ dst [OPTION...]" options       exitFailure
test/test.hs view
@@ -1,1 +1,1 @@-{-# OPTIONS_GHC -F -pgmF tasty-auto #-}+{-# OPTIONS_GHC -F -pgmF tasty-auto -optF --debug #-}