how to run PropEr tests from Eunit?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

how to run PropEr tests from Eunit?

Roman Shestakov
hello,

I am trying to run PropEr tests from Eunit and I must admit, I can't figure out how to run them


lets say I want to test the following three functions

%%--------------------------------------------------------------------
%% @doc
%% convert Date to atom
%% @end
%%--------------------------------------------------------------------
-spec date_to_atom(date()) -> atom().
date_to_atom({Year, Month, Day}) ->
   list_to_atom(date_to_string({Year, Month, Day})).

%%--------------------------------------------------------------------
%% @doc
%% Convert Date to string
%% @end
%%--------------------------------------------------------------------
-spec date_to_string(date()) -> string().
date_to_string({Year, Month, Day}) ->
   lists:flatten(io_lib:format("~4.10.0B~2.10.0B~2.10.0B", [Year, Month, Day])).


%%--------------------------------------------------------------------
%% @doc
%% convert Date represented as atom into Erlang date format
%% @end
%%--------------------------------------------------------------------
-spec atom_to_date(atom()) -> date().
atom_to_date(Date) ->
   Year = list_to_integer(lists:sublist(atom_to_list(Date),1,4)),
   Month = list_to_integer(lists:sublist(atom_to_list(Date),5,2)),
   Day = list_to_integer(lists:sublist(atom_to_list(Date),7,2)),
   {Year, Month, Day}.



with the following property:

proper_time_to_atom() ->
   ?FORALL(Date, date(),
        begin
        EncDate = ec_time_fns:atom_to_date(ec_time_fns:date_to_atom(Date)),
        EncDate =:= Date
        end).
             
running the following from erl works fine
proper:quickcheck(ec_time_fns_tests:proper_time_to_atom()).


but how do I make eunit to run these test?


tried this , but it doesn't seem to work

time_to_atom_test_() ->
   ?_test(proper:quickcheck(proper_time_to_atom())).


any ideas?

Regards, Roman


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to run PropEr tests from Eunit?

Frédéric Trottier-Hébert
<base href="x-msg://2/">The simplest way I know to do them individually is with separate tests:

proper_test_() ->
    [?_assert(proper:quickcheck(prop_some_property())),
     ?_assert(proper:quickcheck(prop_some_property())),
     ...].

You can then create macros to do it for you of the form

-define(PROPTEST(A), ?_assert(proper:quickcheck(A()))).

and then call

proper_test_() ->
    [?PROPTEST(prop_something), ?PROPTEST(prop_something_else),
     ?PROPTEST(prop_other), ?PROPTEST(prop_last)].

or whatever you feel like.

If you want to run them all, make sure your module's properties all start with the prefix 'prop_'. Then you can do something like

proper_test() ->
    [] = proper:module(?MODULE).

which will find all the properties of the current module and run them for you. Also, don't forget to always include the proper include file first, because both PropEr and EUnit define a LET macro, but the PropEr one is the only one I've seen actively used.

On 2011-06-23, at 18:12 PM, Roman Shestakov wrote:

hello,

I am trying to run PropEr tests from Eunit and I must admit, I can't figure out how to run them


lets say I want to test the following three functions

%%--------------------------------------------------------------------
%% @doc
%% convert Date to atom
%% @end
%%--------------------------------------------------------------------
-spec date_to_atom(date()) -> atom().
date_to_atom({Year, Month, Day}) ->
   list_to_atom(date_to_string({Year, Month, Day})).

%%--------------------------------------------------------------------
%% @doc
%% Convert Date to string
%% @end
%%--------------------------------------------------------------------
-spec date_to_string(date()) -> string().
date_to_string({Year, Month, Day}) ->
   lists:flatten(io_lib:format("~4.10.0B~2.10.0B~2.10.0B", [Year, Month, Day])).


%%--------------------------------------------------------------------
%% @doc
%% convert Date represented as atom into Erlang date format
%% @end
%%--------------------------------------------------------------------
-spec atom_to_date(atom()) -> date().
atom_to_date(Date) ->
   Year = list_to_integer(lists:sublist(atom_to_list(Date),1,4)),
   Month = list_to_integer(lists:sublist(atom_to_list(Date),5,2)),
   Day = list_to_integer(lists:sublist(atom_to_list(Date),7,2)),
   {Year, Month, Day}.



with the following property:

proper_time_to_atom() ->
   ?FORALL(Date, date(),
        begin
        EncDate = ec_time_fns:atom_to_date(ec_time_fns:date_to_atom(Date)),
        EncDate =:= Date
        end).
              
running the following from erl works fine
proper:quickcheck(ec_time_fns_tests:proper_time_to_atom()).


but how do I make eunit to run these test?


tried this , but it doesn't seem to work

time_to_atom_test_() ->
   ?_test(proper:quickcheck(proper_time_to_atom())).


any ideas?

Regards, Roman

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to run PropEr tests from Eunit?

Bob Ippolito
This is what I've been using:

proper_test_() ->
    [{atom_to_list(F),
      fun () -> ?assert(proper:quickcheck(?MODULE:F(), [long_result])) end}
     || {F, 0} <- ?MODULE:module_info(exports), F > 'prop_', F < 'prop`'].

2011/6/23 Frédéric Trottier-Hébert <[hidden email]>:

> The simplest way I know to do them individually is with separate tests:
> proper_test_() ->
>     [?_assert(proper:quickcheck(prop_some_property())),
>      ?_assert(proper:quickcheck(prop_some_property())),
>      ...].
> You can then create macros to do it for you of the form
> -define(PROPTEST(A), ?_assert(proper:quickcheck(A()))).
> and then call
> proper_test_() ->
>     [?PROPTEST(prop_something), ?PROPTEST(prop_something_else),
>      ?PROPTEST(prop_other), ?PROPTEST(prop_last)].
> or whatever you feel like.
> If you want to run them all, make sure your module's properties all start
> with the prefix 'prop_'. Then you can do something like
> proper_test() ->
>     [] = proper:module(?MODULE).
> which will find all the properties of the current module and run them for
> you. Also, don't forget to always include the proper include file first,
> because both PropEr and EUnit define a LET macro, but the PropEr one is the
> only one I've seen actively used.
>
> --
> Fred Hébert
> http://www.erlang-solutions.com
>
>
> On 2011-06-23, at 18:12 PM, Roman Shestakov wrote:
>
> hello,
>
> I am trying to run PropEr tests from Eunit and I must admit, I can't figure
> out how to run them
>
>
> lets say I want to test the following three functions
>
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date to atom
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_atom(date()) -> atom().
> date_to_atom({Year, Month, Day}) ->
>    list_to_atom(date_to_string({Year, Month, Day})).
>
> %%--------------------------------------------------------------------
> %% @doc
> %% Convert Date to string
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_string(date()) -> string().
> date_to_string({Year, Month, Day}) ->
>    lists:flatten(io_lib:format("~4.10.0B~2.10.0B~2.10.0B", [Year, Month,
> Day])).
>
>
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date represented as atom into Erlang date format
> %% @end
> %%--------------------------------------------------------------------
> -spec atom_to_date(atom()) -> date().
> atom_to_date(Date) ->
>    Year = list_to_integer(lists:sublist(atom_to_list(Date),1,4)),
>    Month = list_to_integer(lists:sublist(atom_to_list(Date),5,2)),
>    Day = list_to_integer(lists:sublist(atom_to_list(Date),7,2)),
>    {Year, Month, Day}.
>
>
>
> with the following property:
>
> proper_time_to_atom() ->
>    ?FORALL(Date, date(),
>         begin
>         EncDate = ec_time_fns:atom_to_date(ec_time_fns:date_to_atom(Date)),
>         EncDate =:= Date
>         end).
>
> running the following from erl works fine
> proper:quickcheck(ec_time_fns_tests:proper_time_to_atom()).
>
>
> but how do I make eunit to run these test?
>
>
> tried this , but it doesn't seem to work
>
> time_to_atom_test_() ->
>    ?_test(proper:quickcheck(proper_time_to_atom())).
>
>
> any ideas?
>
> Regards, Roman
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to run PropEr tests from Eunit?

Roman Shestakov
thanks a lot Bob, this is very helpful
Regards, Roman


From: Bob Ippolito <[hidden email]>
To: Frédéric Trottier-Hébert <[hidden email]>
Cc: Roman Shestakov <[hidden email]>; [hidden email]
Sent: Fri, 24 June, 2011 18:05:37
Subject: Re: [erlang-questions] how to run PropEr tests from Eunit?

This is what I've been using:

proper_test_() ->
    [{atom_to_list(F),
      fun () -> ?assert(proper:quickcheck(?MODULE:F(), [long_result])) end}
    || {F, 0} <- ?MODULE:module_info(exports), F > 'prop_', F < 'prop`'].

2011/6/23 Frédéric Trottier-Hébert <[hidden email]>:

> The simplest way I know to do them individually is with separate tests:
> proper_test_() ->
>     [?_assert(proper:quickcheck(prop_some_property())),
>      ?_assert(proper:quickcheck(prop_some_property())),
>      ...].
> You can then create macros to do it for you of the form
> -define(PROPTEST(A), ?_assert(proper:quickcheck(A()))).
> and then call
> proper_test_() ->
>     [?PROPTEST(prop_something), ?PROPTEST(prop_something_else),
>      ?PROPTEST(prop_other), ?PROPTEST(prop_last)].
> or whatever you feel like.
> If you want to run them all, make sure your module's properties all start
> with the prefix 'prop_'. Then you can do something like
> proper_test() ->
>     [] = proper:module(?MODULE).
> which will find all the properties of the current module and run them for
> you. Also, don't forget to always include the proper include file first,
> because both PropEr and EUnit define a LET macro, but the PropEr one is the
> only one I've seen actively used.
>
> --
> Fred Hébert
> http://www.erlang-solutions.com
>
>
> On 2011-06-23, at 18:12 PM, Roman Shestakov wrote:
>
> hello,
>
> I am trying to run PropEr tests from Eunit and I must admit, I can't figure
> out how to run them
>
>
> lets say I want to test the following three functions
>
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date to atom
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_atom(date()) -> atom().
> date_to_atom({Year, Month, Day}) ->
>    list_to_atom(date_to_string({Year, Month, Day})).
>
> %%--------------------------------------------------------------------
> %% @doc
> %% Convert Date to string
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_string(date()) -> string().
> date_to_string({Year, Month, Day}) ->
>    lists:flatten(io_lib:format("~4.10.0B~2.10.0B~2.10.0B", [Year, Month,
> Day])).
>
>
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date represented as atom into Erlang date format
> %% @end
> %%--------------------------------------------------------------------
> -spec atom_to_date(atom()) -> date().
> atom_to_date(Date) ->
>    Year = list_to_integer(lists:sublist(atom_to_list(Date),1,4)),
>    Month = list_to_integer(lists:sublist(atom_to_list(Date),5,2)),
>    Day = list_to_integer(lists:sublist(atom_to_list(Date),7,2)),
>    {Year, Month, Day}.
>
>
>
> with the following property:
>
> proper_time_to_atom() ->
>    ?FORALL(Date, date(),
>         begin
>         EncDate = ec_time_fns:atom_to_date(ec_time_fns:date_to_atom(Date)),
>         EncDate =:= Date
>         end).
>
> running the following from erl works fine
> proper:quickcheck(ec_time_fns_tests:proper_time_to_atom()).
>
>
> but how do I make eunit to run these test?
>
>
> tried this , but it doesn't seem to work
>
> time_to_atom_test_() ->
>    ?_test(proper:quickcheck(proper_time_to_atom())).
>
>
> any ideas?
>
> Regards, Roman
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
>

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to run PropEr tests from Eunit?

Paul Peregud-2
I wonder how did you solve the issue with eunit hiding output from PropEr?

I do following on test setup:

    meck:new(io, [unstick, passthrough]),
    meck:expect(io, fwrite, fun
                                (FString, Args) -> meck:passthrough([user, FString, Args])
                            end)

This approach is ugly and also very slow. Does anyone have a better solution?

Best,
PP.



2011/6/24 Roman Shestakov <[hidden email]>
thanks a lot Bob, this is very helpful
Regards, Roman


From: Bob Ippolito <[hidden email]>
To: Frédéric Trottier-Hébert <[hidden email]>
Cc: Roman Shestakov <[hidden email]>; [hidden email]
Sent: Fri, 24 June, 2011 18:05:37
Subject: Re: [erlang-questions] how to run PropEr tests from Eunit?

This is what I've been using:

proper_test_() ->
    [{atom_to_list(F),
      fun () -> ?assert(proper:quickcheck(?MODULE:F(), [long_result])) end}
    || {F, 0} <- ?MODULE:module_info(exports), F > 'prop_', F < 'prop`'].

2011/6/23 Frédéric Trottier-Hébert <[hidden email]>:
> The simplest way I know to do them individually is with separate tests:
> proper_test_() ->
>     [?_assert(proper:quickcheck(prop_some_property())),
>      ?_assert(proper:quickcheck(prop_some_property())),
>      ...].
> You can then create macros to do it for you of the form
> -define(PROPTEST(A), ?_assert(proper:quickcheck(A()))).
> and then call
> proper_test_() ->
>     [?PROPTEST(prop_something), ?PROPTEST(prop_something_else),
>      ?PROPTEST(prop_other), ?PROPTEST(prop_last)].
> or whatever you feel like.
> If you want to run them all, make sure your module's properties all start
> with the prefix 'prop_'. Then you can do something like
> proper_test() ->
>     [] = proper:module(?MODULE).
> which will find all the properties of the current module and run them for
> you. Also, don't forget to always include the proper include file first,
> because both PropEr and EUnit define a LET macro, but the PropEr one is the
> only one I've seen actively used.
>
> --

> Fred Hébert
> http://www.erlang-solutions.com
>
>
> On 2011-06-23, at 18:12 PM, Roman Shestakov wrote:
>
> hello,
>
> I am trying to run PropEr tests from Eunit and I must admit, I can't figure
> out how to run them
>
>
> lets say I want to test the following three functions
>
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date to atom
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_atom(date()) -> atom().
> date_to_atom({Year, Month, Day}) ->
>    list_to_atom(date_to_string({Year, Month, Day})).
>
> %%--------------------------------------------------------------------
> %% @doc
> %% Convert Date to string
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_string(date()) -> string().
> date_to_string({Year, Month, Day}) ->
>    lists:flatten(io_lib:format("~4.10.0B~2.10.0B~2.10.0B", [Year, Month,
> Day])).
>
>
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date represented as atom into Erlang date format
> %% @end
> %%--------------------------------------------------------------------
> -spec atom_to_date(atom()) -> date().
> atom_to_date(Date) ->
>    Year = list_to_integer(lists:sublist(atom_to_list(Date),1,4)),
>    Month = list_to_integer(lists:sublist(atom_to_list(Date),5,2)),
>    Day = list_to_integer(lists:sublist(atom_to_list(Date),7,2)),
>    {Year, Month, Day}.
>
>
>
> with the following property:
>
> proper_time_to_atom() ->
>    ?FORALL(Date, date(),
>         begin
>         EncDate = ec_time_fns:atom_to_date(ec_time_fns:date_to_atom(Date)),
>         EncDate =:= Date
>         end).
>
> running the following from erl works fine
> proper:quickcheck(ec_time_fns_tests:proper_time_to_atom()).
>
>
> but how do I make eunit to run these test?
>
>
> tried this , but it doesn't seem to work
>
> time_to_atom_test_() ->
>    ?_test(proper:quickcheck(proper_time_to_atom())).
>
>
> any ideas?
>
> Regards, Roman
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
>

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to run PropEr tests from Eunit?

Fred Hebert (MononcQc)
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 erlang:group_leader/2. 

On Mon, Jul 25, 2011 at 8:19 AM, Paweł Peregud <[hidden email]> wrote:
I wonder how did you solve the issue with eunit hiding output from PropEr?

I do following on test setup:

    meck:new(io, [unstick, passthrough]),
    meck:expect(io, fwrite, fun
                                (FString, Args) -> meck:passthrough([user, FString, Args])
                            end)

This approach is ugly and also very slow. Does anyone have a better solution?

Best,
PP.




2011/6/24 Roman Shestakov <[hidden email]>
thanks a lot Bob, this is very helpful
Regards, Roman


From: Bob Ippolito <[hidden email]>
To: Frédéric Trottier-Hébert <[hidden email]>
Cc: Roman Shestakov <[hidden email]>; [hidden email]
Sent: Fri, 24 June, 2011 18:05:37
Subject: Re: [erlang-questions] how to run PropEr tests from Eunit?

This is what I've been using:

proper_test_() ->
    [{atom_to_list(F),
      fun () -> ?assert(proper:quickcheck(?MODULE:F(), [long_result])) end}
    || {F, 0} <- ?MODULE:module_info(exports), F > 'prop_', F < 'prop`'].

2011/6/23 Frédéric Trottier-Hébert <[hidden email]>:
> The simplest way I know to do them individually is with separate tests:
> proper_test_() ->
>     [?_assert(proper:quickcheck(prop_some_property())),
>      ?_assert(proper:quickcheck(prop_some_property())),
>      ...].
> You can then create macros to do it for you of the form
> -define(PROPTEST(A), ?_assert(proper:quickcheck(A()))).
> and then call
> proper_test_() ->
>     [?PROPTEST(prop_something), ?PROPTEST(prop_something_else),
>      ?PROPTEST(prop_other), ?PROPTEST(prop_last)].
> or whatever you feel like.
> If you want to run them all, make sure your module's properties all start
> with the prefix 'prop_'. Then you can do something like
> proper_test() ->
>     [] = proper:module(?MODULE).
> which will find all the properties of the current module and run them for
> you. Also, don't forget to always include the proper include file first,
> because both PropEr and EUnit define a LET macro, but the PropEr one is the
> only one I've seen actively used.
>
> --

> Fred Hébert
> http://www.erlang-solutions.com
>
>
> On 2011-06-23, at 18:12 PM, Roman Shestakov wrote:
>
> hello,
>
> I am trying to run PropEr tests from Eunit and I must admit, I can't figure
> out how to run them
>
>
> lets say I want to test the following three functions
>
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date to atom
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_atom(date()) -> atom().
> date_to_atom({Year, Month, Day}) ->
>    list_to_atom(date_to_string({Year, Month, Day})).
>
> %%--------------------------------------------------------------------
> %% @doc
> %% Convert Date to string
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_string(date()) -> string().
> date_to_string({Year, Month, Day}) ->
>    lists:flatten(io_lib:format("~4.10.0B~2.10.0B~2.10.0B", [Year, Month,
> Day])).
>
>
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date represented as atom into Erlang date format
> %% @end
> %%--------------------------------------------------------------------
> -spec atom_to_date(atom()) -> date().
> atom_to_date(Date) ->
>    Year = list_to_integer(lists:sublist(atom_to_list(Date),1,4)),
>    Month = list_to_integer(lists:sublist(atom_to_list(Date),5,2)),
>    Day = list_to_integer(lists:sublist(atom_to_list(Date),7,2)),
>    {Year, Month, Day}.
>
>
>
> with the following property:
>
> proper_time_to_atom() ->
>    ?FORALL(Date, date(),
>         begin
>         EncDate = ec_time_fns:atom_to_date(ec_time_fns:date_to_atom(Date)),
>         EncDate =:= Date
>         end).
>
> running the following from erl works fine
> proper:quickcheck(ec_time_fns_tests:proper_time_to_atom()).
>
>
> but how do I make eunit to run these test?
>
>
> tried this , but it doesn't seem to work
>
> time_to_atom_test_() ->
>    ?_test(proper:quickcheck(proper_time_to_atom())).
>
>
> any ideas?
>
> Regards, Roman
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
>

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to run PropEr tests from Eunit?

Motiejus Jakštys
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
> erlang:group_leader/2.
>

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.

Motiejus
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to run PropEr tests from Eunit?

Frédéric Trottier-Hébert
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



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
>> erlang:group_leader/2.
>>
>
> 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.
>
> Motiejus
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to run PropEr tests from Eunit?

Motiejus Jakštys
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
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions