hpc-coveralls 0.6.1 → 0.7.0
raw patch · 9 files changed
+52/−19 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Trace.Hpc.Coveralls.Lix: isOtherwiseEntry :: CoverageEntry -> Bool
+ Trace.Hpc.Coveralls.Util: fst3 :: (a, b, c) -> a
+ Trace.Hpc.Coveralls.Util: listToMaybe :: [a] -> Maybe [a]
+ Trace.Hpc.Coveralls.Util: snd3 :: (a, b, c) -> b
+ Trace.Hpc.Coveralls.Util: trd3 :: (a, b, c) -> c
- Trace.Hpc.Coveralls.Types: type CoverageEntry = (MixEntry, Integer, [String])
+ Trace.Hpc.Coveralls.Types: type CoverageEntry = ([MixEntry], [Integer], [String])
Files
- CHANGELOG.md +4/−0
- README.md +5/−5
- hpc-coveralls.cabal +1/−1
- src/HpcCoverallsMain.hs +3/−4
- src/Trace/Hpc/Coveralls.hs +8/−1
- src/Trace/Hpc/Coveralls/Config.hs +2/−2
- src/Trace/Hpc/Coveralls/Lix.hs +14/−4
- src/Trace/Hpc/Coveralls/Types.hs +2/−2
- src/Trace/Hpc/Coveralls/Util.hs +13/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+[0.7.0](https://github.com/guillaume-nargeot/hpc-coveralls/issues?q=milestone:v0.7.0+is:closed)+-----+* Fix coverage conversion rule for otherwise bug+ [0.6.1](https://github.com/guillaume-nargeot/hpc-coveralls/issues?milestone=8&state=closed) ----- * Safer implementation of the result coverage value retrieval from coveralls.io (issue 25)
README.md view
@@ -1,6 +1,8 @@-hpc-coveralls [](https://travis-ci.org/guillaume-nargeot/hpc-coveralls) [](https://gitter.im/guillaume-nargeot/hpc-coveralls) [](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29) [](http://hackage.haskell.org/package/hpc-coveralls-0.6.1)+hpc-coveralls ============= +[](https://travis-ci.org/guillaume-nargeot/hpc-coveralls) [](https://gitter.im/guillaume-nargeot/hpc-coveralls) [](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29) [](http://hackage.haskell.org/package/hpc-coveralls-0.7.0) [](https://waffle.io/guillaume-nargeot/hpc-coveralls)+ hpc-coveralls converts and sends Haskell projects hpc code coverage to [coverall.io](http://coveralls.io/). At the moment, only [Travis CI](http://travis-ci.org) has been tested, but hpc-coveralls should be compatible with other CI services (Check `HpcCoverallsMain` [source](https://github.com/guillaume-nargeot/hpc-coveralls/blob/master/src/HpcCoverallsMain.hs) for the list).@@ -77,14 +79,12 @@ hpc-coveralls test1 test2 ``` -As noted earlier, - ### Options #### --exclude-dir The `--exclude-dir` option allows to exclude source files located under a given directory from the coverage report.<br/>-You can exclude source files located under the `test/` by using this option as in the following example:+You can exclude source files located under the `test/` directory by using this option as in the following example: ```yaml hpc-coveralls --exclude-dir=test [test-suite-names]@@ -128,8 +128,8 @@ # Limitations Because of the way hpc works, coverage data is only generated for modules that are referenced directly or indirectly by the test suites.- As a result, the total package coverage computed by coveralls may be higher than what it really is.+An option will be added soon in order to allow specifying source folders to include in the total coverage computation. # Contributing
hpc-coveralls.cabal view
@@ -1,5 +1,5 @@ name: hpc-coveralls-version: 0.6.1+version: 0.7.0 synopsis: Coveralls.io support for Haskell. description: This utility converts and sends Haskell projects hpc code coverage to
src/HpcCoverallsMain.hs view
@@ -6,7 +6,7 @@ import Data.Aeson import qualified Data.ByteString.Lazy.Char8 as BSL import Data.List-import Data.Maybe+import Data.Maybe hiding (listToMaybe) import HpcCoverallsCmdLine import System.Console.CmdArgs import System.Environment (getEnv, getEnvironment)@@ -14,6 +14,7 @@ import Trace.Hpc.Coveralls import Trace.Hpc.Coveralls.Config (Config(Config)) import Trace.Hpc.Coveralls.Curl+import Trace.Hpc.Coveralls.Util urlApiV1 :: String urlApiV1 = "https://coveralls.io/api/v1/jobs"@@ -37,9 +38,7 @@ writeJson filePath = BSL.writeFile filePath . encode getConfig :: HpcCoverallsArgs -> Maybe Config-getConfig hca = case testSuites hca of- [] -> Nothing- testSuiteNames -> Just $ Config testSuiteNames (excludeDirs hca) (coverageMode hca)+getConfig hca = Config (excludeDirs hca) (coverageMode hca) <$> listToMaybe (testSuites hca) main :: IO () main = do
src/Trace/Hpc/Coveralls.hs view
@@ -13,6 +13,7 @@ import Data.Aeson import Data.Aeson.Types ()+import Data.Function import Data.List import qualified Data.Map.Strict as M import System.Exit (exitFailure)@@ -64,13 +65,19 @@ startCol = startCol' - 1 (startLine', startCol', endLine, endCol) = fromHpcPos hpcPos +groupMixEntryTixs :: [(MixEntry, Integer, [String])] -> [CoverageEntry]+groupMixEntryTixs = map mergeOnLst3 . groupBy ((==) `on` fst . fst3)+ where mergeOnLst3 xxs@(x : _) = (map fst3 xxs, map snd3 xxs, trd3 x)+ mergeOnLst3 [] = error "mergeOnLst3 appliedTo empty list"+ coverageToJson :: LixConverter -> FilePath -> ModuleCoverageData -> Value coverageToJson converter filePath (source, mix, tixs) = object [ "name" .= filePath, "source" .= source, "coverage" .= coverage]- where coverage = toSimpleCoverage converter lineCount mixEntryTixs+ where coverage = toSimpleCoverage converter lineCount mixEntriesTixs lineCount = length $ lines source+ mixEntriesTixs = groupMixEntryTixs mixEntryTixs mixEntryTixs = zip3 mixEntries tixs (map getExprSource' mixEntries) Mix _ _ _ _ mixEntries = mix getExprSource' = getExprSource $ lines source
src/Trace/Hpc/Coveralls/Config.hs view
@@ -3,7 +3,7 @@ import Trace.Hpc.Coveralls.Types (CoverageMode) data Config = Config {- testSuites :: ![String], excludedDirs :: ![FilePath],- coverageMode :: !CoverageMode+ coverageMode :: !CoverageMode,+ testSuites :: ![String] }
src/Trace/Hpc/Coveralls/Lix.hs view
@@ -31,12 +31,22 @@ where fffst (x, _, _, _) = x toLineHit :: CoverageEntry -> (Int, Bool)-toLineHit (entry, cnt, _source) = (getLine entry - 1, cnt > 0)+toLineHit (entries, counts, _source) = (getLine (head entries) - 1, all (> 0) counts) +isOtherwiseEntry :: CoverageEntry -> Bool+isOtherwiseEntry (mixEntries, _, source) =+ source == ["otherwise"] && boxLabels == otherwiseBoxLabels+ where boxLabels = map snd mixEntries+ otherwiseBoxLabels = [+ ExpBox False,+ BinBox GuardBinBox True,+ BinBox GuardBinBox False]+ adjust :: CoverageEntry -> CoverageEntry-adjust coverageEntry@(mixEntry, _, source) = case (snd mixEntry, source) of- (BinBox GuardBinBox False, ["otherwise"]) -> (mixEntry, 1, source)- _ -> coverageEntry+adjust coverageEntry@(mixEntries, tixs, source) =+ if isOtherwiseEntry coverageEntry && any (> 0) tixs+ then (mixEntries, [1, 1, 1], source)+ else coverageEntry -- | Convert hpc coverage entries into a line based coverage format toLix :: Int -- ^ Source line count
src/Trace/Hpc/Coveralls/Types.hs view
@@ -17,8 +17,8 @@ import Trace.Hpc.Mix type CoverageEntry = (- MixEntry, -- mix entry- Integer, -- tix value+ [MixEntry], -- mix entries+ [Integer], -- tix values [String]) -- entry source code data Hit = Full
src/Trace/Hpc/Coveralls/Util.hs view
@@ -11,11 +11,24 @@ import Data.List +fst3 :: (a, b, c) -> a+fst3 (x, _, _) = x++snd3 :: (a, b, c) -> b+snd3 (_, x, _) = x++trd3 :: (a, b, c) -> c+trd3 (_, _, x) = x+ fst4 :: (a, b, c, d) -> a fst4 (x, _, _, _) = x toFirstAndRest :: (a, b, c, d) -> (a, (b, c, d)) toFirstAndRest (a, b, c, d) = (a, (b, c, d))++listToMaybe :: [a] -> Maybe [a]+listToMaybe [] = Nothing+listToMaybe xs = Just xs matchAny :: [String] -> String -> Bool matchAny patterns fileName = any (`isPrefixOf` fileName) patterns