Commits

Anonymous committed 2e982d5

Added haddock coverage test

Comments (0)

Files changed (2)

   build-depends:       base ==4.6.*,
                        failure <=0.2.1
   
-Test-Suite test-diffgeom
+-- Main functionality tests
+test-suite test-diffgeom
     hs-source-dirs: tests, src
     type:       exitcode-stdio-1.0
     main-is:    MainTestSuite.hs
         , tasty-quickcheck >= 0.3
         , failure
 
+-- Documentation coverage reporting
+test-suite haddock
+    hs-source-dirs: tests
+    type:       exitcode-stdio-1.0
+    main-is:    Haddock.hs
+    default-language: Haskell2010
+    build-depends: base ==4.6.*, process == 1.1.*, regex-compat == 0.95.*
+
+
 -- You can disable the hlint test suite with -f-test-hlint
 flag test-hlint
   default: True
+module Main (main) where
+
+import Data.List (genericLength)
+import Data.Maybe (catMaybes)
+import System.Exit (exitFailure, exitSuccess)
+import System.Process (readProcess)
+import Text.Regex (matchRegex, mkRegex)
+
+average :: (Fractional a, Real b) => [b] -> a
+average xs = realToFrac (sum xs) / genericLength xs
+
+expected :: Fractional a => a
+expected = 90
+
+main :: IO ()
+main = do
+    output <- readProcess "cabal" ["haddock"] ""
+    if average (match output) >= expected
+        then exitSuccess
+        else putStr output >> exitFailure
+
+match :: String -> [Int]
+match = fmap read . concat . catMaybes . fmap (matchRegex pattern) . lines
+  where
+    pattern = mkRegex "^ *([0-9]*)% "