Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #!/usr/bin/env stack
  2. -- stack --resolver lts-8.11 --install-ghc runghc --package turtle --package text
  3.  
  4. {-
  5.  
  6. The MIT License (MIT)
  7.  
  8. Copyright (c) 2017 aiya000
  9.  
  10. Permission is hereby granted, free of charge, to any person obtaining a copy
  11. of this software and associated documentation files (the "Software"), to deal
  12. in the Software without restriction, including without limitation the rights
  13. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. copies of the Software, and to permit persons to whom the Software is
  15. furnished to do so, subject to the following conditions:
  16.  
  17. The above copyright notice and this permission notice shall be included in
  18. all copies or substantial portions of the Software.
  19.  
  20. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. THE SOFTWARE.
  27.  
  28. -}
  29.  
  30. {-# LANGUAGE FlexibleInstances #-}
  31. {-# LANGUAGE OverloadedStrings #-}
  32.  
  33. import Control.Monad
  34. import Data.List (foldl')
  35. import Turtle
  36. import qualified Data.Text as T
  37. import qualified Data.Text.IO as TIO
  38.  
  39.  
  40. main :: IO ()
  41. main = sh $ do
  42. (exitCode, out, err) <- procStrictWithErr "stack" ["test"] ""
  43. let result = out <> err
  44. if exitCode == ExitSuccess
  45. then void . notifySend $ "stack test is succeed: " <> result
  46. else do
  47. let blobs = cut sections result
  48. forM_ blobs $ \blob ->
  49. when (isErrorSection blob) . void $ notifySend blob
  50. where
  51. notifySend :: Text -> Shell ExitCode
  52. notifySend msg = proc "notify-send" ["notify-stack-test", msg] ""
  53.  
  54. sections :: Pattern ()
  55. sections = void $ do
  56. newline
  57. spaces
  58. newline
  59.  
  60. isErrorSection :: Text -> Bool
  61. isErrorSection x =
  62. let firstLine = head $ T.lines x
  63. in any (== "error:") $ T.words firstLine
  64.  
  65. -- "^.*\.hs:\w+:\w+: error:$"
  66. errorFormat :: Pattern ()
  67. errorFormat = do
  68. skip anyChar
  69. text ".hs:"
  70. skip digit
  71. text ": error:"
  72. eof
  73.  
  74.  
  75. -- vim:filetype=haskell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement