Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExUnit should implement the io protocol #1035

Closed
josevalim opened this issue May 8, 2013 · 1 comment · Fixed by #1059
Closed

ExUnit should implement the io protocol #1035

josevalim opened this issue May 8, 2013 · 1 comment · Fixed by #1059

Comments

@josevalim
Copy link
Member

It is common for Elixir code to output something to the CLI. Those, however, become non-trivial to test since we don't provide a mechanism to capture IO.

Luckily, all the IO in Erlang is done via the IO protocol, which means we can replace the Erlang group leader and capture the IO. This will make it possible to test many warnings in Elixir, test IEx.Helpers and more.

This is a proposal for adding a function called capture_io/1 to ExUnit.Assertions (or maybe ExUnit.Helpers) that receives a function and while it executes the function, all the output is captured (and the input is mocked to return nothing so far):

assert capture_io(fn ->
  Code.eval "some code that emits a warning"
end) =~ %r/got warning/

To implement capture_io/1, we need to take a better look at the "IO protocol". Luckily, the eunit test framework in Erlang implements it too, so we can always take a look at it for clues.

@mururu
Copy link
Contributor

mururu commented May 9, 2013

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants