Skip to content

Commit a04e531

Browse files
committed
fix warnings in the test runner, fix #249
1 parent cde71de commit a04e531

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

gibbon-compiler/tests/TestRunner.hs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
{-# LANGUAGE NamedFieldPuns #-}
33
{-# LANGUAGE OverloadedStrings #-}
44
{-# LANGUAGE CPP #-}
5+
{-# LANGUAGE LambdaCase #-}
56
module TestRunner where
67

78
import Control.Monad
89
import Data.Maybe ( catMaybes )
910
import Data.Foldable
1011
import Data.List
1112
import Data.Scientific
12-
import Data.Text.Prettyprint.Doc
13-
import Data.Text.Prettyprint.Doc.Render.Terminal
13+
import Prettyprinter
14+
import Prettyprinter.Render.Terminal
1415
import Data.Time.LocalTime
1516
import Data.Yaml as Y
1617
import Options.Applicative as OA hiding (empty, str)
@@ -242,10 +243,13 @@ readBenchResult :: String -> BenchResult
242243
readBenchResult 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

Comments
 (0)