test-lib 0.1.0.0 → 0.2
raw patch · 3 files changed
+82/−23 lines, 3 filesdep +test-libdep ~basedep ~simple-get-optnew-component:exe:test-runnerPVP ok
version bump matches the API change (PVP)
Dependencies added: test-lib
Dependency ranges changed: base, simple-get-opt
API changes (from Hackage documentation)
+ TestLib: Options :: String -> [String] -> Bool -> FilePath -> [FilePath] -> Maybe String -> Bool -> [String] -> [String] -> Maybe Config -> Options
+ TestLib: [optBinFlags] :: Options -> [String]
+ TestLib: [optBinary] :: Options -> String
+ TestLib: [optCfg] :: Options -> Maybe Config
+ TestLib: [optDiffTool] :: Options -> Maybe String
+ TestLib: [optHelp] :: Options -> Bool
+ TestLib: [optIgnoreExpected] :: Options -> Bool
+ TestLib: [optOther] :: Options -> [String]
+ TestLib: [optResultDir] :: Options -> FilePath
+ TestLib: [optTestFileExts] :: Options -> [String]
+ TestLib: [optTests] :: Options -> [FilePath]
+ TestLib: data Options
+ TestLib: main :: IO ()
+ TestLib: mainWithOpts :: Options -> IO ()
Files
- exe/Main.hs +9/−0
- src/TestLib.hs +53/−13
- test-lib.cabal +20/−10
+ exe/Main.hs view
@@ -0,0 +1,9 @@+module Main(main) where++import qualified TestLib++main :: IO ()+main = TestLib.main+++
src/TestLib.hs view
@@ -1,4 +1,4 @@-module TestLib (Config(..), mainWith) where+module TestLib (Config(..), mainWith, mainWithOpts, main, Options(..)) where import SimpleGetOpt import Control.Monad (foldM,when)@@ -6,7 +6,7 @@ , createDirectoryIfMissing,canonicalizePath ) import System.Environment (withArgs) import System.FilePath((</>),(<.>),splitFileName,splitDirectories,takeFileName- , isRelative, pathSeparator )+ , isRelative, pathSeparator, takeExtension ) import System.Process ( createProcess,CreateProcess(..), StdStream(..) , proc, waitForProcess, readProcessWithExitCode )@@ -34,14 +34,25 @@ -- ^ Examine a file name to determine if it is a test. } +main :: IO ()+main =+ do opts <- getOpts options+ mainWithOpts opts+ -- | Define a @main@ function for an executable. mainWith :: Config -> IO () mainWith cfg =- do let optSpec = options cfg- opts <- getOpts optSpec+ do opts0 <- getOpts options+ let opts = opts0 { optCfg = Just cfg }+ mainWithOpts $ case optBinary opts of+ "" -> opts { optBinary = cfgDefaultBinary cfg }+ _ -> opts - when (optHelp opts) $- do dumpUsage optSpec+-- | Run with the given options+mainWithOpts :: Options -> IO ()+mainWithOpts opts =+ do when (optHelp opts) $+ do dumpUsage options exitSuccess -- Normalize paths@@ -57,6 +68,9 @@ withArgs (optOther opts') (defaultMain (generateTests opts' testFiles)) +++ -- Command Line Options -------------------------------------------------------- data Options = Options@@ -67,20 +81,25 @@ , optTests :: [FilePath] , optDiffTool :: Maybe String , optIgnoreExpected :: Bool- , optCfg :: Config+ , optTestFileExts :: [String]+ , optBinFlags :: [String]+ -- ^ Add this flags to the binary, followed by the test file+ , optCfg :: Maybe Config } -options :: Config -> OptSpec Options-options cfg = OptSpec- { progDefaults = Options { optBinary = cfgDefaultBinary cfg+options :: OptSpec Options+options = OptSpec+ { progDefaults = Options { optBinary = "" , optOther = [] , optHelp = False , optResultDir = "output" , optTests = [] , optDiffTool = Nothing+ , optBinFlags = []+ , optTestFileExts = [] , optIgnoreExpected = False- , optCfg = cfg+ , optCfg = Nothing } , progOptions =@@ -88,6 +107,10 @@ "the binary executable to use" $ ReqArg "PATH" $ \s o -> Right o { optBinary = s } + , Option "F" ["flag"]+ "add a flag to the test binary"+ $ ReqArg "STRING" $ \s o -> Right o { optBinFlags = optBinFlags o ++[s]}+ , Option "r" ["result-dir"] "the result directory for test runs" $ ReqArg "PATH" $ \s o -> Right o { optResultDir = s }@@ -104,6 +127,15 @@ "ignore expected failures" $ NoArg $ \o -> Right o { optIgnoreExpected = True } + , Option "" ["ext"]+ "files with this extension are tests"+ $ ReqArg "STRING" $ \s o ->+ let e = case s of+ '.' : _ -> s+ _ -> '.' : s+ in Right o { optTestFileExts = e : optTestFileExts o }++ , Option "h" ["help"] "display this message" $ NoArg $ \o -> Right o { optHelp = True }@@ -202,7 +234,9 @@ runBinary :: Options -> Handle -> FilePath -> String -> IO () runBinary opts hout path file = do let bin = optBinary opts- args = cfgBinOpts (optCfg opts) file+ args = case optCfg opts of+ Just x -> optBinFlags opts ++ cfgBinOpts x file+ Nothing -> optBinFlags opts ++ [file] (_, _, _, ph) <- createProcess (proc bin args) { cwd = Just path , std_out = UseHandle hout@@ -265,7 +299,13 @@ '.' : _ -> True _ -> False - isTestFile f = cfgIsTestCase (optCfg opts) (takeFileName f)+ isTestFile f = case optCfg opts of+ Nothing -> byExt+ Just cfg -> byExt || cfgIsTestCase cfg file+ where+ file = takeFileName f+ byExt = takeExtension file `elem` optTestFileExts opts+
test-lib.cabal view
@@ -1,5 +1,5 @@ name: test-lib-version: 0.1.0.0+version: 0.2 synopsis: A library to make a quick test-runner script. description: This library makes it easy to define an executable, which can find and run a bunch of tests for a binary.@@ -15,15 +15,25 @@ library hs-source-dirs: src exposed-modules: TestLib- build-depends: base >=4.12 && <4.13,- directory >=1.3 && <1.4,- filepath >=1.4 && <1.5,- process >=1.6 && <1.7,- containers >=0.6 && <0.7,- HUnit,- test-framework,- test-framework-hunit,- simple-get-opt+ build-depends: base >=4.9 && <4.13,+ directory >=1.3 && <1.4,+ filepath >=1.4 && <1.5,+ process >=1.4 && <1.7,+ containers >=0.5 && <0.7,+ HUnit >= 1.3.0 && < 1.7,+ simple-get-opt >= 0.2.0 && < 0.3,+ test-framework >= 0.8.0 && < 0.9,+ test-framework-hunit >= 0.3.0 && < 0.4 + ghc-options: -Wall default-language: Haskell2010++executable test-runner+ hs-source-dirs: exe+ main-is: Main.hs+ build-depends: base, simple-get-opt, test-lib+ ghc-options: -Wall+ default-language: Haskell2010++