My goal is quite simple; while I am learning Erlang, I would like to use rebar to create a basic module with an eunit test:
I have tried the following:
mkdir erlangscratch
cd erlangscratch
rebar create template=simplemod modid=erlangscratch
Edit the 'test/erlangscratch_tests.erl' to look like this:
-module(erlangscratch_tests).
-include_lib("eunit/include/eunit.hrl").
% This should fail
basic_test_() ->
?assert(1 =:= 2).
Execute the tests:
snowch@tp:~/erlangscratch$ rebar co eu
==> erlangscratch (compile)
==> erlangscratch (eunit)
The tests weren't executed, but it also seems that the code isn't compiling.
Here are the contents of my folder:
snowch@tp:~/erlangscratch$ tree .
.
├── src
│ └── erlangscratch.erl
└── test
└── erlangscratch_tests.erl
2 directories, 2 files
Question: What step(s) have I missed out?
UPDATE:
As per the accepted answer, basic_test_
function needed to be renamed and the 'src/erlangscratch.app.src' was missing so I created it with the following contents:
{application, erlangscratch,
[
{description, "An Erlang erlangscratch library"},
{vsn, "1"},
{modules, [
erlangscratch
]},
{registered, []},
{applications, [
kernel,
stdlib
]},
{env, []}
]}.
You are mixing tests with test generators .
In short the second one should return fun's or lists of fun's. You can distinguish both by _
at the end of your tests names, and _
and the beginning of your macros.
Simple solution would be using either
basic_test() ->
?assert(1 =:= 2).
or
basic_test_() ->
?_assert(1 =:= 2).
depending on your needs, and what you understand better.
EDIT after sharing folder structure
It seems rebar is not recognizing your project as an OTP application . You might be just missing simple .app.src
file. Something like:
{application, myapp,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{env, []}
]}.
And since rebar is capable of generating one for you, you either just call rebar create-app
or extend one of existing templates.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.