0 | module Evince.Rerun
 1 |
 2 | import Data.List
 3 | import Data.String
 4 | import System.File
 5 |
 6 | failureFilePath : String
 7 | failureFilePath = ".evince-failures"
 8 |
 9 | joinPath : List String -> String
10 | joinPath = concat . intersperse "."
11 |
12 | ||| Write failed test paths to the failure file. Deletes the file if
13 | ||| there are no failures (clean slate).
14 | export
15 | writeFailures : List (List String) -> IO ()
16 | writeFailures [] = do
17 |   _ <- removeFile failureFilePath
18 |   pure ()
19 | writeFailures paths = do
20 |   let content = unlines (map joinPath paths)
21 |   _ <- writeFile failureFilePath content
22 |   pure ()
23 |
24 | ||| Read previously failed test paths from the failure file.
25 | export
26 | readFailures : IO (Maybe (List String))
27 | readFailures = do
28 |   Right content <- readFile failureFilePath
29 |     | Left _ => pure Nothing
30 |   let paths = filter (/= "") (lines content)
31 |   pure (if null paths then Nothing else Just paths)
32 |