Safe Haskell | None |
---|---|
Language | Haskell2010 |
- Module: Reflex.Process.Repl
- Description: Run repl-like processes in a reflex application.
Synopsis
- data Repl t = Repl {
- _repl_process :: Process t ByteString ByteString
- _repl_finished :: Event t (Map Int Cmd)
- _repl_started :: Dynamic t (Int, Maybe Cmd)
- _repl_exited :: Event t ExitCode
- data Cmd = Cmd {}
- data Accum = Accum {}
- accumHandle :: (Int -> ByteString -> Bool) -> ByteString -> (Map Int Lines, Int, Lines) -> (Map Int Lines, Int, Lines)
- accumHandles :: (Int -> ByteString -> Bool) -> These ByteString ByteString -> Accum -> Accum
- flushAccum :: Accum -> Accum
- repl :: forall t m. (Adjustable t m, MonadFix m, MonadHold t m, MonadIO (Performable m), MonadIO m, NotReady t m, PerformEvent t m, PostBuild t m, TriggerEvent t m) => CreateProcess -> Event t [Command] -> (Int -> ByteString -> Bool) -> m (Repl t)
- data Lines = Lines {}
- emptyLines :: Lines
- addLines :: ByteString -> Lines -> Lines
- linesFromBS :: ByteString -> Lines
- unLines :: Lines -> ByteString
- lastWholeLine :: Lines -> Maybe ByteString
- splitLinesOn :: (ByteString -> Bool) -> Lines -> Maybe (Lines, Lines)
- data Command
- unsafeCommand :: ByteString -> Command
- command :: ByteString -> [Command]
- commands :: [ByteString] -> [Command]
- displayCommand :: Command -> ByteString
- sendCommands :: [Command] -> Maybe (SendPipe ByteString)
- testRepl :: IO ()
- mkTestCommands :: (PerformEvent t m, PostBuild t m, TriggerEvent t m, MonadIO (Performable m)) => m (Event t [Command])
- assertStdoutEq :: MonadIO m => String -> Maybe Cmd -> ByteString -> m Bool
- assertStderrEq :: MonadIO m => String -> Maybe Cmd -> ByteString -> m Bool
- assertStderr :: MonadIO m => String -> Maybe Cmd -> (Lines -> Bool) -> m Bool
- assertStdout :: MonadIO m => String -> Maybe Cmd -> (Lines -> Bool) -> m Bool
- assertHandleEq :: MonadIO m => (Cmd -> Lines) -> String -> Maybe Cmd -> ByteString -> m Bool
- assertHandle :: MonadIO m => (Cmd -> Lines) -> String -> Maybe Cmd -> (Lines -> Bool) -> m Bool
- assertCmd :: MonadIO m => String -> Maybe Cmd -> (Cmd -> Bool) -> m Bool
Documentation
Output of a repl
session
Repl | |
|
An individual command submitted to the repl, and its output
Cmd | |
|
An accumulator used to track and combine the repl's output streams
accumHandle :: (Int -> ByteString -> Bool) -> ByteString -> (Map Int Lines, Int, Lines) -> (Map Int Lines, Int, Lines) Source #
Accumulate a handle, grouping its output by prompts
accumHandles :: (Int -> ByteString -> Bool) -> These ByteString ByteString -> Accum -> Accum Source #
Accumulate the output of stdout and stderr, grouping the output lines of both by prompt
flushAccum :: Accum -> Accum Source #
Take all the pending output and consider it complete.
:: forall t m. (Adjustable t m, MonadFix m, MonadHold t m, MonadIO (Performable m), MonadIO m, NotReady t m, PerformEvent t m, PostBuild t m, TriggerEvent t m) | |
=> CreateProcess | Command to run to enter repl |
-> Event t [Command] | Commands to send to the repl |
-> (Int -> ByteString -> Bool) | Test for determining whether a line is the prompt we're waiting or |
-> m (Repl t) |
Run a repl, feed it commands, and produce output grouped by those commands. The repl in question must be able to print its prompt on both stdout and stderr.
Accumulator for line-based output that keeps track of any dangling, unterminated line
emptyLines :: Lines Source #
Empty output
addLines :: ByteString -> Lines -> Lines Source #
Add some raw output to a Lines
. This will chop the raw output up into lines.
linesFromBS :: ByteString -> Lines Source #
Convert a ByteString
into a Lines
unLines :: Lines -> ByteString Source #
Convert a Lines
back into a ByteString
lastWholeLine :: Lines -> Maybe ByteString Source #
Convenience accessor for the last whole line received by a Lines
.
Ignores any unterminated line that may follow.
splitLinesOn :: (ByteString -> Bool) -> Lines -> Maybe (Lines, Lines) Source #
Split lines into two. The sequence that satisfies the predicate is
consumed and will not appear in either resulting Lines
.
A string that will be sent to the repl for evaluation. A newline will be
appended to the end of the string. Command
s should not themselves contain newlines.
Instances
Eq Command Source # | |
Ord Command Source # | |
Read Command Source # | |
Show Command Source # | |
unsafeCommand :: ByteString -> Command Source #
Constructs a Command
without checking for newlines. If there are
newlines in the input, things will not work properly.
command :: ByteString -> [Command] Source #
Convert a ByteString
into a set of Command
s. Any newlines found in the
input are considered Command
separators.
commands :: [ByteString] -> [Command] Source #
Convert a ByteString
into a set of Command
s. Any newlines found in the
input are considered Command
separators.
displayCommand :: Command -> ByteString Source #
Turn a command back into a ByteString
.
sendCommands :: [Command] -> Maybe (SendPipe ByteString) Source #
Convert commands to a format that can be sent over stdin
A headless repl test that runs ghci, executes some commands, and checks that the output is as expected.
mkTestCommands :: (PerformEvent t m, PostBuild t m, TriggerEvent t m, MonadIO (Performable m)) => m (Event t [Command]) Source #
Constructs some testing commands that are fed in on a timer
assertStdoutEq :: MonadIO m => String -> Maybe Cmd -> ByteString -> m Bool Source #
Check that stdout equals the given value
assertStderrEq :: MonadIO m => String -> Maybe Cmd -> ByteString -> m Bool Source #
Check that stderr equals the given value
assertStderr :: MonadIO m => String -> Maybe Cmd -> (Lines -> Bool) -> m Bool Source #
Test the contents of stderr
assertStdout :: MonadIO m => String -> Maybe Cmd -> (Lines -> Bool) -> m Bool Source #
Test the contents of stdout
assertHandleEq :: MonadIO m => (Cmd -> Lines) -> String -> Maybe Cmd -> ByteString -> m Bool Source #
Check that a handle equals the given value