New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'generator' option to eunit to run a single generator #250
Conversation
+1 for selecting generators/tests with "tests" parameter. |
@richcarl thoughts? |
I think that if you write suite=a,b,... test=x,y,..., then rebar should for each m in a,b,... check module m (and m_tests) for test functions (..._test() and ...test()), and for each t in x,y,..., pick the shortest named test function (if any) such that t is a prefix of the name, and run that as a test if it is named ..._test() or as a test generator if it is named ...test(). Alternatively, don't allow t to be an arbitrary prefix, but only an exact match of the whole name before _test() or test(). |
fair enough. however, according to the documentation I don't see an option to run a specific test, just a generator. @richcarl can you please point me in the right direction? |
Oops, you're right, I never implemented {test, M, F}. I think I should do that. (Unofficially, {M,F} works right now but should be removed, since it's ambiguous.) Meanwhile, you can use eunit_test:mf_wrapper(M,F) to turn a module and function name into a 0-arity test fun. This gives better error reporting than erlang:make_fun(M,F,0) in case the module or function is missing. |
@richcarl the two functions you are referring to I'm a little doubtful on how to proceed. Wouldn't it be better to implement only the generators selection for now, and leave the implementation of the tests once these are properly supported in eunit? Or is there a way to implement those in a clean and maintainable way (i.e. without undocumented functions)? @Tuncer? |
Don't be such a wuss, Roberto! ;-) Anyhow, you can trust that eunit_test:mf_wrapper(M,F) won't go away anytime soon, even though it's not documented. And erlang:make_fun(M,F,0) isn't documented either, but in practice it's currently the only way of dynamically making a symbolic fun object from atoms+arity, and it's used by several projects; it's not likely to be removed or renamed. |
No problem in going this way, if that's what it takes. ^^_ But before I dig into this I'd still want to hear from @Tuncer, as I'd rather avoid losing dev time on this if this route isn't viable in the first place. |
I don't think eunit:mf_wrapper/2 should be documented. (In my dev repo at github, I have added {test,M,F} which has the same effect, but that might not be included in the official OTP distro soon enough for you. But you can change your implementation to use this later on when it's generally available.) The erlang:make_fun/3 function shouldn't need to be documented either - actually, if you're only targeting R15 and later, you can simply use the syntax "fun M:F/A" where M, F, A, are variables (only constant atoms and integers are allowed in R14 and earlier). From the R15A relase notes: "OTP-9643 Variables are now now allowed in 'fun M:F/A'". |
I've opened a new pull request #282 implementing what has been discussed above. |
Use lowercase for Windows drive name to resolve issue basho#250
Eunit allows to specify individual test generators to run, instead of all the tests or a specific suite (Ref). This is very useful when you are working on a single test and don't necessarily want to run all tests every time you are writing one.
You can for instance run just the single test
myapp_mymod_tests:myfunc_test_/0
by running:This patch allows to specify a single generator test like this:
Output of
make check
:Three new tests added, partial output of
rebar eunit -v
: