[erlang-questions] EUnit setUp/tearDown question

Gianfranco Alongi gianfranco.alongi@REDACTED
Mon Oct 25 12:37:17 CEST 2010


Hi Muharem, 

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

also you might find something useful on my Erlang Testing Blog.

 http://erlcode.wordpress.com/

Happy hacking.

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: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