Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add eunit support #46

Closed
wants to merge 2 commits into from

4 participants

@doubleyou

Introduce a new make target – 'eunit' (looks up in src/ and in test/)
Introduce a new parameter – EUNIT_OPTS

Everything is being compiled into ./.eunit folder, just to keep this stuff isolated.

Maybe it's actually better to replace EUNIT_OPTS with EUNIT_VERBOSE, because so far, the only way to use EUNIT_OPTS is:

EUNIT_OPTS = [verbose]

Thoughts?

Dmitry Demes... added some commits
Dmitry Demeshchuk Add eunit support 283770c
Dmitry Demeshchuk Update docs 5b51f33
@essen
Owner

Did you just copy what rebar is doing? The .eunit folder makes no sense, and it makes no sense to have "eunit" be a separate target from "tests", aren't they tests too?

Did you try running eunit from common_test? It works pretty good already.

@doubleyou

Default tests don't work when run from common_test if they are placed separately from source files inside the test folder. In particular, you will get errors like this (I disabled warnings_as_errors in order to see if the tests still run – they don't):

test/foo_tests.erl:0: Warning: function main_test/0 already exported

Test run failed! Reason:
no_suite_specified

Try compiling, say, gproc, you will see what I mean.

Which is expected, as the current erlang.mk approach is to run EUnit tests from the source files and run common_test from the test directory, at least so far I understand from the code. The problem is, many people use separate EUnit tests and no common_test at all.

Having a separate folder for compiled files actually makes some sense, as it allows you to recompile only changed files upon every test, like it happens with make app.

Finally, I do realize that the target eunit doesn't make sense when a target tests already exists. But nobody would accept a patch that breaks the old targets and renames them from tests to common_test. :)

@doubleyou

And, yeah, I've copied rebar's behavior, more or less. Instead I don't recompile everything, just what have changed.

@essen
Owner

One thing for sure is the .eunit folder has to go. The rest I will answer another day, I am currently spec'ing what will become erlang.mk 1.0 so I will put some thoughts into this when I get there.

Thanks.

@doubleyou

I'm down for using the same folder to keep all test beams. Right now, as far as I understand, everything is being compiled into the test folder and being kept along with the .erl files.

Can't wait for the new spec!

@essen essen added the todo spec label
@ddosia

@doubleyou make eunit hangs up if there is no EUNIT_OPTS defined

@ddosia ddosia commented on the diff
erlang.mk
@@ -262,6 +262,23 @@ build-plt: deps app
dialyze:
@dialyzer --src src --plt .$(PROJECT).plt --no_native $(DIALYZER_OPTS)
+eunit: deps .eunit
+ @export EUNIT=$(EUNIT_OPTS) && erl \
+ -pa .eunit -pa $(DEPS_DIR)/*/ebin/ \
+ -run eunit test .eunit/*.beam \
@ddosia
ddosia added a note

Other issue is that it runs tests twice: once for m.beam, once for m_tests.beam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@essen
Owner

I just pushed the new erlang.mk (though it isn't the default one, you gotta clone and run make to get it at the moment). It has a component based build system that allows us to add support for anything without forcing everyone to have everything in their erlang.mk.

What you did could very well be added as a plugin, like this one for example: https://github.com/extend/erlang.mk/blob/master/plugins/ct.mk - do you think you would have time to do it soon? I'm looking for someone to do the first with and then others will have a clearer path to follow. :)

@andrzejsliwa

in my case I made something like that:

PROJECT = commodore_c64

DEPS = proper eunit_formatters
dep_proper = git@github.com:andrzejsliwa/proper.git
dep_eunit_formatters = git@github.com:seancribbs/eunit_formatters.git
.PHONY: test

CT_SUITES = eunit # to run eunits from CT as well.
include erlang.mk

ifneq ($(wildcard test/),)
ebin/$(PROJECT).app:: $(shell find test -type f -name \*.erl)
    $(if $(strip $?),$(call compile_erl,$?))
endif

eunit: ERLC_OPTS = $(TEST_ERLC_OPTS) # to have -ifdef(TEST) working properly
eunit: clean app
    $(gen_verbose) erl -noshell -pa ebin -eval 'eunit:test({application, $(PROJECT)}, [no_tty, {report, {eunit_progress, [colored, profile]}}])' -s init stop

I also removed parse transform for eunits (from TEST_ERLC_OPTS) as long it is part of eunit include file. Otherwise I have warnings about already exported functions.

@essen essen removed the todo spec label
@essen
Owner

A variable that sets the eunit_autoexport parse_transform by default for CT (like CT_AUTOEXPORT ?= the_option_here) that can be overriden could make everyone happy.

@essen
Owner

#154 looks like a good start to have a eunit plugin. Feedback is needed there. Closing this here, thanks!

@essen essen closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 12, 2014
  1. Add eunit support

    Dmitry Demeshchuk authored
  2. Update docs

    Dmitry Demeshchuk authored
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 2 deletions.
  1. +4 −0 README.md
  2. +19 −2 erlang.mk
View
4 README.md
@@ -124,6 +124,7 @@ The following targets are defined:
| `clean-docs` | Clean the Edoc documentation |
| `test_*` | Run the common_test suite `*` |
| `tests` | Run all the common_test suites |
+| `eunit` | Run EUnit tests |
| `build-plt` | Generate the PLT needed by Dialyzer |
| `dialyze` | Run Dialyzer on the application |
| `pkg-list` | List packages in the index |
@@ -208,6 +209,9 @@ not found locally.
`RELX_OPTS` is for setting relx in-line options, if any.
+`EUNIT_OPTS` is for setting EUnit options. So far, the only valid non-empty
+value is ```[verbose]``` (without quotes).
+
Extra targets
-------------
View
21 erlang.mk
@@ -47,7 +47,7 @@ gen_verbose_0 = @echo " GEN " $@;
gen_verbose = $(gen_verbose_$(V))
.PHONY: rel clean-rel all clean-all app clean deps clean-deps \
- docs clean-docs build-tests tests build-plt dialyze
+ docs clean-docs build-tests tests build-plt dialyze eunit
# Release.
@@ -152,7 +152,7 @@ ebin/$(PROJECT).app: $(shell find src -type f -name \*.erl) \
$(call compile_dtl,$(filter %.dtl,$?)))
clean:
- $(gen_verbose) rm -rf ebin/ test/*.beam erl_crash.dump
+ $(gen_verbose) rm -rf ebin/ test/*.beam erl_crash.dump .eunit
# Dependencies.
@@ -262,6 +262,23 @@ build-plt: deps app
dialyze:
@dialyzer --src src --plt .$(PROJECT).plt --no_native $(DIALYZER_OPTS)
+eunit: deps .eunit
+ @export EUNIT=$(EUNIT_OPTS) && erl \
+ -pa .eunit -pa $(DEPS_DIR)/*/ebin/ \
+ -run eunit test .eunit/*.beam \
@ddosia
ddosia added a note

Other issue is that it runs tests twice: once for m.beam, once for m_tests.beam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ -run init stop \
+ -noshell -noinput
+
+.eunit: $(shell find src -type f -name \*.erl) \
+ $(shell find test -type f -name \*.erl)
+ @mkdir -p .eunit
+ $(erlc_verbose) erlc -v \
+ -o .eunit/ \
+ -I include/ \
+ $(ERLC_OPTS) \
+ -DTEST \
+ $?
+
# Packages.
$(PKG_FILE):
Something went wrong with that request. Please try again.