elixir-lang/elixir — pull request #1103 by mururu (2013-05-22 16:06:33+00:00)
Title: Capture_io can has mock input and ExUnit.Server stops when getting :eof as an input

discussing at #919

Using this patch, we can test IEx like the following.

```elixir
ExUnit.start []

defmodule IEx.InteractiveTest do
use ExUnit.Case, async: true

import ExUnit.CaptureIO

setup_all do
:application.start(:iex)
end

setup do
scope = :elixir.scope_for_eval(
file: "iex",
delegate_locals_to: IEx.Helpers
)

config=IEx.Config[
binding: [],
scope: scope,
]

{ :ok, config: config }
end

test "iex", context do
input = %B"""
a = 2
a + 3
"""
expect = %B"""
2
5
"""

assert capture_io(input, fn ->
IEx.Server.start(context[:config])
end) |> strip == expect
end

test "#iex:break", context do
input = %B"""
"a
#iex:break
"""

output = capture_io(input, fn ->
IEx.Server.start(context[:config])
end) |> strip

assert output =~ %r/TokenMissingError/
assert output =~ %r/incomplete expression/
end

defp strip(output) do
output |> String.split("\n") |> tl |> Enum.join("\n")
end
end
```