[erlang-questions] EUnit setUp/tearDown question

Muharem Hrnjadovic muharem@REDACTED
Mon Oct 25 12:20:46 CEST 2010


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20101025/0c76c0b5/attachment.bin>


More information about the erlang-questions mailing list