Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
5 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
language: haskell | ||
install: | ||
- cabal update | ||
- cabal install | ||
test: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,7 @@ | ||
#!/usr/bin/env runhaskell | ||
\begin{code} | ||
{-# LANGUAGE CPP #-} | ||
|
||
import Control.Monad (when, unless, mplus) | ||
|
||
import Data.Maybe (listToMaybe, fromMaybe) | ||
import Distribution.PackageDescription | ||
(PackageDescription, buildable, exeName, buildInfo, executables, customFieldsBI, BuildInfo) | ||
import Distribution.Verbosity (normal) | ||
import Distribution.Simple.Build (build) | ||
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..)) | ||
import Distribution.Simple.PreProcess (knownSuffixHandlers) | ||
import Distribution.Simple.Program (programFindLocation, lookupKnownProgram ) | ||
import Distribution.Simple.Setup (defaultBuildFlags) | ||
import Distribution.Simple | ||
( Args, defaultMainWithHooks, UserHooks(..), simpleUserHooks) | ||
|
||
import System.Exit (ExitCode(..)) | ||
import System.FilePath ( (</>), splitDirectories, isAbsolute ) | ||
import System.IO (openFile, IOMode (..)) | ||
import System.Process | ||
import System.Directory | ||
( getCurrentDirectory, createDirectoryIfMissing | ||
, setCurrentDirectory, findExecutable, canonicalizePath | ||
, removeFile, doesDirectoryExist | ||
) | ||
|
||
main :: IO () | ||
main = defaultMainWithHooks hooks | ||
|
||
hooks :: UserHooks | ||
hooks = simpleUserHooks { runTests = runMyTests } | ||
|
||
findHPC :: LocalBuildInfo -> IO FilePath | ||
findHPC lbi = do | ||
Just hpcProgram <- return $ lookupKnownProgram "hpc" $ withPrograms lbi | ||
Just hpc <- programFindLocation hpcProgram normal | ||
return hpc | ||
`catch` \_ -> do | ||
Just hpc <- findExecutable "hpc" | ||
return hpc | ||
|
||
testSpeculation :: a -> (BuildInfo -> a) -> PackageDescription -> a | ||
testSpeculation dflt f pd = | ||
fromMaybe dflt $ listToMaybe | ||
[ f (buildInfo exe) | ||
| exe <- executables pd | ||
, exeName exe == "test-speculation" ] | ||
|
||
runMyTests :: Args -> Bool -> PackageDescription -> LocalBuildInfo -> IO () | ||
runMyTests args0 _unknown pd lbi = do | ||
let args = if null args0 then [] else "-t" : args0 | ||
-- dir <- getWorkingDirectory | ||
let testDir = buildDir lbi </> "test-speculation" | ||
baseDir <- getCurrentDirectory | ||
canonicalBuildDir <- canonicalizePath (buildDir lbi) | ||
t <- doesDirectoryExist testDir | ||
unless t $ do | ||
unless (testSpeculation False buildable pd) $ do | ||
fail "Reconfigure with 'cabal configure -ftests' or 'cabal install -ftests' and try again." | ||
putStrLn "building tests" | ||
build pd lbi defaultBuildFlags knownSuffixHandlers | ||
putStrLn "tests built" | ||
|
||
setCurrentDirectory testDir | ||
let customFields = testSpeculation [] customFieldsBI pd | ||
profiling = maybe False (const True) $ lookup "x-hpc" customFields | ||
|
||
when profiling $ do | ||
removeFile "test-speculation.tix" | ||
putStrLn $ "removed test-speculation.tix" | ||
`catch` \_ -> return () | ||
|
||
exitcode <- system $ unwords $ "test-speculation" : args | ||
unless (exitcode == ExitSuccess) $ | ||
fail "test failed" | ||
|
||
when profiling $ do | ||
hpc <- findHPC lbi | ||
|
||
exitcode <- system $ unwords $ hpc | ||
: "report" | ||
: "test-speculation" | ||
: "--srcdir=../../.." | ||
: [] | ||
unless (exitcode == ExitSuccess) $ | ||
fail "hpc report failed" | ||
|
||
let markupDir base = base </> "doc" </> "html" </> "test-speculation" | ||
createDirectoryIfMissing True (markupDir canonicalBuildDir) | ||
|
||
exitcode <- system $ unwords $ hpc | ||
: "markup" | ||
: "test-speculation" | ||
: "--srcdir=../../.." | ||
: ("--destdir=" ++ markupDir canonicalBuildDir) | ||
: "--exclude=Main" | ||
: [] | ||
unless (exitcode == ExitSuccess) $ | ||
fail "hpc report failed" | ||
|
||
putStrLn $ "Code coverage created: " ++ (markupDir (buildDir lbi) </> "hpc_index.html") | ||
|
||
\end{code} | ||
#!/usr/bin/runhaskell | ||
> module Main (main) where | ||
|
||
> import Distribution.Simple | ||
|
||
> main :: IO () | ||
> main = defaultMain |