Skip to content

Commit

Permalink
fix warnings in the test runner, fix #249
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses4ever committed Jan 31, 2024
1 parent cde71de commit 7ccac95
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions gibbon-compiler/tests/TestRunner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
module TestRunner where

import Control.Monad
import Data.Maybe ( catMaybes )
import Data.Foldable
import Data.List
import Data.Scientific
import Data.Text.Prettyprint.Doc
import Data.Text.Prettyprint.Doc.Render.Terminal
import Prettyprinter
import Prettyprinter.Render.Terminal
import Data.Time.LocalTime
import Data.Yaml as Y
import Options.Applicative as OA hiding (empty, str)
Expand Down Expand Up @@ -242,10 +243,13 @@ readBenchResult :: String -> BenchResult
readBenchResult str =
case selftimed_indices of
[] -> error $ "no SELFTIMED found in:\n" ++ show str
[one] -> let (selftimed:_) = lines (drop one str)
[one] -> let selftimed = case lines (drop one str) of
st:_ -> st
[] -> error "impossible" -- if we get here, the line is non-empty (cf. [one]),
-- and `lines` never returns [] on such input
timing_info = selftimed \\ "SELFTIMED: "
in BenchResult (toRealFloat $ read timing_info)
oth -> error $ "multiple SELFTIMED found in:\n" ++ show str
_ -> error $ "multiple SELFTIMED found in:\n" ++ show str
where
selftimed_indices = T.indices "SELFTIMED: " (T.pack str)

Expand All @@ -264,8 +268,14 @@ readPerfFile fp = do
str <- readFile fp
let stanza_indices = findIndices (== 'X') str
pairs = partition' 2 1 (stanza_indices ++ [length str])
stanzas = map (\[a,b] -> drop a $ take b str) pairs
perf_res = map (\(h:_:br) -> (readHeader h, readBenchResult (intercalate "\n" br))) $
stanzas = map (\case
[a,b] -> drop a $ take b str
_ -> error "readPerfFile: incomplete pattern matching parsing stanzas"
) pairs
perf_res = map (\case
(h:_:br) -> (readHeader h, readBenchResult (intercalate "\n" br))
_ -> error "readPerfFile: incomplete pattern matching parsing perf result"
) $
map lines stanzas
return $ M.fromList perf_res

Expand Down

0 comments on commit 7ccac95

Please sign in to comment.