[erlang-questions] EUnit setUp/tearDown question

Gianfranco Alongi gianfranco.alongi@REDACTED
Mon Oct 25 14:16:04 CEST 2010


Hi Muharem,

> "BTW, in the solution you provided "fun test_is_link_with_regular/1"
> would be an Instantiator, right?"

Yes, you are correct.

Cheers
/G

----- Original Message -----
From: "Muharem Hrnjadovic" <muharem@REDACTED>
To: "Gianfranco Alongi" <gianfranco.alongi@REDACTED>
Cc: erlang-questions@REDACTED
Sent: Monday, October 25, 2010 11:59:50 AM GMT +00:00 GMT Britain, Ireland, Portugal
Subject: Re: [erlang-questions] EUnit setUp/tearDown question

On 10/25/2010 12:37 PM, Gianfranco Alongi wrote:
> 
> Hi Muharem, 
Hello Gianfranco,

> Maybe you already found your way to the User Guide, but I'll post the
> link in case,
> 
>  http://www.erlang.org/doc/apps/eunit/users_guide.html
I did pore over this for quite a while but could not figure how to set
up the test suite described in the original email.

The examples in the User Guide are nice but pretty simple.  Adding
something like the example you kindly provided to it would be very
helpful IMHO.

BTW, in the solution you provided "fun test_is_link_with_regular/1"
would be an Instantiator, right?

> also you might find something useful on my Erlang Testing Blog.
> 
>  http://erlcode.wordpress.com/
Oh, nice :-) Will take a look.

> ----- Original Message -----
> From: "Muharem Hrnjadovic" <muharem@REDACTED>
> To: "Gianfranco Alongi" <gianfranco.alongi@REDACTED>
> Cc: erlang-questions@REDACTED
> Sent: Monday, October 25, 2010 11:20:46 AM GMT +00:00 GMT Britain, Ireland, Portugal
> Subject: Re: [erlang-questions] EUnit setUp/tearDown question
> 
> Hello Gianfranco,
> 
> thanks a million for the example below! It helped a lot :-)
> 
> On 10/25/2010 11:08 AM, Gianfranco Alongi wrote:
>> Hi,
>>
>>
>> -module(wth).
>> -include_lib("eunit/include/eunit.hrl").
>>
>> is_link_test_() ->
>>     {foreach,
>>      fun() ->  ?cmd("mktemp -d temp") -- "\n"  end,
>>      fun(T) -> ?cmd("rm -rf " ++ T) end,
>>      [
>>       fun test_is_link_with_regular/1,
>>       fun test_is_link_with_link/1
>>      ]
>>     }.
>>
>> % ------------------------------------------------------------------------------
>> is_link(P) ->
>>     {ok, FIT} = file:read_link_info(P),
>>     element(3,FIT) =:= symlink.
>>   
>> test_is_link_with_regular(T) ->
>>     {"Test is link with regular",
>>     fun() ->
>> 	    P = filename:join(T, "a"),
>> 	    ?cmd("touch "++P),
>> 	    ?assert(not is_link(P))
>>     end}.
>>
>> test_is_link_with_link(T) ->
>>     {"Test Is link with Link",
>>      fun() ->
>> 	     P = filename:join(T, "a"),
>> 	     ?cmd("touch "++P),
>> 	     ?cmd("ln -s "++P++" "++P++".link"),
>> 	     ?assert(is_link(P ++ ".link"))
>>      end}.
>>
>>
>>
>>  zenon$ erlc wth.erl 
>>  zenon$ erl -pa -eval 'eunit:test(wth,[verbose]).'
>>
>> Erlang R13B04 (erts-5.7.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]
>>
>> Eshell V5.7.5  (abort with ^G)
>> 1> ======================== EUnit ========================
>> module 'wth'
>>   wth: test_is_link_with_regular (Test is link with regular)...[0.008 s] ok
>>   wth: test_is_link_with_link (Test Is link with Link)...[0.011 s] ok
>>   [done in 0.049 s]
>> =======================================================
>>   All 2 tests passed.

Best regards/Mit freundlichen Grüßen

-- 
Muharem Hrnjadovic <muharem@REDACTED>
Public key id   : B2BBFCFC
Key fingerprint : A5A3 CC67 2B87 D641 103F  5602 219F 6B60 B2BB FCFC



More information about the erlang-questions mailing list