Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. {-# LANGUAGE RecordWildCards #-}
  2. {-# LANGUAGE OverloadedStrings #-}
  3.  
  4. module ParseValidate
  5. ( parseLog
  6. , TestFailure(..)
  7. , ValidateLog(..)
  8. ) where
  9.  
  10. import Text.Trifecta
  11. import Text.Trifecta.Delta
  12. import qualified Data.Text as T
  13. import Data.Text (Text)
  14.  
  15. data TestFailure = TestFailure { testCategory :: Text
  16. , testName :: Text
  17. , reason :: Text
  18. , failedWays :: [Text]
  19. }
  20. deriving (Show)
  21.  
  22. data ValidateLog = ValidateLog { failures :: [TestFailure]
  23. , statFailures :: [TestFailure]
  24. }
  25. deriving (Show)
  26.  
  27. parseLog :: Text -> ValidateLog
  28. parseLog log =
  29. vlog
  30. where
  31. -- Only look in the last few kilobytes of the log for the beginning of the
  32. -- testsuite results
  33. testsuiteLines :: [Text]
  34. testsuiteLines = map T.strip
  35. $ dropWhile (not . T.isPrefixOf "OVERALL SUMMARY") $ T.lines $ T.takeEnd 40000 log
  36.  
  37. failures = map parseFailure $ stanza "Unexpected failures"
  38. statFailures = map parseFailure $ stanza "Unexpected stat failures"
  39.  
  40. -- A group of lines starting with string and ending with a blank line
  41. stanza :: Text -> [Text]
  42. stanza start =
  43. takeWhile (not . T.null . T.strip)
  44. $ drop 1 $ dropWhile (not . T.isPrefixOf start)
  45. $ testsuiteLines
  46.  
  47. parseFailure :: Text -> Maybe TestFailure
  48. parseFailure line =
  49. case parseString testFailure delta (T.unpack line) of
  50. Success r -> r
  51. Failure doc -> error $ show doc
  52. where
  53. delta = Columns 0 0
  54.  
  55. vlog = ValidateLog {..}
  56.  
  57.  
  58. testFailure :: Parser TestFailure
  59. testFailure = do
  60. spaces
  61. testCategory <- T.pack <$> manyTill anyChar space
  62. spaces
  63. testName <- T.pack <$> manyTill anyChar space
  64. spaces
  65. char '['
  66. reason <- T.pack <$> manyTill anyChar (char ']')
  67. spaces
  68. char '('
  69. failedWays <- sepBy (T.pack <$> many (noneOf ",)")) (char ',')
  70. char ')'
  71. return TestFailure{..}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement