3

I want to start lager before any eunit test is executed so that I can see the log when the tests are actually run (I use the log for debugging purposes).

However I have hundreds of tests (spread across multiple apps and modules) and I don't want to go through every single one and put lager:start() at the beginning so I was wondering if there is a way to tell rebar (or eunit) to execute lager:start() before executing the eunit tests?

ymn
  • 2,175
  • 2
  • 21
  • 39
Svetlin Mladenov
  • 4,307
  • 24
  • 31

2 Answers2

2

I think you can use erl params like "-s lager", and pass it by method are described in following post.

passing runtime arguments to erlang when running rebar eunit

Community
  • 1
  • 1
Petr Kozorezov
  • 426
  • 2
  • 7
  • I tries `ERL_FLAGS="-s lager" ./rebar skip_deps=true eunit` but it doesn't work. I don't know why. But if I manually run erlang: `ERL_FLAGS="-s lager" erl -pa ebin` and then run the tests everything works. Are you sure ERL_FLAGS works when used with rebar because rebar doesn't seem to spawn `erl` as a separate system process or anything similar. All eunit test are just run in the same virtual machine rebar is run in. – Svetlin Mladenov Jan 14 '13 at 12:07
  • I experimented with this, and `ERL_AFLAGS="-s lager" ./rebar eunit skip_deps=true` works for me. But why ERL_FLAGS isn't, i don't know. – Petr Kozorezov Jan 14 '13 at 12:42
  • OK. ERL_AFLAGS works for me, too. I accept you answer. To be honest I was hoping for a more elegant solution but it will do for now. Thanks. – Svetlin Mladenov Jan 14 '13 at 20:33
  • Note that you might also need "-pa deps/goldrush/ebin deps/lager/ebin". Note that I couldn't get "-pa deps/*/ebin" to work from inside a Makefile. – Roger Lipscombe Nov 07 '13 at 13:17
0

(I know this isn't a full answer, but I agree with Svetlin that there should be a more elegant approach... I'll offering this as an incremental improvement on Petr's answer)

If you use a Makefile with rebar, you could modify the make target to set this environment variable, it'd be something like:

$ make test

or

$ make localtest

And that target would look like:

test:
        ERL_AFLAGS="-s lager" 
        $(REBAR) skip_deps=true eunit
lenards
  • 141
  • 1
  • 8
  • I got no success with your proposal: I get this error: {"init terminating in do_boot",{undef,[{lager,start,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}} – Nikola Borisov May 18 '21 at 22:49