Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
turion committed Feb 13, 2024
1 parent 3cfcb8e commit dbd2cae
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions rhine/test/Clock/Except.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{-# LANGUAGE Arrows #-}
{-# LANGUAGE OverloadedStrings #-}

module Clock.Except where

-- base
import GHC.IO.Handle (hDuplicateTo)
import System.IO (IOMode (ReadMode), stdin, withFile)

-- transformers
import Control.Monad.Trans.Writer.CPS

-- text
import Data.Text (Text)

-- tasty
import Test.Tasty (testGroup)

-- tasty-hunit
import Test.Tasty.HUnit (testCase, (@?))

-- rhine
import FRP.Rhine
import FRP.Rhine.Clock.Except (CatchClock (CatchClock), ExceptClock (ExceptClock))
import Paths_rhine
import System.IO.Error (isEOFError)

type E = ExceptT IOError IO
type WT = WriterT [Text]
type M = WT E
type EClock = ExceptClock StdinClock IOError


type TestClock =
LiftClock
E
WT
( CatchClock
EClock
IOError
EClock
IOError
)

-- FIXME also need to test the other branch of CatchClock
testClock :: TestClock
testClock = liftClock $ CatchClock (ExceptClock StdinClock) $ const $ Right $ ExceptClock StdinClock

clsf :: ClSF M TestClock () ()
clsf = proc () -> do
tag <- tagS -< ()
arrMCl tell -< either (const ["weird"]) pure tag

tests =
testGroup
"ExceptClock"
[ testCase "Outputs the exception on EOF" $ do
testdataFile <- getDataFileName "test/assets/testdata.txt"
withFile testdataFile ReadMode $ \h -> do
hDuplicateTo h stdin
Left result <- runExceptT $ runWriterT $ flow $ clsf @@ testClock
isEOFError result @? "It's an EOF error"
]

0 comments on commit dbd2cae

Please sign in to comment.