blob: d3fa71dec7becb2239b7a26fa52fa23200f70592 (
plain) (
blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import System.Cmd
import System.Environment
import System.FilePath
import System.Exit
import System.Directory
import Data.List
import Control.Monad
import Text.Printf
import Text.Regex
main = do
args <- getArgs
when (null args) $ error "You must give the path to the GHC lib dir as an argument"
putStrLn "Running tests..."
let libdir = head args
walkDirs libdir "."
putStrLn "All tests passed!"
haddockEq file1 file2 = (stripLinks file1) == (stripLinks file2)
where
stripLinks f = subRegex (mkRegexWithOpts "<A HREF=[^>]*>" False False) f "<A HREF=\"\">"
allModules dir = do
contents <- getDirectoryContents dir
return $ filter ((==) ".hs" . takeExtension) contents
check modules = do
forM_ modules $ \mod -> do
let outfile = "output" </> (dropExtension mod ++ ".html")
let reffile = dropExtension mod ++ ".html.ref"
b <- doesFileExist reffile
if b
then do
copyFile reffile ("output" </> reffile)
out <- readFile outfile
ref <- readFile reffile
if not $ haddockEq out ref
then do
putStrLn $ "Output for " ++ mod ++ " has changed! Exiting with diff:"
system $ "diff " ++ reffile ++ " " ++ outfile
exitFailure
else do
putStrLn $ "Pass: " ++ mod
else do
putStrLn $ "Pass: " ++ mod ++ " (no .ref file)"
walkDirs libdir basedir = do
contents <- getDirectoryContents basedir
dirs <- filterM doesDirectoryExist .
map (basedir </>) .
filter (`notElem` [".", "..", "output"]) $ contents
mapM_ (testDir libdir) dirs
testDir libdir dir = do
mods <- allModules dir
let mods' = map (dir </>) mods
let outdir = "output" </> dir
createDirectoryIfMissing True outdir
code <- system $ printf "haddock -B %s -o %s -h --optghc=-fglasgow-exts %s" libdir outdir (unwords mods')
unless (code == ExitSuccess) $ error "Haddock run failed! Exiting."
check mods'
walkDirs libdir dir
|