hcltest 0.3.6 → 0.3.7
raw patch · 7 files changed
+98/−80 lines, 7 filesdep ~basedep ~doctestdep ~eithersetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, doctest, either, filepath, free, lens, monad-control, optparse-applicative, tagged
API changes (from Hackage documentation)
Files
- .travis.yml +6/−2
- LICENSE +1/−1
- Setup.hs +47/−17
- hcltest.cabal +25/−33
- src/Test/HClTest/Monad.hs +4/−3
- src/Test/HClTest/Program.hs +1/−0
- tests/doctests.hsc +14/−24
.travis.yml view
@@ -1,7 +1,9 @@ env:- - GHCVER=7.4.2 CABALVER=1.16 - GHCVER=7.6.3 CABALVER=1.18- - GHCVER=7.8.2 CABALVER=1.20+ - GHCVER=7.8.3 CABALVER=1.18+ - GHCVER=7.8.4 CABALVER=1.18+ - GHCVER=7.10.1 CABALVER=1.22+ - GHCVER=head CABALVER=1.22 before_install: - sudo add-apt-repository -y ppa:hvr/ghc@@ -19,4 +21,6 @@ - hlint src matrix:+ allow_failures:+ - env: GHCVER=head CABALVER=1.22 fast_finish: true
LICENSE view
@@ -1,4 +1,4 @@-Copyright 2013 Benno Fünfstück+Copyright 2013-2015 Benno Fünfstück All rights reserved.
Setup.hs view
@@ -1,43 +1,73 @@-#!/usr/bin/runhaskell {-# OPTIONS_GHC -Wall #-} module Main (main) where +import Data.IORef import Data.List ( nub ) import Data.Version ( showVersion ) import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )-import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )+import Distribution.PackageDescription ( PackageDescription(), TestSuite(..), hsSourceDirs, exeModules, libBuildInfo, buildInfo, libModules, modulePath, exeName) import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )-import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose ) import Distribution.Simple.BuildPaths ( autogenModulesDir )-import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )-import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )+import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, withExeLBI, ComponentLocalBuildInfo(), LocalBuildInfo(), componentPackageDeps )+import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag, buildDistPref, defaultDistPref, fromFlagOrDefault )+import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )+import Distribution.Text (disp) import Distribution.Verbosity ( Verbosity )-import System.FilePath ( (</>) )+import System.Directory ( canonicalizePath )+import System.FilePath ( (</>), dropExtension )+import Text.PrettyPrint (render) main :: IO () main = defaultMainWithHooks simpleUserHooks { buildHook = \pkg lbi hooks flags -> do- generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi+ generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi flags buildHook simpleUserHooks pkg lbi hooks flags } -generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()-generateBuildModule verbosity pkg lbi = do+-- Very ad-hoc implementation of difference lists+singletonDL :: a -> [a] -> [a]+singletonDL = (:)++emptyDL :: [a] -> [a]+emptyDL = id++appendDL :: ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]+appendDL x y = x . y++generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> BuildFlags -> IO ()+generateBuildModule verbosity pkg lbi flags = do let dir = autogenModulesDir lbi createDirectoryIfMissingVerbose verbosity True dir- withLibLBI pkg lbi $ \_ libcfg -> do- withTestLBI pkg lbi $ \suite suitecfg -> do- rewriteFile (map fixchar $ dir </> "Build_" ++ testName suite ++ ".hs") $ unlines- [ "module Build_" ++ testName suite ++ " where"- , "deps :: [String]"- , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))- ]+ withTestLBI pkg lbi $ \suite suitelbi -> do+ srcDirs <- mapM canonicalizePath $ hsSourceDirs $ testBuildInfo suite+ distDir <- canonicalizePath $ fromFlagOrDefault defaultDistPref $ buildDistPref flags++ doctestVar <- newIORef emptyDL+ withLibLBI pkg lbi $ \lib liblbi ->+ let mods = map (render . disp) $ libModules lib in+ modifyIORef doctestVar $ appendDL . singletonDL $ doctestTarget "libary" mods (libBuildInfo lib) liblbi suitelbi+ withExeLBI pkg lbi $ \exe exelbi ->+ let mods = dropExtension (modulePath exe) : map (render . disp) (exeModules exe) in+ modifyIORef doctestVar $ appendDL . singletonDL $ doctestTarget ("executable " ++ exeName exe) mods (buildInfo exe) exelbi suitelbi+ doctestTargets <- fmap ($ []) $ readIORef doctestVar++ rewriteFile (dir </> "Build_" ++ map fixchar (testName suite) ++ ".hs") $ unlines+ [ "module Build_" ++ map fixchar (testName suite) ++ " where"+ , "getDistDir :: FilePath"+ , "getDistDir = " ++ show distDir+ , "getSrcDirs :: [FilePath]"+ , "getSrcDirs = " ++ show srcDirs+ , "doctestTargets :: [(String, [String], [FilePath], [String])]"+ , "doctestTargets = " ++ show doctestTargets+ ]+ where formatdeps = map (formatone . snd) formatone p = case packageName p of PackageName n -> n ++ "-" ++ showVersion (packageVersion p)+ doctestTarget name mods targetbi targetlbi suitelbi = (name, mods, hsSourceDirs targetbi, formatdeps $ testDeps targetlbi suitelbi) fixchar '-' = '_'- fixchar a = a+ fixchar c = c testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)] testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
hcltest.cabal view
@@ -1,10 +1,10 @@ name: hcltest-version: 0.3.6+version: 0.3.7 cabal-version: >=1.10 build-type: Custom license: BSD3 license-file: LICENSE-copyright: Copyright (C) 2013 Benno Fünfstück+copyright: Copyright (C) 2013-2015 Benno Fünfstück maintainer: Benno Fünfstück <benno.fuenfstueck@gmail.com> stability: experimental homepage: http://github.com/bennofs/hcltest/@@ -26,58 +26,50 @@ location: git://github.com/bennofs/hcltest.git library+ exposed-modules:+ Test.HClTest+ Test.HClTest.Program+ Test.HClTest.Monad+ Test.HClTest.Setup+ Test.HClTest.Trace+ Test.Tasty.HClTest build-depends:- base >=4.5.1.0 && <4.8,+ base >=4.5.1.0 && <4.9, bytestring >=0.9.2.1 && <0.11, text >=0.11.2.3 && <1.3,- free >=4.5 && <4.10,+ free >=4.5 && <4.13, process >=1.1.0.1 && <1.3,- filepath >=1.3.0.0 && <1.4,+ filepath >=1.3.0.0 && <1.5, transformers >=0.3.0.0 && <0.5,- either >=4.1.1 && <4.4,+ either >=4.1.1 && <4.5, directory >=1.1.0.2 && <1.3, dlist >=0.6.0.1 && <0.8, temporary >=1.2.0.1 && <1.3, mtl >=2.1.2 && <2.3,- lens >=4.0.7 && <4.5,+ lens >=4.0.7 && <4.12, tasty >=0.8.0.2 && <0.11,- tagged >=0.7.1 && <0.8,+ tagged >=0.7.1 && <0.9, mmorph >=1.0.2 && <1.1, random-shuffle >=0.0.4 && <0.1, split >=0.2.1.1 && <0.3, stm ==2.4.*,- optparse-applicative >=0.7.0.2,- monad-control >=0.3.2.3 && <0.4,+ optparse-applicative >=0.7.0.2 && <0.12,+ monad-control >=1 && <1.1, transformers-base >=0.4.1 && <0.5- exposed-modules:- Test.HClTest- Test.HClTest.Program- Test.HClTest.Monad- Test.HClTest.Setup- Test.HClTest.Trace- Test.Tasty.HClTest- exposed: True- buildable: True default-language: Haskell2010+ other-extensions: TemplateHaskell hs-source-dirs: src ghc-options: -Wall- other-extensions: TemplateHaskell- + test-suite doctests- build-depends:- base >=4.5.1.0 && <4.8,- directory >=1.1.0.2 && <1.3,- doctest >=0.9.10.2 && <0.10,- filepath >=1.3.0.0 && <1.4- - if impl(ghc <7.6.1)- buildable: True- ghc-options: -Werror type: exitcode-stdio-1.0 main-is: doctests.hs- buildable: True+ build-depends:+ base >=4.5.1.0 && <4.9,+ directory >=1.1.0.2 && <1.3,+ doctest >=0.9.10.2 && <0.11,+ filepath >=1.3.0.0 && <1.5 default-language: Haskell2010+ other-extensions: TemplateHaskell hs-source-dirs: tests ghc-options: -Wall -threaded- other-extensions: TemplateHaskell-
src/Test/HClTest/Monad.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-} -- | This module defines the basic test type, HClTest, which is a monad. It also provides functions -- for creating and running tests. module Test.HClTest.Monad@@ -51,9 +52,9 @@ liftBase = liftIO instance MonadBaseControl IO (HClTest w) where- data StM (HClTest w) a = HClTestSt { unHClTestSt :: StM (ReaderT Config (MaybeT (WriterT (DL.DList w) IO))) a }- liftBaseWith f = HClTest $ liftBaseWith (\k -> f (fmap HClTestSt . k . unHClTest ))- restoreM = HClTest . restoreM . unHClTestSt+ type StM (HClTest w) a = StM (ReaderT Config (MaybeT (WriterT (DL.DList w) IO))) a+ liftBaseWith f = HClTest $ liftBaseWith (\k -> f (k . unHClTest ))+ restoreM = HClTest . restoreM -- | Run a HClTest. The first argument is the timeout for waiting for output -- of the process, in milliseconds. The second argument is the test case.
src/Test/HClTest/Program.hs view
@@ -30,6 +30,7 @@ import System.Timeout import Test.HClTest.Monad import Test.HClTest.Trace+import Prelude -- | A output stream. data Stream = Stdout | Stderr deriving Show
tests/doctests.hsc view
@@ -13,12 +13,8 @@ ----------------------------------------------------------------------------- module Main where -import Build_doctests (deps)-import Control.Applicative+import Build_doctests (doctestTargets) import Control.Monad-import Data.List-import System.Directory-import System.FilePath import Test.DocTest ##ifdef mingw32_HOST_ARCH@@ -50,22 +46,16 @@ ##endif main :: IO ()-main = withUnicode $ getSources >>= \sources -> doctest $- "-isrc"- : "-idist/build/autogen"- : "-optP-include"- : "-optPdist/build/autogen/cabal_macros.h"- : "-hide-all-packages"- : map ("-package="++) deps ++ sources--getSources :: IO [FilePath]-getSources = filter (isSuffixOf ".hs") <$> go "src"- where- go dir = do- (dirs, files) <- getFilesAndDirectories dir- (files ++) . concat <$> mapM go dirs--getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])-getFilesAndDirectories dir = do- c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir- (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c+main = withUnicode $ do+ forM_ doctestTargets $ \(name, mods, dirs, dep) -> do+ putStrLn $ ":: Running doctests for " ++ name+ doctest $+ "-idist/build/autogen"+ : "-idist/build"+ : "-optP-include"+ : "-optPdist/build/autogen/cabal_macros.h"+ : "-package-dbdist/package.conf.inplace"+ : "-hide-all-packages"+ : map ("-package="++) dep+ ++ map ("-i"++) dirs+ ++ mods