File: Doctests.hs

package info (click to toggle)
haskell-servant 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 228 kB
  • ctags: 8
  • sloc: haskell: 1,120; ansic: 8; makefile: 6
file content (40 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Main where

import           Data.List            (isPrefixOf)
import           System.Directory
import           System.FilePath
import           System.FilePath.Find
import           Test.DocTest

main :: IO ()
main = do
    files <- find always (extension ==? ".hs") "src"
    tfiles <- find always (extension ==? ".hs") "test/Servant"
    mCabalMacrosFile <- getCabalMacrosFile
    doctest $ "-isrc" : "-Iinclude" :
              (maybe [] (\ f -> ["-optP-include", "-optP" ++ f]) mCabalMacrosFile) ++
              "-XOverloadedStrings" :
              "-XFlexibleInstances" :
              "-XMultiParamTypeClasses" :
              (files ++ tfiles)

getCabalMacrosFile :: IO (Maybe FilePath)
getCabalMacrosFile = do
  exists <- doesDirectoryExist "dist-ghc"
  if exists
    then do
      contents <- getDirectoryContents "dist-ghc"
      let rest = "build" </> "autogen" </> "cabal_macros.h"
      whenExists $ case filter ("dist-sandbox-" `isPrefixOf`) contents of
        [x] -> "dist" </> x </> rest
        [] -> "dist-ghc" </> rest
        xs -> error $ "ran doctests with multiple dist/dist-sandbox-xxxxx's: \n"
                    ++ show xs ++ "\nTry cabal clean"
    else return Nothing
 where
  whenExists :: FilePath -> IO (Maybe FilePath)
  whenExists file = do
    exists <- doesFileExist file
    return $ if exists
      then Just file
      else Nothing