module Test.Framework.Runners.XML (
produceReport
) where
import Test.Framework.Runners.Statistics ( testCountTotal, TestStatistics(..) )
import Test.Framework.Runners.Core ( FinishedTest )
import Test.Framework.Runners.XML.JUnitWriter ( RunDescription(..), serialize )
import Data.Time.Format ( formatTime )
import Data.Time.LocalTime ( getZonedTime )
#if MIN_VERSION_time(1,5,0)
import Data.Time.Format ( defaultTimeLocale )
#else
import System.Locale ( defaultTimeLocale )
#endif
import Network.HostName ( getHostName )
produceReport :: Bool -> TestStatistics -> [FinishedTest] -> IO String
produceReport nested test_statistics fin_tests = fmap (serialize nested) $ mergeResults test_statistics fin_tests
mergeResults :: TestStatistics -> [FinishedTest] -> IO RunDescription
mergeResults test_statistics fin_tests = do
host <- getHostName
theTime <- getZonedTime
return RunDescription {
errors = 0
, failedCount = testCountTotal (ts_failed_tests test_statistics)
, skipped = Nothing
, hostname = Just host
, suiteName = "test-framework tests"
, testCount = testCountTotal (ts_total_tests test_statistics)
, time = 0.0
, timeStamp = Just $ formatTime defaultTimeLocale "%a %B %e %k:%M:%S %Z %Y" theTime
, runId = Nothing
, package = Nothing
, tests = fin_tests
}