[erlang-questions] erl_call + eunit: how to redirect eunit output to erl_call?

Marco Molteni marco.molteni@REDACTED
Mon Nov 2 22:40:01 CET 2015

Hi all,

to be able to do real test-driven development, one needs extremely fast unit tests (ideally less than 10ms per test case).

To run the unit tests, one needs the Erlang VM, which on my laptop has an overhead of around 1.2 - 1.5 secs:

  $ time erl -noshell -s init stop
  real    0m1.217s

(clearly for a long-running Erlang system this is not a problem at all :-)

If we run an empty UT, we get:

  $ time erl -pa bin -noshell -eval 'eunit:test("bin", [verbose])' -s init stop
  ======================== EUnit ========================
  directory "bin"
    ftp30_test: simple_test (module 'ftp30_test')...ok
    [done in 0.009 s]
    Test passed.
  real    0m1.250s

confirming the overhead.

I was thinking: is it possible to shave off this overhead, when running the UTs?

I found out about erl_call [1] and I was excited, so in one terminal I started the VM as:

  erl -pa ebin -sname dust

and in another terminal I ran:

  $ time erl_call -sname dust -a 'eunit test ["ebin", [verbose]]'
  real	0m0.024s

Now, if you look at the time, it took 24 msec as opposed to the traditional 1250 msec, so it looks good, but, there is no eunit output!

The classic eunit output still goes to the first terminal, where I launched the VM:

  ======================== EUnit ========================
  directory "ebin"
    ftp30_test: simple_test (module 'ftp30_test')...ok
    [done in 0.011 s]
    Test passed.

I know that eunit plays tricks with stdout, I was wondering if there was a way to redirect the output so that one can get it out of erl_call.

I am willing to attempt to make the changes, but I'd like some guidance :-)

And, I also realize that I am not counting the compile time and that when the number of tests becomes big enough, the 1.2 sec overhead will be negligible. On the other hand, I am used to blazingly fast C++ TDD (when not compiling templated code ;-), and I think that to do TDD one needs extremely fast feedback. Even waiting 1 sec doesn't feel right :-)

Or maybe another path to consider is not using erl_call at all and just using the VM, with a stripped-down environment like the SEE explained in Joe's second edition Programming Erlang...


[1] http://www.erlang.org/doc/man/erl_call.html

More information about the erlang-questions mailing list