EUnit Tests?

25 views
Skip to first unread message

Kevin Montuori

unread,
Jun 30, 2015, 2:39:42 PM6/30/15
to nitro...@googlegroups.com

Hi All --

This is most likely a stupid question but I'm stumped: What's the
suggested way of running EUnit tests (not wf_test tests) as part of a
slim Nitrogen application? I assume there's a rebar incantation or some
magic place to put the *_tests.erl files that I just haven't landed upon
yet (but not for lack of trying!).

Thanks for any help!

k.

--
Kevin Montuori
mont...@gmail.com

Jesse Gumm

unread,
Jul 2, 2015, 10:49:19 PM7/2/15
to nitrogenweb
Hi Kevin,

Sorry for the delay. Google Groups flagged this message a potential
spam (no idea why).

It's a good question, and one that isn't at all obvious.

Due to the unusual Nitrogen directory structure (with the site
directory containing code and static data), to make eunit work you're
going to need to make one change to your rebar.config:

Add the line:

{recursive_cmds, [eunit]}.

This line tells rebar to run eunit in recursive directories

Then, you're going to want to run:

./rebar skip_deps=true eunit

skip_deps=true will prevent it from running eunit on all your dependency apps.

Or to take it a step further, you can modify your makefile to add a
"test" rule as follow:

test: get-deps compile
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH; echo "Using
Erlang in `which erl`"; $(REBAR) skip_deps=true eunit)

Then `make test` will properly run not only any tests in the modules
in site/src but also you can use site/test for your test files.

At some point, all this worked without the above tweaks, but I'm not
sure what changed in rebar exactly to prevent it from running the
tests, but it's no big deal - I will take some time to document this
process (and include some default rules) for the next Nitrogen release
(either 2.3.2 or 2.4).

Hope that helps,
> --
> You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb...@googlegroups.com.
> To post to this group, send email to nitro...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nitrogenweb.
> For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Jesse Gumm

unread,
Jul 2, 2015, 10:51:37 PM7/2/15
to nitrogenweb
For reference, I've made a reminder issue on github to include proper
documentation for eunit here:
https://github.com/nitrogen/nitrogen/issues/88

Thanks for bringing to light just how difficult and non-obvious this process is.

Kevin Montuori

unread,
Jul 3, 2015, 2:33:27 PM7/3/15
to nitro...@googlegroups.com
>>>>> "jg" == Jesse Gumm <gu...@sigma-star.com> writes:

jg> Add the line:

jg> {recursive_cmds, [eunit]}.

!!

One could read a lot of rebar documentation (and, indeed, source)
without stumbling upon that. Thanks, Jesse, for taking the time to
answer!

Jesse Gumm

unread,
Jul 3, 2015, 2:37:37 PM7/3/15
to nitrogenweb
You ain't kiddin', chum! It took a fair bit of digging to come across that one.

It's documented here
(https://github.com/rebar/rebar/blob/3f0ead5dc5c110d30f7a04f6dce044eba2be8282/rebar.config.sample),
but it's not obvious that it's needed in this context without
realizing that the 'site' directory requires it. There was a bit of
tracing which led to this
(https://github.com/rebar/rebar/blob/a3713879b401a39b37505499e1a43ab164420354/src/rebar_core.erl#L156)
and then it clicked what was needed.

-Jesse
Reply all
Reply to author
Forward
0 new messages