-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] |