tasty-th 0.1.4 → 0.1.5
raw patch · 3 files changed
+21/−4 lines, 3 filesdep +haskell-src-exts
Dependencies added: haskell-src-exts
Files
- BSD3.txt +1/−1
- src/Test/Tasty/TH.hs +18/−1
- tasty-th.cabal +2/−2
BSD3.txt view
@@ -1,5 +1,5 @@ Copyright (c) 2010, Oscar Finnsson-Copyright (c) 2013-2016, Benno Fünfstück+Copyright (c) 2013-2017, Benno Fünfstück All rights reserved. Redistribution and use in source and binary forms, with or without
src/Test/Tasty/TH.hs view
@@ -29,6 +29,9 @@ import Control.Monad (join) import Control.Applicative+import Language.Haskell.Exts (parseFileContents)+import Language.Haskell.Exts.Parser (ParseResult(..))+import qualified Language.Haskell.Exts.Syntax as S import Language.Haskell.TH import Data.List import Data.Maybe@@ -78,9 +81,23 @@ extractTestFunctions :: FilePath -> IO [String] extractTestFunctions filePath = do file <- readFile filePath- let functions = map fst . concatMap lex . lines $ file+ -- we first try to parse the file using haskell-src-exts+ -- if that fails, we fallback to lexing each line, which is less+ -- accurate but is more reliable (haskell-src-exts sometimes struggles+ -- with less-common GHC extensions).+ let functions = fromMaybe (lexed file) (parsed file) filtered pat = filter (pat `isPrefixOf`) functions return . nub $ concat [filtered "prop_", filtered "case_", filtered "test_"]+ where+ lexed = map fst . concatMap lex . lines+ + parsed file = case parseFileContents file of+ ParseOk parsedModule -> Just (declarations parsedModule)+ ParseFailed _ _ -> Nothing+ declarations (S.Module _ _ _ _ decls) = mapMaybe testFunName decls+ declarations _ = []+ testFunName (S.PatBind _ (S.PVar _ (S.Ident _ n)) _ _) = Just n+ testFunName _ = Nothing -- | Extract the name of the current module. locationModule :: ExpQ
tasty-th.cabal view
@@ -1,5 +1,5 @@ name: tasty-th-version: 0.1.4+version: 0.1.5 cabal-version: >= 1.6 build-type: Simple license: BSD3@@ -14,7 +14,7 @@ library exposed-modules: Test.Tasty.TH- build-depends: base >= 4 && < 5, tasty, template-haskell+ build-depends: base >= 4 && < 5, haskell-src-exts >= 1.18.0, tasty, template-haskell hs-source-dirs: src other-extensions: TemplateHaskell