I want to test some third-party Erlang code using EUnit.

The output from the code's functions is displayed to the standard output using `io:format/2`. I would like to capture that output and perform an `?assert` test on the string that would be printed out. I cannot modify the third-party code.

Is the a way to do this with Erlang? (For instance, in Java I can simply use System.setOut() to an output stream).

**Update:** 

The `group_leader/2` seems to be on the right track. 

But, I still don't see how that allows me to capture the string printed by `io:format` so I can test my assertion. A very simplified example of the code is:

```
result(Value) ->
    io:format("Result: ~w~n", [Value]).

test_result() ->
    ?assertMatch("Result: 5~n", result(5)).

```

Clearly, the return from function `result/1` is the atom `ok`, but I actually want to test the string that was output to the console (i.e. `"Result: 5~n"`).

Am I wrong with this approach, because it seems nobody else does this (judging by my lack of search results)?

Background: the third-party code is an interactive console application, so all of the functions just use `io:format` to show results.