sbv-7.9: SBVTestSuite/SBVDocTest.hs
module Main (main) where
import System.FilePath.Glob (glob)
import Test.DocTest (doctest)
import Data.Char (toLower)
import Data.List (isSuffixOf)
import System.Exit (exitSuccess)
import Utils.SBVTestFramework (getTestEnvironment, TestEnvironment(..), CIOS(..))
import System.Random (randomRIO)
main :: IO ()
main = do (testEnv, testPercentage) <- getTestEnvironment
putStrLn $ "SBVDocTest: Test platform: " ++ show testEnv
case testEnv of
TestEnvLocal -> runDocTest False False 100
TestEnvCI env -> if testPercentage < 50
then do putStrLn $ "Test percentage below tresheold, skipping doctest: " ++ show testPercentage
exitSuccess
else runDocTest (env == CIWindows) True testPercentage
TestEnvUnknown -> do putStrLn "Unknown test environment, skipping doctests"
exitSuccess
where runDocTest onWindows onRemote tp = do srcFiles <- glob "Data/SBV/**/*.hs"
docFiles <- glob "Documentation/SBV/**/*.hs"
let allFiles = srcFiles ++ docFiles
testFiles = filter (\nm -> not (skipWindows nm || skipRemote nm)) allFiles
args = ["--fast", "--no-magic"]
tfs <- pickPercentage tp testFiles
doctest $ args ++ tfs
where skipWindows nm
| not onWindows = False
| True = -- The following test has a path encoded in its output, and hence fails on Windows
-- since it has the c:\blah\blah format. Skip it:
"nodiv0.hs" `isSuffixOf` map toLower nm
skipRemote nm
| not onRemote = False
| True = any (`isSuffixOf` map toLower nm) $ map (map toLower) skipList
where skipList = [ "Interpolants.hs" -- The following test requires mathSAT, so can't run on remote
, "HexPuzzle.hs" -- Doctest is way too slow on this with ghci loading, sigh
, "MultMask.hs" -- Also, quite slow
]
-- Pick (about) the given percentage of files
pickPercentage :: Int -> [String] -> IO [String]
pickPercentage 100 xs = return xs
pickPercentage 0 _ = return []
pickPercentage p xs = concat <$> mapM pick xs
where pick f = do c <- randomRIO (0, 100)
return [f | c >= p]