packages feed

hpc-coveralls 0.4.0 → 0.5.0

raw patch · 7 files changed

+77/−32 lines, 7 filesdep ~asyncdep ~hpcPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: async, hpc

API changes (from Hackage documentation)

+ Trace.Hpc.Coveralls.Lix: adjust :: CoverageEntry -> CoverageEntry
+ Trace.Hpc.Coveralls.Types: type CoverageEntry = (MixEntry, Integer, [String])
+ Trace.Hpc.Coveralls.Util: mapFirst :: (a -> a) -> [a] -> [a]
+ Trace.Hpc.Coveralls.Util: mapLast :: (a -> a) -> [a] -> [a]
+ Trace.Hpc.Coveralls.Util: subSeq :: Int -> Int -> [a] -> [a]
+ Trace.Hpc.Coveralls.Util: subSubSeq :: Int -> Int -> [[a]] -> [[a]]
- Trace.Hpc.Coveralls.Lix: toLineHit :: (MixEntry, Integer) -> (Int, Bool)
+ Trace.Hpc.Coveralls.Lix: toLineHit :: CoverageEntry -> (Int, Bool)
- Trace.Hpc.Coveralls.Lix: toLix :: Int -> [(MixEntry, Integer)] -> Lix
+ Trace.Hpc.Coveralls.Lix: toLix :: Int -> [CoverageEntry] -> Lix

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+[0.5.0](https://github.com/guillaume-nargeot/hpc-coveralls/issues?milestone=6&state=closed)+-----+* Mark `otherwise` as fully covered (issue #3)+ [0.4.0](https://github.com/guillaume-nargeot/hpc-coveralls/issues?milestone=5&state=closed) ----- * Add option to configure the coverage data conversion (issue #15)
README.md view
@@ -1,4 +1,4 @@-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)+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) [![v0.5.0 on Hackage](http://img.shields.io/badge/hackage-0.5.0-brightgreen.svg)](http://hackage.haskell.org/package/hpc-coveralls-0.5.0) =============  hpc-coveralls converts and sends Haskell projects hpc code coverage to [coverall.io](http://coveralls.io/).@@ -11,17 +11,16 @@  ## Travis CI -Commands to add to your project `.travis.yml` when using GHC 7.8:+Below is the simplest example of configuration for your project `.travis.yml`: ```yaml-before_install:-  - cabal install hpc-coveralls script:   - cabal configure --enable-tests --enable-library-coverage && cabal build && cabal test after_script:+  - cabal install hpc-coveralls   - hpc-coveralls [options] [test-suite-names] ``` -When using a GHC version prior to 7.8, you have to replace the `cabal test` command by `run-cabal-test`, as in the following example:+If your build fails with an error message starting by "hpc:", just replace the `cabal test` command by `run-cabal-test`, as in the following example: ```yaml before_install:   - cabal install hpc-coveralls@@ -32,22 +31,26 @@   - hpc-coveralls [options] [test-suite-names] ``` -The reason for this is explained in the next section.+This will prevent the build to fail because of hpc related reasons, which are usually not fatal and should not affect the coverage data. Details are available in the next section. +You may also experience some issues related to your project dependencies, which can be solved by using the `--avoid-reinstalls`/`--force-reinstalls` flags.+ For a real world example usage, please refer to [this-project](https://github.com/guillaume-nargeot/project-euler-haskell) `.travis.yml` file ([result on coveralls](https://coveralls.io/r/guillaume-nargeot/project-euler-haskell)). You can also refer to the `.travis.yml` file of hpc-coveralls itself, which is configured with [multi-ghc-travis](https://github.com/hvr/multi-ghc-travis).  ## The run-cabal-test command -When using hpc 0.6, `cabal test` outputs an error message and exits with the error code `1`, which results in a build failure.+Under certain conditions related to the project structure and the version of hpc, `cabal test` may output an error message and exit with the error code `1`, which would result in a build failure.<br/> -In order to prevent this from happening, hpc-coveralls provides the `run-cabal-test` command which runs `cabal test` and returns with `0` if the following regex never matches any line of the output:+To prevent this from happening, hpc-coveralls provides the `run-cabal-test` command which runs `cabal test` and returns with `0` if the following regular expression never matches any line of the output:  ```perl /^Test suite .*: FAIL$/ ``` -As this issue is fixed in the hpc version shipped with GHC 7.8, you don't have to use `run-cabal-test` when testing with GHC 7.8 and can safely use `cabal test`.+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))  ### Options @@ -67,6 +70,8 @@ ```yaml hpc-coveralls test1 test2 ```++As noted earlier,   ### Options 
hpc-coveralls.cabal view
@@ -1,5 +1,5 @@ name:           hpc-coveralls-version:        0.4.0+version:        0.5.0 synopsis:       Coveralls.io support for Haskell. description:   This utility converts and sends Haskell projects hpc code coverage to@@ -7,13 +7,14 @@   .   /Usage/   .-  Commands to add to your project .travis.yml when using Travis CI:+  Below is the simplest example of .travis.yml configuration to use with Travis CI:   .-  > before_install:-  >   - cabal install hpc-coveralls+  > language: haskell+  > ghc: 7.8   > script:   >   - cabal configure --enable-tests --enable-library-coverage && cabal build && cabal test   > after_script:+  >   - cabal install hpc-coveralls   >   - hpc-coveralls [options] [test-suite-names]   .   Further information can be found in the <https://github.com/guillaume-nargeot/hpc-coveralls README>.@@ -28,8 +29,8 @@ stability:      experimental cabal-version:  >= 1.8 tested-with:    GHC == 7.6, GHC == 7.8-bug-reports:    https://github.com/guillaume-nargeot/hpc-coveralls-homepage:       https://github.com/guillaume-nargeot/hpc-coveralls/issues+homepage:       https://github.com/guillaume-nargeot/hpc-coveralls+bug-reports:    https://github.com/guillaume-nargeot/hpc-coveralls/issues  extra-source-files:   README.md,@@ -58,7 +59,7 @@     containers >= 0.5,     cmdargs >= 0.10,     curl >= 1.3.8,-    hpc >= 0.6.0.0+    hpc >= 0.6  executable hpc-coveralls   hs-source-dirs: src@@ -70,14 +71,14 @@     containers >= 0.5,     cmdargs >= 0.10,     curl >= 1.3.8,-    hpc >= 0.6.0.0+    hpc >= 0.6   ghc-options:    -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns  executable run-cabal-test   hs-source-dirs: src   main-is:        RunCabalTestMain.hs   build-depends:-    async >= 2.0.0.0,+    async >= 2.0,     base < 5,     process,     regex-posix,
src/Trace/Hpc/Coveralls.hs view
@@ -23,6 +23,7 @@ import           Trace.Hpc.Coveralls.Util import           Trace.Hpc.Mix import           Trace.Hpc.Tix+import           Trace.Hpc.Util  type ModuleCoverageData = (     String,    -- file source code@@ -32,10 +33,10 @@ type TestSuiteCoverageData = M.Map FilePath ModuleCoverageData  -- single file coverage data in the format defined by coveralls.io-type SimpleCoverage = [CoverageEntry]+type SimpleCoverage = [CoverageValue]  -- Is there a way to restrict this to only Number and Null?-type CoverageEntry = Value+type CoverageValue = Value  type LixConverter = Lix -> SimpleCoverage @@ -53,9 +54,16 @@     None       -> Number 0     Irrelevant -> Null -toSimpleCoverage :: LixConverter -> Int -> [(MixEntry, Integer)] -> SimpleCoverage+toSimpleCoverage :: LixConverter -> Int -> [CoverageEntry] -> SimpleCoverage toSimpleCoverage convert lineCount = convert . toLix lineCount +getExprSource :: [String] -> MixEntry -> [String]+getExprSource source (hpcPos, _) = subSubSeq startCol endCol subLines+    where subLines = subSeq startLine endLine source+          startLine = startLine' - 1+          startCol = startCol' - 1+          (startLine', startCol', endLine, endCol) = fromHpcPos hpcPos+ coverageToJson :: LixConverter -> FilePath -> ModuleCoverageData -> Value coverageToJson converter filePath (source, mix, tixs) = object [     "name" .= filePath,@@ -63,8 +71,9 @@     "coverage" .= coverage]     where coverage = toSimpleCoverage converter lineCount mixEntryTixs           lineCount = length $ lines source-          mixEntryTixs = zip (getMixEntries mix) tixs-          getMixEntries (Mix _ _ _ _ mixEntries) = mixEntries+          mixEntryTixs = zip3 mixEntries tixs (map getExprSource' mixEntries)+          Mix _ _ _ _ mixEntries = mix+          getExprSource' = getExprSource $ lines source  toCoverallsJson :: String -> String -> LixConverter -> TestSuiteCoverageData -> Value toCoverallsJson serviceName jobId converter testSuiteCoverageData = object [
src/Trace/Hpc/Coveralls/Lix.hs view
@@ -19,24 +19,29 @@ import Trace.Hpc.Util  toHit :: [Bool] -> Hit-toHit [] = Irrelevant+toHit []  = Irrelevant toHit [x] = if x then Full else None toHit xs-    | and xs = Full-    | or xs = Partial+    | and xs    = Full+    | or xs     = Partial     | otherwise = None  getLine :: MixEntry -> Int getLine = fffst . fromHpcPos . fst     where fffst (x, _, _, _) = x -toLineHit :: (MixEntry, Integer) -> (Int, Bool)-toLineHit (entry, cnt) = (getLine entry - 1, cnt > 0)+toLineHit :: CoverageEntry -> (Int, Bool)+toLineHit (entry, cnt, _source) = (getLine entry - 1, cnt > 0) +adjust :: CoverageEntry -> CoverageEntry+adjust coverageEntry@(mixEntry, _, source) = case (snd mixEntry, source) of+    (BinBox GuardBinBox False, ["otherwise"]) -> (mixEntry, 1, source)+    _ -> coverageEntry+ -- | Convert hpc coverage entries into a line based coverage format-toLix :: Int                   -- ^ Source line count-      -> [(MixEntry, Integer)] -- ^ Mix entries and associated hit count-      -> Lix                   -- ^ Line coverage+toLix :: Int             -- ^ Source line count+      -> [CoverageEntry] -- ^ Mix entries and associated hit count+      -> Lix             -- ^ Line coverage toLix lineCount entries = map toHit (groupByIndex lineCount sortedLineHits)     where sortedLineHits = sortBy (comparing fst) lineHits-          lineHits = map toLineHit entries+          lineHits = map (toLineHit . adjust) entries
src/Trace/Hpc/Coveralls/Types.hs view
@@ -14,6 +14,12 @@ import Data.Data import Network.Curl import System.Console.CmdArgs.Default+import Trace.Hpc.Mix++type CoverageEntry = (+    MixEntry, -- mix entry+    Integer,  -- tix value+    [String])   -- entry source code  data Hit = Full          | Partial
src/Trace/Hpc/Coveralls/Util.hs view
@@ -20,6 +20,21 @@ matchAny :: [String] -> String -> Bool matchAny patterns fileName = any (`isPrefixOf` fileName) patterns +mapFirst :: (a -> a) -> [a] -> [a]+mapFirst f (x : xs) = f x : xs+mapFirst _ []       = []+ +mapLast :: (a -> a) -> [a] -> [a]+mapLast f [x]      = [f x]+mapLast f (x : xs) = x : mapLast f xs+mapLast _ []       = []++subSeq :: Int -> Int -> [a] -> [a]+subSeq start end = drop start . take end++subSubSeq :: Int -> Int -> [[a]] -> [[a]]+subSubSeq start end = mapFirst (drop start) . mapLast (take end)+ groupByIndex :: Int -> [(Int, a)] -> [[a]] groupByIndex size = take size . flip (++) (repeat []) . groupByIndex' 0 []     where groupByIndex' _ ys [] = [ys]