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 | ||| Render a test path in the dot-joined format used by the failure file.
10 | export
11 | joinPath : List String -> String
12 | joinPath = concat . intersperse "."
13 |
14 | ||| Write failed test paths to the failure file. Deletes the file if
15 | ||| there are no failures (clean slate).
16 | export
17 | writeFailures : List (List String) -> IO ()
18 | writeFailures [] = do
19 |   _ <- removeFile failureFilePath
20 |   pure ()
21 | writeFailures paths = do
22 |   let content = unlines (map joinPath paths)
23 |   _ <- writeFile failureFilePath content
24 |   pure ()
25 |
26 | ||| Read previously failed test paths from the failure file.
27 | export
28 | readFailures : IO (Maybe (List String))
29 | readFailures = do
30 |   Right content <- readFile failureFilePath
31 |     | Left _ => pure Nothing
32 |   let paths = filter (/= "") (lines content)
33 |   pure (if null paths then Nothing else Just paths)
34 |