4

I have been trying to export all the functions in an erlang module for use in a common test SUITE, not an eunit module. So far it has not worked for me. I am using rebar to run the SUITE, and I came across this question (http://lists.basho.com/pipermail/rebar_lists.basho.com/2011-October/001141.html), which is essentially exactly what I want to do, but the method will not work for me.

I have also added {plugins, [rebar_ct]}. into rebar.config but it has made no difference. I should point out all my tests pass when I export the functions normally, but I want to avoid this. Any help would be great thanks.

liam_g
  • 314
  • 1
  • 5
  • 15

2 Answers2

11

The compiler will cause all functions in a module to be exported if you add this into it:

-compile(export_all).

Or you could do it based on defs, like:

-ifdef(EXPORTALL).
-compile(export_all).
-endif.

That will only export everything if you have {d, 'EXPORTALL', true} in your rebar config erl_opts setting, e.g. something like:

{erl_opts, [
    {d, 'EXPORTALL', true}
    ]}.

If that doesn't work, make sure you don't have erl_opts twice in your rebar config.

Michael
  • 3,639
  • 14
  • 29
  • Thank you, it does work when I do that, but I want to avoid exporting everything as it is unnecessary and costly. I just want them exported when the test suite is calling them. Using a method like eunit test only export like below. `-ifdef(EUNIT).` `-compile(export_all).` `-endif.` – liam_g Dec 10 '15 at 15:22
  • `TEST` is defined for eunit, but I don't know off hand if it is defined for ct. – Michael Dec 10 '15 at 15:46
  • It is not defined for ct, so the next step is to define it in the config with `{d, 'TEST', true}` in erl_opts, but for some unknown reason to me, it will not work. – liam_g Dec 10 '15 at 16:03
  • It's weird, `{d, 'TEST', true}` really should work, works for me, and the only time I just saved tearing my hair out because a def wasn't defined was when I had `erl_opts` twice. If you do `rebar eunit ct` does that work? – Michael Dec 10 '15 at 16:07
  • Nope no luck unfortunately, and I've only erl_opts defined once as well. – liam_g Dec 10 '15 at 16:18
  • That's really weird. `rebar ct` doesn't compile the modules/app, but `eunit` does, if it hasn't previously been compiled for eunit, so I don't see how you're ending up without TEST defined when your ct suites are run. Another thing you can try is `rebar -DTEST clean compile ct`, which defines TEST, or `-DCT` if you want to distinguish eunit and ct. – Michael Dec 11 '15 at 16:46
  • Hi @liam_g, I understood when you say that "exporting everything is unnecessary". But, why is it expensive? – Bhuvan Nov 11 '22 at 14:30
5

with rebar3 you can define in the config file extra option for the compilation for common test:

{ct_compile_opts, []}.

her you can add export_all which will be available for common test only. not sure it exists for rebar.

Pascal
  • 13,977
  • 2
  • 24
  • 32