Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
killy971 committed Jun 17, 2017
2 parents 17cc255 + a383cc6 commit cb9f6a4
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 28 deletions.
19 changes: 12 additions & 7 deletions src/CodecovHaskellCmdLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,31 @@ import Data.List
import Data.Version (Version(..))
import Paths_codecov_haskell (version)
import System.Console.CmdArgs
import Trace.Hpc.Codecov.Paths (defaultTixDir,defaultMixDir)

data CodecovHaskellArgs = CmdMain
{ token :: Maybe String
, accessToken :: Maybe String
, excludeDirs :: [String]
, testSuites :: [String]
, tixDir :: FilePath
, mixDir :: FilePath
, displayReport :: Bool
, printResponse :: Bool
, dontSend :: Bool
} deriving (Data, Show, Typeable)

codecovHaskellArgs :: CodecovHaskellArgs
codecovHaskellArgs = CmdMain
{ token = Nothing &= explicit &= typDir &= name "token" &= help "Codecov upload token for this repository"
, accessToken = Nothing &= explicit &= typDir &= name "access-token" &= help "Codecov access token to retrieve reports for private repos"
, 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 codecov.io"
, printResponse = False &= explicit &= name "print-response" &= help "Prints the json reponse received from codecov.io"
, dontSend = False &= explicit &= name "dont-send" &= help "Do not send the report to codecov.io"
, testSuites = [] &= typ "TEST-SUITE" &= args
{ token = Nothing &= explicit &= typDir &= name "token" &= help "Codecov upload token for this repository"
, accessToken = Nothing &= explicit &= typDir &= name "access-token" &= help "Codecov access token to retrieve reports for private repos"
, excludeDirs = [] &= explicit &= typDir &= name "exclude-dir" &= help "Exclude sources files under the matching directory from the coverage report"
, tixDir = defaultTixDir &= explicit &= typDir &= name "tix-dir" &= help "Exclude sources files under the matching directory from the coverage report"
, mixDir = defaultMixDir &= explicit &= typDir &= name "mix-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 codecov.io"
, printResponse = False &= explicit &= name "print-response" &= help "Prints the json reponse received from codecov.io"
, dontSend = False &= explicit &= name "dont-send" &= help "Do not send the report to codecov.io"
, testSuites = [] &= typ "TEST-SUITE" &= args
} &= summary ("codecov-haskell-" ++ versionString version ++ ", (C) Guillaume Nargeot 2014")
&= program "codecov-haskell"
where versionString = intercalate "." . map show . versionBranch
8 changes: 7 additions & 1 deletion src/CodecovHaskellMain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import System.Environment (getEnv, getEnvironment)
import System.Exit (exitFailure, exitSuccess)
import Trace.Hpc.Codecov
import Trace.Hpc.Codecov.Config (Config(Config))
import qualified Trace.Hpc.Codecov.Config as Config
import Trace.Hpc.Codecov.Curl
import Trace.Hpc.Codecov.Util

Expand All @@ -39,7 +40,12 @@ getUrlWithToken apiUrl _ Nothing = return apiUrl
getUrlWithToken apiUrl param (Just t) = return $ apiUrl ++ "&" ++ param ++ "=" ++ t

getConfig :: CodecovHaskellArgs -> Maybe Config
getConfig cha = Config (excludeDirs cha) <$> listToMaybe (testSuites cha)
getConfig cha = do _testSuites <- listToMaybe (testSuites cha)
return Config { Config.excludedDirs = excludeDirs cha
, Config.testSuites = _testSuites
, Config.tixDir = tixDir cha
, Config.mixDir = mixDir cha
}

main :: IO ()
main = do
Expand Down
15 changes: 8 additions & 7 deletions src/Trace/Hpc/Codecov.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,21 @@ mergeModuleCoverageData (source, mix, tixs1) (_, _, tixs2) =
mergeCoverageData :: [TestSuiteCoverageData] -> TestSuiteCoverageData
mergeCoverageData = foldr1 (M.unionWith mergeModuleCoverageData)

readMix' :: String -> TixModule -> IO Mix
readMix' name tix = readMix [getMixPath name tix] (Right tix)
readMix' :: Config -> String -> TixModule -> IO Mix
readMix' config name tix = readMix (getMixPaths config name tix) $ Right tix

-- | Create a list of coverage data from the tix input
readCoverageData :: String -- ^ test suite name
readCoverageData :: Config -- ^ codecov-haskell configuration
-> String -- ^ test suite name
-> [String] -- ^ excluded source folders
-> IO TestSuiteCoverageData -- ^ coverage data list
readCoverageData testSuiteName excludeDirPatterns = do
tixPath <- getTixPath testSuiteName
readCoverageData config testSuiteName excludeDirPatterns = do
tixPath <- getTixPath config testSuiteName
mtix <- readTix tixPath
case mtix of
Nothing -> error ("Couldn't find the file " ++ tixPath) >> exitFailure
Just (Tix tixs) -> do
mixs <- mapM (readMix' testSuiteName) tixs
mixs <- mapM (readMix' config testSuiteName) tixs
let files = map filePath mixs
sources <- mapM readFile files
let coverageDataList = zip4 files sources mixs (map tixModuleTixs tixs)
Expand All @@ -111,7 +112,7 @@ readCoverageData testSuiteName excludeDirPatterns = do
generateCodecovFromTix :: Config -- ^ codecov-haskell configuration
-> IO Value -- ^ code coverage result in json format
generateCodecovFromTix config = do
testSuitesCoverages <- mapM (`readCoverageData` excludedDirPatterns) testSuiteNames
testSuitesCoverages <- mapM (flip (readCoverageData config) excludedDirPatterns) testSuiteNames
return $ toCodecovJson converter $ mergeCoverageData testSuitesCoverages
where excludedDirPatterns = excludedDirs config
testSuiteNames = testSuites config
Expand Down
4 changes: 3 additions & 1 deletion src/Trace/Hpc/Codecov/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ module Trace.Hpc.Codecov.Config where

data Config = Config {
excludedDirs :: ![FilePath],
testSuites :: ![String]
testSuites :: ![String],
tixDir :: !FilePath,
mixDir :: !FilePath
}
26 changes: 14 additions & 12 deletions src/Trace/Hpc/Codecov/Paths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
module Trace.Hpc.Codecov.Paths where

import Trace.Hpc.Tix
import Trace.Hpc.Codecov.Config

hpcDir :: FilePath
hpcDir = "dist/hpc/"
defaultHpcDir :: FilePath
defaultHpcDir = "dist/hpc/"

tixDir :: FilePath
tixDir = hpcDir ++ "tix/"
defaultTixDir :: FilePath
defaultTixDir = defaultHpcDir ++ "tix/"

mixDir :: FilePath
mixDir = hpcDir ++ "mix/"
defaultMixDir :: FilePath
defaultMixDir = defaultHpcDir ++ "mix/"

getMixPath :: String -> TixModule -> FilePath
getMixPath testSuiteName tix = mixDir ++ dirName ++ "/"
getMixPaths :: Config -> String -> TixModule -> [FilePath]
getMixPaths config testSuiteName tix = do _dirName <- dirName
return $ mixDir config ++ _dirName ++ "/"
where dirName = case span (/= '/') modName of
(_, []) -> testSuiteName
(packageId, _) -> packageId
(_, []) -> [ testSuiteName ]
(packageId, _) -> [ "", packageId ]
TixModule modName _ _ _ = tix

getTixPath :: String -> IO FilePath
getTixPath testSuiteName = return $ tixDir ++ testSuiteName ++ "/" ++ getTixFileName testSuiteName
getTixPath :: Config -> String -> IO FilePath
getTixPath config testSuiteName = return $ tixDir config ++ testSuiteName ++ "/" ++ getTixFileName testSuiteName
66 changes: 66 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-8.12

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps: []

# Override default flag values for local packages and extra-deps
flags: {}

# Extra package databases containing global packages
extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.1"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor

0 comments on commit cb9f6a4

Please sign in to comment.