hpc-coveralls 0.5.0 → 0.6.0
raw patch · 6 files changed
+84/−28 lines, 6 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- CHANGELOG.md +5/−0
- README.md +22/−6
- hpc-coveralls.cabal +8/−6
- src/HpcCoverallsCmdLine.hs +2/−0
- src/HpcCoverallsMain.hs +22/−14
- src/Trace/Hpc/Coveralls/Curl.hs +25/−2
CHANGELOG.md view
@@ -1,3 +1,8 @@+[0.6.0](https://github.com/guillaume-nargeot/hpc-coveralls/issues?milestone=7&state=closed)+-----+* Add flag to print the raw json responses from coveralls.io (issue #24)+* Retrieve and display total coverage result on success response from coveralls.io (issue #21)+ [0.5.0](https://github.com/guillaume-nargeot/hpc-coveralls/issues?milestone=6&state=closed) ----- * Mark `otherwise` as fully covered (issue #3)
README.md view
@@ -1,4 +1,4 @@-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.5.0)+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.0) ============= hpc-coveralls converts and sends Haskell projects hpc code coverage to [coverall.io](http://coveralls.io/).@@ -20,7 +20,7 @@ - hpc-coveralls [options] [test-suite-names] ``` -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:+If your build fails during the test phase 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@@ -33,10 +33,16 @@ 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.+You may also experience some issues related to your project dependencies, which can be solved by using the `--avoid-reinstalls`/`--force-reinstalls` flags.</br>+Another way to solve problems related dependencies is to install hpc-coveralls in a sandbox, as in the example below:+```yaml+after_script:+ - cabal sandbox init && cabal install hpc-coveralls+ - .cabal-sandbox/bin/hpc-coveralls [options] [test-suite-names]+``` -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).+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)).<br/>+Other real world examples can be found on this [wiki page](https://github.com/guillaume-nargeot/hpc-coveralls/wiki/List-of-repositories-using-hpc-coveralls) which contains a list of GitHub repositories using hpc-coveralls. ## The run-cabal-test command @@ -111,9 +117,19 @@ #### --dont-send -The `--dont-send` option prevents hpc-coveralls from sending the coverage report to coveralls.io.+This boolean option prevents hpc-coveralls from sending the coverage report to coveralls.io. This option can be used together with `--display-report` for testing purpose.<br/> For example, you can try various combinations of the other options and confirm the difference in the resulting report outputs.++#### --print-response++This boolean option prints the raw json response received after posting the coverage report to coveralls.io.++# 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. # Contributing
hpc-coveralls.cabal view
@@ -1,5 +1,5 @@ name: hpc-coveralls-version: 0.5.0+version: 0.6.0 synopsis: Coveralls.io support for Haskell. description: This utility converts and sends Haskell projects hpc code coverage to@@ -54,24 +54,26 @@ Trace.Hpc.Coveralls.Paths build-depends: aeson,- base < 5,+ base >=4 && < 5, bytestring >= 0.10, containers >= 0.5, cmdargs >= 0.10, curl >= 1.3.8,- hpc >= 0.6+ hpc >= 0.6,+ split executable hpc-coveralls hs-source-dirs: src main-is: HpcCoverallsMain.hs build-depends: aeson,- base < 5,+ base >= 4 && < 5, bytestring >= 0.10, containers >= 0.5, cmdargs >= 0.10, curl >= 1.3.8,- hpc >= 0.6+ hpc >= 0.6,+ split ghc-options: -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns executable run-cabal-test@@ -79,7 +81,7 @@ main-is: RunCabalTestMain.hs build-depends: async >= 2.0,- base < 5,+ base >=4 && < 5, process, regex-posix, split
src/HpcCoverallsCmdLine.hs view
@@ -12,6 +12,7 @@ { excludeDirs :: [String] , testSuites :: [String] , displayReport :: Bool+ , printResponse :: Bool , dontSend :: Bool , coverageMode :: CoverageMode } deriving (Data, Show, Typeable)@@ -20,6 +21,7 @@ hpcCoverallsArgs = CmdMain { excludeDirs = [] &= explicit &= typDir &= name "exclude-dir" &= help "Exclude sources files under the matching directory from the coverage report" , displayReport = False &= explicit &= name "display-report" &= help "Display the json code coverage report that will be sent to coveralls.io"+ , printResponse = False &= explicit &= name "print-response" &= help "Prints the json reponse received from coveralls.io" , dontSend = False &= explicit &= name "dont-send" &= help "Do not send the report to coveralls.io" , coverageMode = AllowPartialLines &= explicit &= typ "MODE" &= name "coverage-mode" &= help "Coverage conversion mode: AllowPartialLines (default), StrictlyFullLines" , testSuites = [] &= typ "TEST-SUITE" &= args
src/HpcCoverallsMain.hs view
@@ -1,18 +1,19 @@ module Main where -import Control.Applicative-import Control.Monad-import Data.Aeson+import Control.Applicative+import Control.Concurrent+import Control.Monad+import Data.Aeson import qualified Data.ByteString.Lazy.Char8 as BSL-import Data.List-import Data.Maybe-import HpcCoverallsCmdLine-import System.Console.CmdArgs-import System.Environment (getEnv, getEnvironment)-import System.Exit (exitFailure, exitSuccess)-import Trace.Hpc.Coveralls-import Trace.Hpc.Coveralls.Config (Config(Config))-import Trace.Hpc.Coveralls.Curl+import Data.List+import Data.Maybe+import HpcCoverallsCmdLine+import System.Console.CmdArgs+import System.Environment (getEnv, getEnvironment)+import System.Exit (exitFailure, exitSuccess)+import Trace.Hpc.Coveralls+import Trace.Hpc.Coveralls.Config (Config(Config))+import Trace.Hpc.Coveralls.Curl urlApiV1 :: String urlApiV1 = "https://coveralls.io/api/v1/jobs"@@ -52,7 +53,14 @@ let filePath = serviceName ++ "-" ++ jobId ++ ".json" writeJson filePath coverallsJson unless (dontSend hca) $ do- response <- postJson filePath urlApiV1+ response <- postJson filePath urlApiV1 (printResponse hca) case response of- PostSuccess url -> putStrLn ("URL: " ++ url) >> exitSuccess+ PostSuccess url -> do+ putStrLn ("URL: " ++ url)+ -- wait 5 seconds until the page is available+ threadDelay (5 * 10000000)+ coverageResult <- readCoverageResult url (printResponse hca)+ case coverageResult of+ Just totalCoverage -> putStrLn ("Coverage: " ++ totalCoverage) >> exitSuccess+ Nothing -> exitSuccess PostFailure msg -> putStrLn ("Error: " ++ msg) >> exitFailure
src/Trace/Hpc/Coveralls/Curl.hs view
@@ -10,11 +10,13 @@ -- -- Functions for sending coverage report files over http. -module Trace.Hpc.Coveralls.Curl ( postJson, PostResult (..) ) where+module Trace.Hpc.Coveralls.Curl ( postJson, readCoverageResult, PostResult (..) ) where +import Control.Monad import Data.Aeson import Data.Aeson.Types (parseMaybe) import qualified Data.ByteString.Lazy.Char8 as LBS+import Data.List.Split import Data.Maybe import Network.Curl import Trace.Hpc.Coveralls.Types@@ -34,11 +36,32 @@ -- | Send file content over HTTP using POST request postJson :: String -- ^ target file -> URLString -- ^ target url+ -> Bool -- ^ print json response if true -> IO PostResult -- ^ POST request result-postJson path url = do+postJson path url printResponse = do h <- initialize setopt h (CurlVerbose True) setopt h (CurlURL url) setopt h (CurlHttpPost $ httpPost path) r <- perform_with_response_ h+ when printResponse $ putStrLn $ respBody r return $ parseResponse r++-- | Extract the total coverage percentage value from coveralls coverage result+-- page content.+-- The current implementation is kept as low level as possible in order not+-- to increase the library build time, by not relying on additional packages.+extractCoverage :: String -> String+extractCoverage = head . splitOn "<" . (!! 1) . splitOn prefix+ where prefix = "div class='coverage'>\n<strong>"++-- | Read the coveraege result page from coveralls.io+readCoverageResult :: URLString -- ^ target url+ -> Bool -- ^ print json response if true+ -> IO (Maybe String) -- ^ coverage result+readCoverageResult url printResponse = do+ response <- curlGetString url []+ when printResponse $ putStrLn $ snd response+ return $ case response of+ (CurlOK, body) -> Just $ extractCoverage body+ _ -> Nothing