I'm discovering that EUnit is really powerful.<br>I'll be more careful next time with test generation/run function.<br>Thanks.<br><br><div><span class="gmail_quote">On 11/3/07, <b class="gmail_sendername">Richard Carlsson
</b> <<a href="mailto:richardc@it.uu.se">richardc@it.uu.se</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Ludovic Coquelle wrote:
<br>> I have some problem with the EUnit fixture {setup, Setup, Clearup,<br>> Instanciator}.<br>><br>> From the doc, I understand that the Instanciator should get the value<br>> return by the Setup.<br>> But in the following case, the test fail because assertion is "undefined
<br>> == foo".<br>> Am I missing something?<br>><br>> simple_init() -><br>>     foo.<br>> simple_close(R) -><br>>     R.<br>> simple_do(R) -><br>>     ?assert(R == foo).<br>> simple_test_() ->
<br>>     {<br>>         setup,<br>>         fun simple_init/0,<br>>         fun simple_close/1,<br>>         fun simple_do/1<br>>     }.<br><br>It does get the value from Setup during the test phase, but there is a
<br>previous phase which tries to enumerate the tests, and that will pass<br>a dummy value ('undefined') to avoid actually running the setup.<br><br>Note that the name of your 'simple_do/1' function is misleading: since
<br>it takes a parameter, EUnit assumes that it is (as you said) an<br>instantiator which should get the value from simple_init/0, and should<br>*return a test descriptor*, not try to run a test.<br><br>If you try the following, you will see what is happening:
<br><br>simple_do(R) -><br>  eunit:debug(R),<br>  ?_assert(R == foo).  % note the underscore: return test, don't run it<br><br>(simple_do/1 is run twice - the first time with R='undefined').<br><br>Although EUnit is powerful and compact to write, I know that it
<br>can be hard to keep in mind whether you should currently be writing<br>test-running code of test-generating code.<br><br>    /Richard<br><br><br>--<br> "Having users is like optimization: the wise course is to delay it."
<br>   -- Paul Graham<br></blockquote></div><br>