doctest-discover-configurator (empty) → 0.1.0.6
raw patch · 7 files changed
+171/−0 lines, 7 filesdep +basedep +bytestringdep +configuratorsetup-changed
Dependencies added: base, bytestring, configurator, directory, doctest, doctest-discover-configurator, filepath
Files
- LICENSE +24/−0
- Setup.hs +2/−0
- doctest-discover-configurator.cabal +42/−0
- src/Config.hs +17/−0
- src/Main.hs +24/−0
- src/Runner.hs +61/−0
- test/Doctest-Main.hs +1/−0
+ LICENSE view
@@ -0,0 +1,24 @@+This is free and unencumbered software released into the public domain.++Anyone is free to copy, modify, publish, use, compile, sell, or+distribute this software, either in source code form or as a compiled+binary, for any purpose, commercial or non-commercial, and by any+means.++In jurisdictions that recognize copyright laws, the author or authors+of this software dedicate any and all copyright interest in the+software to the public domain. We make this dedication for the benefit+of the public at large and to the detriment of our heirs and+successors. We intend this dedication to be an overt act of+relinquishment in perpetuity of all present and future rights to this+software under copyright law.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.++For more information, please refer to <http://unlicense.org/>
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ doctest-discover-configurator.cabal view
@@ -0,0 +1,42 @@+name: doctest-discover-configurator+version: 0.1.0.6+synopsis: Easy way to run doctests via cabal (no aeson dependency, uses configurator instead)+description: doctest-discover provides an easy way to run doctests via cabal+license: PublicDomain+license-file: LICENSE+homepage: http://github.com/relrod/doctest-discover-noaeson+author: Karun Ramakrishnan, Ricky Elrod+maintainer: ricky@elrod.me+category: Testing+build-type: Simple+cabal-version: >=1.10++library+ default-language: Haskell2010+ build-depends: base >= 4 && < 5+ , bytestring >= 0.10 && < 0.11+ , configurator >= 0.3 && < 0.4+ , directory >= 1.1 && < 1.3+ , doctest >= 0.9+ , filepath >= 1.2 && < 1.4+ HS-Source-Dirs: src++executable doctest-discover+ default-language: Haskell2010+ build-depends: base >= 4 && < 5+ , bytestring >= 0.10 && < 0.11+ , configurator >= 0.3 && < 0.4+ , directory >= 1.1 && < 1.3+ , doctest >= 0.9+ , filepath >= 1.2 && < 1.4+ main-is: Main.hs + other-modules: Runner, Config+ HS-Source-Dirs: src++test-suite doctests+ default-language: Haskell2010+ type: exitcode-stdio-1.0+ ghc-options: -threaded+ main-is: Doctest-Main.hs+ build-depends: base >4 && <5, doctest-discover-configurator, doctest+ HS-Source-Dirs: test
+ src/Config.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE OverloadedStrings #-}++module Config where++import qualified Data.Configurator as Cfg++data Config = Config {+ ignore :: Maybe [String],+ sourceFolders :: Maybe [String]+} deriving (Show)++config :: String -> IO Config+config file = do+ config' <- Cfg.load [Cfg.Optional file]+ ignore' <- Cfg.lookup config' "ignore"+ sourceFolders' <- Cfg.lookup config' "sourceFolders"+ return $ Config ignore' sourceFolders'
+ src/Main.hs view
@@ -0,0 +1,24 @@+module Main where++import System.Environment+import Control.Applicative+import Runner+import Config+import System.Directory+import System.FilePath++main :: IO ()+main = do+ (_ : _ : dst : args) <- getArgs+ customConfiguration <- case args of+ (configFile : _) -> Just <$> config configFile+ _ -> return Nothing+ let sources = case customConfiguration of+ Just (Config _ (Just sourceFolders')) -> sourceFolders'+ _ -> ["src"]+ files <- mapM getAbsDirectoryContents sources+ let testDriverFileContents = driver (concat files) customConfiguration+ writeFile dst testDriverFileContents++getAbsDirectoryContents :: FilePath -> IO [FilePath]+getAbsDirectoryContents dir = getDirectoryContents dir >>= mapM (canonicalizePath . (dir </>))
+ src/Runner.hs view
@@ -0,0 +1,61 @@+module Runner (+ driver+) where++import Data.List+import Config++-- | Generates doctest driver+--+-- >>> let expected = unlines ["module Main where", "import Test.DocTest", "main :: IO ()", "main = doctest [\"-i/src\",\"foo.hs\",\"bar.hs\"]"]+-- >>> let actual = driver ["foo.hs", "bar.hs", "baz.qux"] Nothing+-- >>> expected == actual+-- True+--+driver :: [FilePath] -> Maybe Config -> String+driver files config' = unlines ["module Main where", "import Test.DocTest", "main :: IO ()", "main = doctest " ++ show (generateConfig files config')]++-- | Generates doctest configuration+--+-- >>> generateConfig ["foo.hs", "bar.hs", "baz.qux"] Nothing+-- ["-i/src","foo.hs","bar.hs"]+--+-- >>> let config = Just (Config (Just ["bar.hs"]) Nothing)+-- >>> generateConfig ["foo.hs", "bar.hs", "baz.qux"] config+-- ["-i/src","foo.hs"]+--+-- >>> let config = Just (Config Nothing (Just ["qux"]))+-- >>> generateConfig ["foo.hs", "bar.hs", "baz.qux"] config+-- ["-i/qux","foo.hs","bar.hs"]+--+-- >>> let config = Just (Config (Just ["bar.hs"]) (Just ["qux"]))+-- >>> generateConfig ["foo.hs", "bar.hs", "baz.qux"] config+-- ["-i/qux","foo.hs"]+--+generateConfig :: [FilePath] -> Maybe Config -> [String]+generateConfig files (Just (Config Nothing (Just sourceFolders'))) = ((++) (map ("-i/"++) sourceFolders') . notCurrentAndParent . filterHaskellSources) files+generateConfig files (Just (Config (Just ignoreList) Nothing)) = ((:) "-i/src" . filter (`notElem` ignoreList) . notCurrentAndParent . filterHaskellSources) files+generateConfig files (Just (Config (Just ignoreList) (Just sourceFolders'))) = ((++) (map ("-i/"++) sourceFolders') . filter (`notElem` ignoreList) . notCurrentAndParent . filterHaskellSources) files+generateConfig files _ = ((:) "-i/src" . notCurrentAndParent . filterHaskellSources) files++-- | Filters out current and parent directories+--+-- >>> notCurrentAndParent ["wat", ".", "..", "wat"]+-- ["wat","wat"]++notCurrentAndParent :: [FilePath] -> [FilePath]+notCurrentAndParent = filter (`notElem` [".", ".."])++-- | Filters out haskell source files+--+-- >>> filterHaskellSources []+-- []+--+-- >>> filterHaskellSources ["foo.hs", "bar.lhs", "foo.txt", "baz.qux"]+-- ["foo.hs","bar.lhs"]+--+filterHaskellSources :: [FilePath] -> [FilePath]+filterHaskellSources = filter isHaskellSource++isHaskellSource :: FilePath -> Bool+isHaskellSource file = isSuffixOf ".hs" file || isSuffixOf ".lhs" file
+ test/Doctest-Main.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF doctest-discover #-}