[erlang-questions] how to run PropEr tests from Eunit?
Tue Aug 9 12:53:09 CEST 2011
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:
You could do something such as:
EunitLeader = erlang:group_leader(),
Res = proper:module(?MODULE),
(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.
On 2011-08-09, at 02:27 AM, Motiejus Jakštys wrote:
> On Mon, Jul 25, 2011 at 08:59:22AM -0400, Fred Hebert wrote:
>> You can just change the process' group leader back to the 'user' process (or
>> any other process depending on your app) from within the test, and then set
>> it back to what it was before using erlang:group_leader/0 and
> Could you elaborate more on this? I couldn't figure out how to create a
> new group leader (erlang manpage does not say much). An example would be
> very helpful.
> Thank you.
> erlang-questions mailing list
More information about the erlang-questions