packages feed

hpc-coveralls 0.9.0 → 1.0.0

raw patch · 9 files changed

+121/−29 lines, 9 filesdep +Cabaldep +transformersdep ~aesonPVP ok

version bump matches the API change (PVP)

Dependencies added: Cabal, transformers

Dependency ranges changed: aeson

API changes (from Hackage documentation)

- Trace.Hpc.Coveralls.Types: instance Data CoverageMode
- Trace.Hpc.Coveralls.Types: instance Default CoverageMode
- Trace.Hpc.Coveralls.Types: instance Eq CoverageMode
- Trace.Hpc.Coveralls.Types: instance Eq Hit
- Trace.Hpc.Coveralls.Types: instance Show CoverageMode
- Trace.Hpc.Coveralls.Types: instance Show Hit
- Trace.Hpc.Coveralls.Types: instance Typeable CoverageMode
+ Trace.Hpc.Coveralls.Types: instance Data.Data.Data Trace.Hpc.Coveralls.Types.CoverageMode
+ Trace.Hpc.Coveralls.Types: instance GHC.Classes.Eq Trace.Hpc.Coveralls.Types.CoverageMode
+ Trace.Hpc.Coveralls.Types: instance GHC.Classes.Eq Trace.Hpc.Coveralls.Types.Hit
+ Trace.Hpc.Coveralls.Types: instance GHC.Show.Show Trace.Hpc.Coveralls.Types.CoverageMode
+ Trace.Hpc.Coveralls.Types: instance GHC.Show.Show Trace.Hpc.Coveralls.Types.Hit
+ Trace.Hpc.Coveralls.Types: instance System.Console.CmdArgs.Default.Default Trace.Hpc.Coveralls.Types.CoverageMode
- Trace.Hpc.Coveralls: generateCoverallsFromTix :: String -> String -> GitInfo -> Config -> IO Value
+ Trace.Hpc.Coveralls: generateCoverallsFromTix :: String -> String -> GitInfo -> Config -> Maybe String -> IO Value

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+[1.0.0](https://github.com/guillaume-nargeot/hpc-coveralls/issues?q=milestone:v1.0.0+is:closed)+* Add support for cabal 1.22 / ghc 7.10 (issue #44)+* Add --service-name option to support Travis-pro (issue #49)+ [0.9.0](https://github.com/guillaume-nargeot/hpc-coveralls/issues?q=milestone:v0.9.0+is:closed) ----- * Fix instructions and target hpc data directory for Cabal 1.22 / GHC 7.10 (issue #38)
README.md view
@@ -1,7 +1,7 @@ hpc-coveralls ============= -[![Build Status](http://img.shields.io/travis/guillaume-nargeot/hpc-coveralls/master.svg)](https://travis-ci.org/guillaume-nargeot/hpc-coveralls) [![Gitter chat](http://img.shields.io/badge/gitter-chat--room-brightgreen.svg)](https://gitter.im/guillaume-nargeot/hpc-coveralls) [![BSD3 License](http://img.shields.io/badge/license-BSD3-brightgreen.svg)](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29) [![Version on Hackage](https://img.shields.io/hackage/v/hpc-coveralls.svg)](http://hackage.haskell.org/package/hpc-coveralls) [![Stories in Ready](https://badge.waffle.io/guillaume-nargeot/hpc-coveralls.png?label=ready&title=Ready)](https://waffle.io/guillaume-nargeot/hpc-coveralls)+[![Build Status](http://img.shields.io/travis/guillaume-nargeot/hpc-coveralls/master.svg)](https://travis-ci.org/guillaume-nargeot/hpc-coveralls) [![Gitter chat](http://img.shields.io/badge/gitter-chat--room-brightgreen.svg)](https://gitter.im/guillaume-nargeot/hpc-coveralls) [![BSD3 License](http://img.shields.io/badge/license-BSD3-brightgreen.svg)](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29) [![Version on Hackage](https://img.shields.io/hackage/v/hpc-coveralls.svg)](http://hackage.haskell.org/package/hpc-coveralls) [![Stories in Progress](https://badge.waffle.io/guillaume-nargeot/hpc-coveralls.svg?label=in%20progress&title=In%20Progress)](https://waffle.io/guillaume-nargeot/hpc-coveralls)  hpc-coveralls converts and sends Haskell projects hpc code coverage to [coverall.io](http://coveralls.io/). @@ -62,7 +62,7 @@  Below are some of the conditions under which you will likely need to use `run-cabal-test`: - when using GHC 7.6 (hpc 0.6 known issue)-- when using GHC 7.8 with multiple test suites covering the same module(s) (issue [#18](https://github.com/guillaume-nargeot/hpc-coveralls/issues/18))+- when using GHC 7.8 with multiple test suites covering the same module(s) (issue [#18](https://github.com/guillaume-nargeot/hpc-coveralls/issues/18)) (fixed in GHC 7.10)  ### Options @@ -136,6 +136,20 @@ #### --curl-verbose  This boolean option enables curl verbose mode and prints the raw json response received after posting the coverage report to coveralls.io.++#### --cabal-file++Use this option to specify the cabal file of the coverage report target package.+This might be required in some cases, especially when building with cabal >= 1.22 and ghc >= 7.10, although hpc-coveralls assumes the package cabal file to be the unique file of extension ".cabal" in the current directory if it exists.+For further details check [this issue](https://github.com/guillaume-nargeot/hpc-coveralls/issues/44).++#### --service-name++This option allows you to override the `service_name` value from the report sent to coveralls.io.+You will have to specify it for example when using Travis-pro as in the example below as there is currently no way to programmatically determine:+```bash+--service-name=travis-pro+```  # Limitations 
hpc-coveralls.cabal view
@@ -1,5 +1,5 @@ name:           hpc-coveralls-version:        0.9.0+version:        1.0.0 synopsis:       Coveralls.io support for Haskell. description:   This utility converts and sends Haskell projects hpc code coverage to@@ -28,7 +28,7 @@ build-type:     Simple stability:      experimental cabal-version:  >= 1.8-tested-with:    GHC == 7.6, GHC == 7.8+tested-with:    GHC == 7.6, GHC == 7.8, GHC == 7.10 homepage:       https://github.com/guillaume-nargeot/hpc-coveralls bug-reports:    https://github.com/guillaume-nargeot/hpc-coveralls/issues @@ -49,14 +49,16 @@     Trace.Hpc.Coveralls.Util   other-modules:     HpcCoverallsCmdLine,+    Trace.Hpc.Coveralls.Cabal,     Trace.Hpc.Coveralls.Config,     Trace.Hpc.Coveralls.Curl,     Trace.Hpc.Coveralls.GitInfo,     Trace.Hpc.Coveralls.Paths   build-depends:-    aeson,+    aeson >= 0.7.1,     base >= 4 && < 5,     bytestring >= 0.10,+    Cabal,     containers >= 0.5,     cmdargs >= 0.10,     curl >= 1.3.8,@@ -67,15 +69,17 @@     pureMD5 >= 2.1,     retry >= 0.5,     safe >= 0.3,-    split+    split,+    transformers >= 0.4.3  executable hpc-coveralls   hs-source-dirs: src   main-is:        HpcCoverallsMain.hs   build-depends:-    aeson,+    aeson >= 0.7.1,     base >= 4 && < 5,     bytestring >= 0.10,+    Cabal,     containers >= 0.5,     cmdargs >= 0.10,     curl >= 1.3.8,@@ -86,7 +90,8 @@     pureMD5 >= 2.1,     retry >= 0.5,     safe >= 0.3,-    split+    split,+    transformers >= 0.4.3   ghc-options:    -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns  executable run-cabal-test
src/HpcCoverallsCmdLine.hs view
@@ -11,6 +11,8 @@ data HpcCoverallsArgs = CmdMain     { optExcludeDirs   :: [String]     , argTestSuites    :: [String]+    , optCabalFile     :: Maybe String+    , optServiceName   :: Maybe String     , optRepoToken     :: Maybe String     , optDisplayReport :: Bool     , optCurlVerbose   :: Bool@@ -25,6 +27,8 @@     , optCurlVerbose   = False             &= explicit                &= name "curl-verbose"   &= help "Enable curl verbose mode and prints the json response received from coveralls.io"     , optDontSend      = False             &= explicit                &= name "dont-send"      &= help "Do not send the report to coveralls.io"     , optCoverageMode  = AllowPartialLines &= explicit &= typ "MODE"  &= name "coverage-mode"  &= help "Coverage conversion mode: AllowPartialLines (default), StrictlyFullLines"+    , optCabalFile     = Nothing           &= explicit &= typ "FILE"  &= name "cabal-file"     &= help "Cabal file (ex.: module-name.cabal)"+    , optServiceName   = Nothing           &= explicit &= typ "TOKEN" &= name "service-name"   &= help "service-name (e.g. travis-pro)"     , optRepoToken     = Nothing           &= explicit &= typ "TOKEN" &= name "repo-token"     &= help "Coveralls repo token"     , argTestSuites    = []                &= typ "TEST-SUITES" &= args     } &= summary ("hpc-coveralls-" ++ versionString version ++ ", (C) Guillaume Nargeot 2014-2015")
src/HpcCoverallsMain.hs view
@@ -12,7 +12,8 @@ import           System.Environment (getEnv, getEnvironment) import           System.Exit (exitFailure) import           Trace.Hpc.Coveralls-import           Trace.Hpc.Coveralls.Config (Config(Config))+import           Trace.Hpc.Coveralls.Cabal+import           Trace.Hpc.Coveralls.Config (Config(Config, cabalFile, serviceName)) import           Trace.Hpc.Coveralls.Curl import           Trace.Hpc.Coveralls.GitInfo (getGitInfo) import           Trace.Hpc.Coveralls.Util@@ -39,7 +40,13 @@ writeJson filePath = BSL.writeFile filePath . encode  getConfig :: HpcCoverallsArgs -> Maybe Config-getConfig hca = Config (optExcludeDirs hca) (optCoverageMode hca) (optRepoToken hca) <$> listToMaybe (argTestSuites hca)+getConfig hca = Config+    (optExcludeDirs hca)+    (optCoverageMode hca)+    (optCabalFile hca)+    (optServiceName hca)+    (optRepoToken hca)+    <$> listToMaybe (argTestSuites hca)  main :: IO () main = do@@ -47,11 +54,16 @@     case getConfig hca of         Nothing -> putStrLn "Please specify a target test suite name"         Just config -> do-            (serviceName, jobId) <- getServiceAndJobID+            (defaultServiceName, jobId) <- getServiceAndJobID+            let sn = fromMaybe defaultServiceName (serviceName config)             gitInfo <- getGitInfo-            coverallsJson <- generateCoverallsFromTix serviceName jobId gitInfo config+            mPkgNameVer <- case cabalFile config of+                Just cabalFilePath -> getPackageNameVersion cabalFilePath+                Nothing -> currDirPkgNameVer+            gitInfo <- getGitInfo+            coverallsJson <- generateCoverallsFromTix sn jobId gitInfo config mPkgNameVer             when (optDisplayReport hca) $ BSL.putStrLn $ encode coverallsJson-            let filePath = serviceName ++ "-" ++ jobId ++ ".json"+            let filePath = sn ++ "-" ++ jobId ++ ".json"             writeJson filePath coverallsJson             unless (optDontSend hca) $ do                 response <- postJson filePath urlApiV1 (optCurlVerbose hca)
src/Trace/Hpc/Coveralls.hs view
@@ -104,21 +104,23 @@ mergeCoverageData :: [TestSuiteCoverageData] -> TestSuiteCoverageData mergeCoverageData = foldr1 (M.unionWith mergeModuleCoverageData) -readMix' :: String -> String -> TixModule -> IO Mix-readMix' hpcDir name tix = readMix [getMixPath hpcDir name tix] (Right tix)+readMix' :: Maybe String -> String -> String -> TixModule -> IO Mix+readMix' mPkgNameVer hpcDir name tix = readMix dirs (Right tix)+    where dirs = nub $ (\x -> getMixPath x hpcDir name tix) <$> [Nothing, mPkgNameVer]  -- | Create a list of coverage data from the tix input-readCoverageData :: String                   -- ^ hpc data directory+readCoverageData :: Maybe String             -- ^ Package name-version+                 -> String                   -- ^ hpc data directory                  -> [String]                 -- ^ excluded source folders                  -> String                   -- ^ test suite name                  -> IO TestSuiteCoverageData -- ^ coverage data list-readCoverageData hpcDir excludeDirPatterns testSuiteName = do+readCoverageData mPkgNameVer hpcDir excludeDirPatterns testSuiteName = do     let tixPath = getTixPath hpcDir testSuiteName     mTix <- readTix tixPath     case mTix of         Nothing -> putStrLn ("Couldn't find the file " ++ tixPath) >> dumpDirectoryTree hpcDir >> ioFailure         Just (Tix tixs) -> do-            mixs <- mapM (readMix' hpcDir testSuiteName) tixs+            mixs <- mapM (readMix' mPkgNameVer hpcDir testSuiteName) tixs             let files = map filePath mixs             sources <- mapM readFile files             let coverageDataList = zip4 files sources mixs (map tixModuleTixs tixs)@@ -128,17 +130,18 @@                   sourceDirFilter = not . matchAny excludeDirPatterns . fst4  -- | Generate coveralls json formatted code coverage from hpc coverage data-generateCoverallsFromTix :: String   -- ^ CI name-                         -> String   -- ^ CI Job ID-                         -> GitInfo  -- ^ Git repo information-                         -> Config   -- ^ hpc-coveralls configuration-                         -> IO Value -- ^ code coverage result in json format-generateCoverallsFromTix serviceName jobId gitInfo config = do+generateCoverallsFromTix :: String       -- ^ CI name+                         -> String       -- ^ CI Job ID+                         -> GitInfo      -- ^ Git repo information+                         -> Config       -- ^ hpc-coveralls configuration+                         -> Maybe String -- ^ Package name-version+                         -> IO Value     -- ^ code coverage result in json format+generateCoverallsFromTix serviceName jobId gitInfo config mPkgNameVer = do     mHpcDir <- firstExistingDirectory hpcDirs     case mHpcDir of         Nothing -> putStrLn "Couldn't find the hpc data directory" >> dumpDirectory distDir >> ioFailure         Just hpcDir -> do-            testSuitesCoverages <- mapM (readCoverageData hpcDir excludedDirPatterns) testSuiteNames+            testSuitesCoverages <- mapM (readCoverageData mPkgNameVer hpcDir excludedDirPatterns) testSuiteNames             let coverageData = mergeCoverageData testSuitesCoverages             return $ toCoverallsJson serviceName jobId repoTokenM gitInfo converter coverageData             where excludedDirPatterns = excludedDirs config
+ src/Trace/Hpc/Coveralls/Cabal.hs view
@@ -0,0 +1,44 @@+-- |+-- Module:      Trace.Hpc.Coveralls.Cabal+-- Copyright:   (c) 2014-2015 Guillaume Nargeot+-- License:     BSD3+-- Maintainer:  Guillaume Nargeot <guillaume+hackage@nargeot.com>+-- Stability:   experimental+--+-- Functions for reading cabal package name and version.++module Trace.Hpc.Coveralls.Cabal (currDirPkgNameVer, getPackageNameVersion) where++import Control.Applicative+import Control.Monad+import Control.Monad.Trans.Maybe+import Data.List (intercalate, isSuffixOf)+import Distribution.Package+import Distribution.PackageDescription+import Distribution.PackageDescription.Parse+import Distribution.Version+import System.Directory++getCabalFile :: FilePath -> IO (Maybe FilePath)+getCabalFile dir = do+    files <- (filter isCabal <$> getDirectoryContents dir) >>= filterM doesFileExist+    case files of+        [file] -> return $ Just file+        _ -> return Nothing+    where isCabal filename = ".cabal" `isSuffixOf` filename && length filename > 6++getPackageNameVersion :: FilePath -> IO (Maybe String)+getPackageNameVersion file = do+    orig <- readFile file+    case parsePackageDescription orig of+        ParseFailed _ -> return Nothing+        ParseOk _warnings gpd -> return $ Just $ name ++ "-" ++ version+            where pkg = package . packageDescription $ gpd+                  PackageName name = pkgName pkg+                  version = showVersion (pkgVersion pkg)+                  showVersion = intercalate "." . map show . versionBranch++currDirPkgNameVer :: IO (Maybe String)+currDirPkgNameVer = runMaybeT $ pkgNameVersion currentDir+    where pkgNameVersion = MaybeT . getPackageNameVersion <=< MaybeT . getCabalFile+          currentDir = "."
src/Trace/Hpc/Coveralls/Config.hs view
@@ -5,6 +5,8 @@ data Config = Config {     excludedDirs :: ![FilePath],     coverageMode :: !CoverageMode,+    cabalFile    :: !(Maybe FilePath),+    serviceName  :: !(Maybe String),     repoToken    :: !(Maybe String),     testSuites   :: ![String]     }
src/Trace/Hpc/Coveralls/Paths.hs view
@@ -12,7 +12,7 @@ module Trace.Hpc.Coveralls.Paths where  import Control.Monad--- import Data.Foldable+import Data.Maybe import Data.Traversable (traverse) import System.Directory (     doesDirectoryExist, getDirectoryContents@@ -34,11 +34,15 @@ mixDir :: String -> FilePath mixDir = (++ "mix/") -getMixPath :: String -> String -> TixModule -> FilePath-getMixPath hpcDir testSuiteName tix = mixDir hpcDir ++ dirName ++ "/"+getMixPath :: Maybe String -- ^ target package name-version+           -> String       -- ^ hpc output base directory+           -> String       -- ^ test suite name+           -> TixModule    -- ^ tix module+           -> FilePath     -- ^ mix file patch+getMixPath mPkgNameVer hpcDir testSuiteName tix = mixDir hpcDir ++ dirName ++ "/"     where dirName = case span (/= '/') modName of               (_, []) -> testSuiteName-              (packageId, _) -> packageId+              (packageId, _) -> fromMaybe packageId mPkgNameVer           TixModule modName _ _ _ = tix  getTixPath :: String -> String -> FilePath