lfex / ltest

A Testing Framework for LFE (successor to lfeunit)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ltest Breaks in Erlang 17.4

oubiwann opened this issue · comments

If you're running LFE and ltest in Erlang 17.4 you will find that the unit tests no longer compile. I haven't isolated the exact culprit, but I'm 99% certain this is due to the EUnit fixes that were added to the latest release of Erlang.

I suspect that something along the lines of changing the test macros to use underscores in module names will fix this, but I haven't tried it yet.

Successful use in Erlang 15, 16, and 17.3:

$ make check-unit
Removing EUnit test files ...
removed ./.eunit/*.beam
Cleaning ebin dir ...
Compiling only project code ...
==> my-test-lib (compile)
Compiled src/my-test-lib-util.lfe
Compiled src/my-test-lib.lfe
Removing old tests ...
rm -rf ./.eunit
mkdir: created directory ./.eunit
Compiling tests ...
Successfully compiled test modules.


------------------
Running unit tests ...
------------------

======================== EUnit ========================
module 'unit-my-test-lib-tests'
  my-adder ............................. [0.002 s] [ok]
  my-sum ......................................... [ok]
  my-sum-zeros ................................... [ok]
  Total module test time: 0.012 s
=======================================================
  All 3 tests passed.

Unsuccessful use in Erlang 17.4:

$ make check-unit
Removing EUnit test files ...
removed ./.eunit/*.beam
Cleaning ebin dir ...
Compiling only project code ...
==> my-test-lib (compile)
Compiled src/my-test-lib-util.lfe
Compiled src/my-test-lib.lfe
Removing old tests ...
rm -rf ./.eunit
mkdir: created directory ./.eunit
Compiling tests ...
Successfully compiled test modules.


------------------
Running unit tests ...
------------------

======================== EUnit ========================
undefined
=ERROR REPORT==== 3-Jan-2015::14:04:40 ===
Loading of /tmp/my-test-lib/.eunit/unit-my-test-lib-tests.beam failed: badfile
*** test module not found ***
**'.eunit/unit-my-test-lib-tests'
=ERROR REPORT==== 3-Jan-2015::14:04:40 ===
beam/beam-load.c(1250): Error loading module '.eunit/unit-my-test-lib-tests':
  module name in object code is unit-my-test-lib-tests
=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
make: *** [check-unit-only] Error 127

I've just re-read the release notes for 17.4, and I'm now much less certain that's where the problem lays.

Skipping the make target and lfetool to run the tests, just using erl, both 17.3 and 17.4 fail:

ERL_LIBS=`lfetool info erllibs` erl -pa \
./.eunit -noshell -eval "eunit:test(['.eunit/unit-my-test-lib-tests'],[verbose])" \
-s erlang halt
======================== EUnit ========================
undefined

=ERROR REPORT==== 3-Jan-2015::14:24:41 ===
beam/beam_load.c(1250): Error loading module '.eunit/unit-my-test-lib-tests':
  module name in object code is unit-my-test-lib-tests

*** test module not found ***
**'.eunit/unit-my-test-lib-tests'


=ERROR REPORT==== 3-Jan-2015::14:24:41 ===
Loading of /tmp/my-test-lib/.eunit/unit-my-test-lib-tests.beam failed: badfile
=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.

There might be some magic that lfetool is doing which works in 17.3 but not in 17.4?

/me digs more ...

Ah ... lfetool strips the ./eunit. Updating the command line with that change, we get the following success with both 17.3 and 17.4:

ERL_LIBS=`lfetool info erllibs` erl -pa \
./.eunit -noshell -eval "eunit:test(['unit-my-test-lib-tests'],[verbose])" \
-s erlang halt
======================== EUnit ========================
module 'unit-my-test-lib-tests'
  unit-my-test-lib-tests: my-adder_test...[0.001 s] ok
  unit-my-test-lib-tests: my-sum_test...ok
  unit-my-test-lib-tests: my-sum-zeros_test...ok
  [done in 0.010 s]
=======================================================
  All 3 tests passed.

Looking into the different behaviour between lfetool with 17.3 and 17.4 now ...

Now we're getting somewhere. The command that gets the unit tests in lfetool ultimately makes this call:

(lists:map
  #'filename:rootname/1
  (filelib:wildcard
    (filename:join (list "." ".eunit" "*.beam"))))

Under 17.3, that gives the following result:

'unit-my-test-lib-tests'

Under 17.4:

'.eunit/unit-my-test-lib-tests'

It turns out the behaviour of (filelib:wildcard ...) is different for 17.3 and 17.4: in the latter, it removes the initial ./. For example:

17.3:

> (filelib:wildcard (filename:join "./" "src/*"))
("./src/my-test-lib-util.lfe"
 "./src/my-test-lib.app.src"
 "./src/my-test-lib.lfe")
> (filelib:wildcard (filename:join "." ".eunit/*"))
("./.eunit/unit-my-test-lib-tests.beam")

17.4:

> (filelib:wildcard (filename:join "./" "src/*"))
("src/my-test-lib-util.lfe"
 "src/my-test-lib.app.src" 
 "src/my-test-lib.lfe")
> (filelib:wildcard (filename:join "." ".eunit/*"))
(".eunit/unit-my-test-lib-tests.beam")

This difference foiled the sed in lfetool.

I believe that this inconsistency was accounted for in a recent contribution made by @fhunleth to lfetool.

Yup, here it is: lfe-deprecated/lfetool#137

When this is merged to stable, lfetool will have support for 17.4.

I've just confirmed that with @fhunleth's patch to lfetool, unit tests pass using 17.4.