22{-# LANGUAGE NamedFieldPuns #-}
33{-# LANGUAGE OverloadedStrings #-}
44{-# LANGUAGE CPP #-}
5+ {-# LANGUAGE LambdaCase #-}
56module TestRunner where
67
78import Control.Monad
89import Data.Maybe ( catMaybes )
910import Data.Foldable
1011import Data.List
1112import Data.Scientific
12- import Data.Text.Prettyprint.Doc
13- import Data.Text.Prettyprint.Doc .Render.Terminal
13+ import Prettyprinter
14+ import Prettyprinter .Render.Terminal
1415import Data.Time.LocalTime
1516import Data.Yaml as Y
1617import Options.Applicative as OA hiding (empty , str )
@@ -242,10 +243,13 @@ readBenchResult :: String -> BenchResult
242243readBenchResult str =
243244 case selftimed_indices of
244245 [] -> error $ " no SELFTIMED found in:\n " ++ show str
245- [one] -> let (selftimed: _) = lines (drop one str)
246+ [one] -> let selftimed = case lines (drop one str) of
247+ st: _ -> st
248+ [] -> error " impossible" -- if we get here, the line is non-empty (cf. [one]),
249+ -- and `lines` never returns [] on such input
246250 timing_info = selftimed \\ " SELFTIMED: "
247251 in BenchResult (toRealFloat $ read timing_info)
248- oth -> error $ " multiple SELFTIMED found in:\n " ++ show str
252+ _ -> error $ " multiple SELFTIMED found in:\n " ++ show str
249253 where
250254 selftimed_indices = T. indices " SELFTIMED: " (T. pack str)
251255
@@ -264,8 +268,14 @@ readPerfFile fp = do
264268 str <- readFile fp
265269 let stanza_indices = findIndices (== ' X' ) str
266270 pairs = partition' 2 1 (stanza_indices ++ [length str])
267- stanzas = map (\ [a,b] -> drop a $ take b str) pairs
268- perf_res = map (\ (h: _: br) -> (readHeader h, readBenchResult (intercalate " \n " br))) $
271+ stanzas = map (\ case
272+ [a,b] -> drop a $ take b str
273+ _ -> error " readPerfFile: incomplete pattern matching parsing stanzas"
274+ ) pairs
275+ perf_res = map (\ case
276+ (h: _: br) -> (readHeader h, readBenchResult (intercalate " \n " br))
277+ _ -> error " readPerfFile: incomplete pattern matching parsing perf result"
278+ ) $
269279 map lines stanzas
270280 return $ M. fromList perf_res
271281
0 commit comments