mirror of
https://github.com/correl/rebar.git
synced 2024-11-14 19:19:30 +00:00
erlc: add test suite
This commit is contained in:
parent
fe9d328cb5
commit
b2dfebab15
14 changed files with 282 additions and 0 deletions
7
inttest/erlc/asn1/SIMPLE-ASN.asn1
Normal file
7
inttest/erlc/asn1/SIMPLE-ASN.asn1
Normal file
|
@ -0,0 +1,7 @@
|
|||
SIMPLE-ASN DEFINITIONS ::= BEGIN
|
||||
|
||||
SimpleMessage ::= SEQUENCE {
|
||||
id INTEGER
|
||||
}
|
||||
|
||||
END
|
98
inttest/erlc/erlc_rt.erl
Normal file
98
inttest/erlc/erlc_rt.erl
Normal file
|
@ -0,0 +1,98 @@
|
|||
-module(erlc_rt).
|
||||
-export([files/0,
|
||||
run/1]).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(MODULES,
|
||||
[first_xrl,
|
||||
first_yrl,
|
||||
foo,
|
||||
foo_app,
|
||||
foo_sup,
|
||||
foo_test_worker,
|
||||
foo_worker,
|
||||
'SIMPLE-ASN']).
|
||||
|
||||
-define(BEAM_FILES,
|
||||
["first_xrl.beam",
|
||||
"first_yrl.beam",
|
||||
"foo.beam",
|
||||
"foo_app.beam",
|
||||
"foo_sup.beam",
|
||||
"foo_test_worker.beam",
|
||||
"foo_worker.beam",
|
||||
"SIMPLE-ASN.beam"]).
|
||||
|
||||
files() ->
|
||||
[
|
||||
{copy, "../../rebar", "rebar"},
|
||||
{copy, "rebar.config", "rebar.config"},
|
||||
{copy, "rebar-no_debug_info.config", "rebar-no_debug_info.config"},
|
||||
{copy, "include", "include"},
|
||||
{copy, "extra-include", "extra-include"},
|
||||
{copy, "src", "src"},
|
||||
{copy, "extra-src", "extra-src"},
|
||||
{copy, "mibs", "mibs"},
|
||||
{copy, "asn1", "asn1"},
|
||||
{create, "ebin/foo.app", app(foo, ?MODULES)}
|
||||
].
|
||||
|
||||
run(_Dir) ->
|
||||
?assertMatch({ok, _}, retest_sh:run("./rebar compile", [])),
|
||||
ok = check_beams(true),
|
||||
ok = check_debug_info(true),
|
||||
MibResult = filename:join(["priv", "mibs", "SIMPLE-MIB.bin"]),
|
||||
?assertMatch(true, filelib:is_regular(MibResult)),
|
||||
?assertMatch({ok, _}, retest_sh:run("./rebar clean", [])),
|
||||
ok = check_beams(false),
|
||||
?assertMatch(false, filelib:is_regular(MibResult)),
|
||||
?assertMatch(
|
||||
{ok, _},
|
||||
retest_sh:run("./rebar -C rebar-no_debug_info.config compile", [])),
|
||||
ok = check_beams(true),
|
||||
ok = check_debug_info(false),
|
||||
?assertMatch(true, filelib:is_regular(MibResult)),
|
||||
ok.
|
||||
|
||||
check_beams(Exist) ->
|
||||
check_files(Exist, fun filelib:is_regular/1).
|
||||
|
||||
check_debug_info(HasDebugInfo) ->
|
||||
check_files(HasDebugInfo, fun has_debug_info/1).
|
||||
|
||||
check_files(Expected, Check) ->
|
||||
lists:foreach(
|
||||
fun(F) ->
|
||||
File = filename:join("ebin", F),
|
||||
?assertEqual(Expected, Check(File))
|
||||
end,
|
||||
?BEAM_FILES).
|
||||
|
||||
%% NOTE: Copied from dialyzer_utils:get_abstract_code_from_beam/1 and
|
||||
%% modified for local use. We could have called the function directly,
|
||||
%% but dialyzer_utils is not an official API to rely on.
|
||||
has_debug_info(File) ->
|
||||
case beam_lib:chunks(File, [abstract_code]) of
|
||||
{ok, {_Mod, List}} ->
|
||||
case lists:keyfind(abstract_code, 1, List) of
|
||||
{abstract_code, {raw_abstract_v1, _Abstr}} ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
end;
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%%
|
||||
%% Generate the contents of a simple .app file
|
||||
%%
|
||||
app(Name, Modules) ->
|
||||
App = {application, Name,
|
||||
[{description, atom_to_list(Name)},
|
||||
{vsn, "1"},
|
||||
{modules, Modules},
|
||||
{registered, []},
|
||||
{applications, [kernel, stdlib]}]},
|
||||
io_lib:format("~p.\n", [App]).
|
1
inttest/erlc/extra-include/foo_extra.hrl
Normal file
1
inttest/erlc/extra-include/foo_extra.hrl
Normal file
|
@ -0,0 +1 @@
|
|||
-define(FOO_EXTRA, foo_extra).
|
13
inttest/erlc/extra-src/foo_sup.erl
Normal file
13
inttest/erlc/extra-src/foo_sup.erl
Normal file
|
@ -0,0 +1,13 @@
|
|||
-module(foo_sup).
|
||||
|
||||
-behavior(supervisor).
|
||||
|
||||
-export([start_link/0,
|
||||
init/1]).
|
||||
|
||||
start_link() ->
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
init(_Args) ->
|
||||
FooChild = {foo,{foo, start_link, []}, permanent, 5000, worker, [foo]},
|
||||
{ok,{{one_for_all,1,1}, [FooChild]}}.
|
1
inttest/erlc/include/foo_core.hrl
Normal file
1
inttest/erlc/include/foo_core.hrl
Normal file
|
@ -0,0 +1 @@
|
|||
-define(FOO_CORE, foo_core).
|
26
inttest/erlc/mibs/SIMPLE-MIB.mib
Normal file
26
inttest/erlc/mibs/SIMPLE-MIB.mib
Normal file
|
@ -0,0 +1,26 @@
|
|||
-- SIMPLE-MIB.
|
||||
-- This is just a simple MIB used for testing!
|
||||
--
|
||||
|
||||
|
||||
SIMPLE-MIB DEFINITIONS ::= BEGIN
|
||||
|
||||
IMPORTS
|
||||
MODULE-IDENTITY, enterprises
|
||||
FROM SNMPv2-SMI;
|
||||
|
||||
ericsson MODULE-IDENTITY
|
||||
LAST-UPDATED
|
||||
"201403060000Z"
|
||||
ORGANIZATION
|
||||
"rebar"
|
||||
CONTACT-INFO
|
||||
"rebar <rebar@example.com>
|
||||
or
|
||||
whoever is currently responsible for the SIMPLE
|
||||
enterprise MIB tree branch (enterprises.999)."
|
||||
DESCRIPTION
|
||||
"This very small module is made available
|
||||
for mib-compilation testing."
|
||||
::= { enterprises 999 }
|
||||
END
|
11
inttest/erlc/rebar-no_debug_info.config
Normal file
11
inttest/erlc/rebar-no_debug_info.config
Normal file
|
@ -0,0 +1,11 @@
|
|||
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
||||
%% ex: ts=4 sw=4 ft=erlang et
|
||||
{erl_first_files, ["first_xrl.erl", "first_yrl.erl"]}.
|
||||
|
||||
{erl_opts,
|
||||
[
|
||||
no_debug_info,
|
||||
{i, "extra-include"},
|
||||
{src_dirs, ["src", "extra-src"]},
|
||||
{platform_define, "R13|R14", 'NO_CALLBACK_ATTRIBUTE'}
|
||||
]}.
|
10
inttest/erlc/rebar.config
Normal file
10
inttest/erlc/rebar.config
Normal file
|
@ -0,0 +1,10 @@
|
|||
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
||||
%% ex: ts=4 sw=4 ft=erlang et
|
||||
{erl_first_files, ["first_xrl.erl", "first_yrl.erl"]}.
|
||||
|
||||
{erl_opts,
|
||||
[
|
||||
{i, "extra-include"},
|
||||
{src_dirs, ["src", "extra-src"]},
|
||||
{platform_define, "R13|R14", 'NO_CALLBACK_ATTRIBUTE'}
|
||||
]}.
|
14
inttest/erlc/src/behaviour/foo_worker.erl
Normal file
14
inttest/erlc/src/behaviour/foo_worker.erl
Normal file
|
@ -0,0 +1,14 @@
|
|||
-module(foo_worker).
|
||||
|
||||
-ifdef(NO_CALLBACK_ATTRIBUTE).
|
||||
|
||||
-export([behaviour_info/1]).
|
||||
|
||||
behaviour_info(callbacks) -> [{status, 0}];
|
||||
behaviour_info(_) -> undefined.
|
||||
|
||||
-else.
|
||||
|
||||
-callback status() -> 'idle' | 'busy'.
|
||||
|
||||
-endif.
|
13
inttest/erlc/src/first_xrl.xrl
Normal file
13
inttest/erlc/src/first_xrl.xrl
Normal file
|
@ -0,0 +1,13 @@
|
|||
Definitions.
|
||||
|
||||
D = [0-9]
|
||||
|
||||
Rules.
|
||||
|
||||
{D}+ :
|
||||
{token,{integer,TokenLine,list_to_integer(TokenChars)}}.
|
||||
|
||||
{D}+\.{D}+((E|e)(\+|\-)?{D}+)? :
|
||||
{token,{float,TokenLine,list_to_float(TokenChars)}}.
|
||||
|
||||
Erlang code.
|
9
inttest/erlc/src/first_yrl.yrl
Normal file
9
inttest/erlc/src/first_yrl.yrl
Normal file
|
@ -0,0 +1,9 @@
|
|||
Nonterminals list elements element.
|
||||
Terminals atom '(' ')'.
|
||||
Rootsymbol list.
|
||||
list -> '(' ')'.
|
||||
list -> '(' elements ')'.
|
||||
elements -> element.
|
||||
elements -> element elements.
|
||||
element -> atom.
|
||||
element -> list.
|
35
inttest/erlc/src/foo.erl
Normal file
35
inttest/erlc/src/foo.erl
Normal file
|
@ -0,0 +1,35 @@
|
|||
-module(foo).
|
||||
|
||||
-export([start_link/0,
|
||||
start_link/1,
|
||||
init/1,
|
||||
terminate/2,
|
||||
handle_info/2,
|
||||
handle_call/3,
|
||||
handle_cast/2,
|
||||
code_change/3]).
|
||||
|
||||
-behavior(gen_server).
|
||||
|
||||
-include("foo_core.hrl").
|
||||
-include("foo_extra.hrl").
|
||||
-include_lib("kernel/include/file.hrl").
|
||||
|
||||
-record(state, {node :: node()}).
|
||||
|
||||
start_link() -> start_link(undefined).
|
||||
|
||||
start_link(Args) ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, Args, []).
|
||||
|
||||
init(_Args) -> {ok, #state{node=node()}}.
|
||||
|
||||
terminate(_Reason, _Data) -> ok.
|
||||
|
||||
handle_info(_Info, State) -> {noreply, State}.
|
||||
|
||||
handle_cast(_Msg, State) -> {noreply, State}.
|
||||
|
||||
handle_call(_Msg, _From, State) -> {reply, ok, State}.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
10
inttest/erlc/src/foo_app.erl
Normal file
10
inttest/erlc/src/foo_app.erl
Normal file
|
@ -0,0 +1,10 @@
|
|||
-module(foo_app).
|
||||
|
||||
-behaviour(application).
|
||||
|
||||
-export([start/2,
|
||||
stop/1]).
|
||||
|
||||
start(_Type, _Args) -> foo_sup:start_link().
|
||||
|
||||
stop(_State) -> ok.
|
34
inttest/erlc/src/foo_test_worker.erl
Normal file
34
inttest/erlc/src/foo_test_worker.erl
Normal file
|
@ -0,0 +1,34 @@
|
|||
-module(foo_test_worker).
|
||||
|
||||
-behaviour(gen_server).
|
||||
-behaviour(foo_worker).
|
||||
|
||||
-export([start_link/0,
|
||||
start_link/1,
|
||||
init/1,
|
||||
handle_call/3,
|
||||
handle_cast/2,
|
||||
handle_info/2,
|
||||
terminate/2,
|
||||
code_change/3,
|
||||
status/0]).
|
||||
|
||||
-include_lib("kernel/include/inet.hrl").
|
||||
|
||||
start_link() -> start_link(undefined).
|
||||
|
||||
start_link(Args) -> gen_server:start_link(?MODULE, Args, []).
|
||||
|
||||
init([]) -> {ok, undefined}.
|
||||
|
||||
handle_call(_Event, _From, State) -> {reply, ok, State}.
|
||||
|
||||
handle_cast(_Event, State) -> {noreply, State}.
|
||||
|
||||
handle_info(_Info, State) -> {noreply, State}.
|
||||
|
||||
terminate(_Reason, _State) -> ok.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
||||
|
||||
status() -> busy.
|
Loading…
Reference in a new issue