[erlang-questions] how to run PropEr tests from Eunit?

Motiejus Jakštys <>
Wed Aug 10 09:50:47 CEST 2011


On Tue, Aug 09, 2011 at 06:53:09AM -0400, Frédéric Trottier-Hébert
wrote:
> The Group Leader is a special concept. In each process' metadata,
> there is an entry for a group leader. The group leader, at the moment,
> is a Pid that is in charge of handling IO requests using the IO
> protocol (http://www.erlang.org/doc/apps/stdlib/io_protocol.html).
> This group leader is the 'user' process by default (that's its
> registered name). When you send io requests to the user process, the
> output gets printed to the shell.
> 
> By default, all processes get the 'user' group leader -- this is set
> through inheritance when spawning a process. The exception to that is
> when you're using OTP application. Then the Application Master (a
> process spawned by the application controller) sets itself as a
> middleman between the user process and your own processes. That lets
> OTP create process groups to shut down in case it's needed.
> 
> In any case, applications like EUnit have decided to overwrite these
> default group leaders and make their own -- this lets them capture
> input the way they want to work with it, log it, or just hide it. This
> makes some macros such as 'assertCmdOutput(Text, CommandString)' work.
> To bypass this, the framework then gives macros like ?debugVal(Val)
> and ?debugMsg(Text) to the programmer. All these macros do is
> something like 'io:format(user, String, Args)'. 
> 
> That's because adding a first argument of this kind lets you redirect
> IO to an io-device (file descriptor, group leader, etc.). You can,
> however, use the following functions to just plainly overwrite the
> group leader back to something new:
> 
> http://erldocs.com/R14B02/erts/erlang.html?i=0&search=group_leader#group_leader/0
> http://erldocs.com/R14B02/erts/erlang.html?i=1&search=group_leader#group_leader/2
> 
> You could do something such as:
> 
> run_proper_test_() -> EunitLeader = erlang:group_leader(),
> erlang:group_leader(whereis(user), self()), Res =
> proper:module(?MODULE), erlang:group_leader(EunitLeader, self()),
> ?_assertEqual([], Res).
> 
> (untested). This would temporarily switch the group leader of the test
> for the time being before setting it back to whatever it was after. So
> for the time PropEr tests are running you get regular output, and then
> it gets back to Eunit-normal afterwards.
> 
> Hope this helps.
> 
> -- Fred Hébert http://www.erlang-solutions.com
> 

Thank you. It worked great!

Motiejus



More information about the erlang-questions mailing list