title: EUnit and io:format
body: <p>I want to test some third-party Erlang code using EUnit.</p>
  
  <p>The output from the code's functions is displayed to the standard output using <code>io:format/2</code>. I would like to capture that output and perform an <code>?assert</code> test on the string that would be printed out. I cannot modify the third-party code.</p>
  
  <p>Is the a way to do this with Erlang? (For instance, in Java I can simply use System.setOut() to an output stream).</p>
  
  <p><strong>Update:</strong> </p>
  
  <p>The <code>group_leader/2</code> seems to be on the right track. </p>
  
  <p>But, I still don't see how that allows me to capture the string printed by <code>io:format</code> so I can test my assertion. A very simplified example of the code is:</p>
  
  <pre><code>result(Value) -&gt;
      io:format("Result: ~w~n", [Value]).
  
  test_result() -&gt;
      ?assertMatch("Result: 5~n", result(5)).
  </code></pre>
  
  <p>Clearly, the return from function <code>result/1</code> is the atom <code>ok</code>, but I actually want to test the string that was output to the console (i.e. <code>"Result: 5~n"</code>).</p>
  
  <p>Am I wrong with this approach, because it seems nobody else does this (judging by my lack of search results)?</p>
  
  <p>Background: the third-party code is an interactive console application, so all of the  functions just use <code>io:format</code> to show results.  </p>