module Test.Framework.Providers.DocTest (docTest) where
import Documentation.Haddock
import qualified Test.DocTest as DocTest
import Test.Framework
import Test.Framework.Providers.HUnit
import Data.List(groupBy)
defaultOptions = RunnerOptions { ropt_threads = Nothing
, ropt_test_options = Nothing
, ropt_test_patterns = Nothing
, ropt_xml_output = Nothing
, ropt_plain_output = Nothing
, ropt_hide_successes = Nothing
}
docTest::[FilePath]
-> [String]
-> IO Test
docTest rootPaths options = do
tests <- DocTest.getDocTests ([Flag_Verbosity "0", Flag_NoWarnings] ++ map Flag_OptGhc options) rootPaths
return $ toTestFrameworkGroup (rootPaths ++ options) tests
toTestFrameworkTest :: [String] -> DocTest.DocTest -> Test
toTestFrameworkTest options test = testCase testName $ DocTest.withInterpreter options $ flip DocTest.toAssertion test
where
testName = DocTest.firstExpression test
toTestFrameworkGroup :: [String] -> [DocTest.DocTest] -> Test
toTestFrameworkGroup options examples = testGroup "DocTest" $ map fileTestGroup $ groupBy w examples
where
w left right = DocTest.sourcePath left == DocTest.sourcePath right
fileTestGroup examples = testGroup fileName $ toTestFrameworkTest options `map` examples
where
fileName = DocTest.sourcePath $ head $ examples