mirror of
https://github.com/correl/rebar.git
synced 2024-12-24 03:00:16 +00:00
Add inttest for default proto compiler (protobuffs)
This borrows heavily from the inttest for gpb, many thanks to Luis Rascão for providing a most useful example.
This commit is contained in:
parent
144cb8c156
commit
9f057f29c5
7 changed files with 175 additions and 0 deletions
4
inttest/proto_protobuffs/include/.gitignore
vendored
Normal file
4
inttest/proto_protobuffs/include/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
79
inttest/proto_protobuffs/proto_protobuffs_rt.erl
Normal file
79
inttest/proto_protobuffs/proto_protobuffs_rt.erl
Normal file
|
@ -0,0 +1,79 @@
|
|||
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
||||
%% ex: ts=4 sw=4 et
|
||||
%% -------------------------------------------------------------------
|
||||
%%
|
||||
%% rebar: Erlang Build Tools
|
||||
%%
|
||||
%% Copyright (c) 2014 Tomas Abrahamsson (tomas.abrahamsson@gmail.com)
|
||||
%%
|
||||
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
%% of this software and associated documentation files (the "Software"), to deal
|
||||
%% in the Software without restriction, including without limitation the rights
|
||||
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
%% copies of the Software, and to permit persons to whom the Software is
|
||||
%% furnished to do so, subject to the following conditions:
|
||||
%%
|
||||
%% The above copyright notice and this permission notice shall be included in
|
||||
%% all copies or substantial portions of the Software.
|
||||
%%
|
||||
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
%% THE SOFTWARE.
|
||||
%% -------------------------------------------------------------------
|
||||
-module(proto_protobuffs_rt).
|
||||
-export([files/0,
|
||||
run/1]).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(MODULES,
|
||||
[foo,
|
||||
foo_app,
|
||||
foo_sup,
|
||||
test_pb]).
|
||||
|
||||
-define(BEAM_FILES,
|
||||
["foo.beam",
|
||||
"foo_app.beam",
|
||||
"foo_sup.beam",
|
||||
"test_pb.beam"]).
|
||||
|
||||
files() ->
|
||||
[
|
||||
{copy, "../../rebar", "rebar"},
|
||||
{copy, "rebar.config", "rebar.config"},
|
||||
{copy, "include", "include"},
|
||||
{copy, "src", "src"},
|
||||
{create, "ebin/foo.app", app(foo, ?MODULES)}
|
||||
].
|
||||
|
||||
run(_Dir) ->
|
||||
?assertMatch({ok, _}, retest_sh:run("./rebar prepare-deps", [])),
|
||||
?assertMatch({ok, _}, retest_sh:run("./rebar clean", [])),
|
||||
?assertMatch({ok, _}, retest_sh:run("./rebar compile", [])),
|
||||
ok = check_beams_generated(),
|
||||
ok.
|
||||
|
||||
check_beams_generated() ->
|
||||
lists:foreach(
|
||||
fun(F) ->
|
||||
File = filename:join("ebin", F),
|
||||
?assert(filelib:is_regular(File))
|
||||
end,
|
||||
?BEAM_FILES).
|
||||
|
||||
%%
|
||||
%% 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, gpb]}]},
|
||||
io_lib:format("~p.\n", [App]).
|
18
inttest/proto_protobuffs/rebar.config
Normal file
18
inttest/proto_protobuffs/rebar.config
Normal file
|
@ -0,0 +1,18 @@
|
|||
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
||||
%% ex: ts=4 sw=4 ft=erlang et
|
||||
|
||||
{erl_opts,
|
||||
[
|
||||
{i, "deps/protobuffs/include"},
|
||||
{platform_define, "R13|R14", 'NO_CALLBACK_ATTRIBUTE'}
|
||||
]}.
|
||||
|
||||
{deps,
|
||||
[
|
||||
{protobuffs, [], {git, "git://github.com/basho/erlang_protobuffs",
|
||||
{branch, "master"}}}
|
||||
]}.
|
||||
|
||||
%% The default proto compiler is protobuffs
|
||||
%% so don't need to specify this
|
||||
%% {proto_compiler, gpb}.
|
35
inttest/proto_protobuffs/src/foo.erl
Normal file
35
inttest/proto_protobuffs/src/foo.erl
Normal file
|
@ -0,0 +1,35 @@
|
|||
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
||||
%% ex: ts=4 sw=4 et
|
||||
-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("../include/test_pb.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}.
|
12
inttest/proto_protobuffs/src/foo_app.erl
Normal file
12
inttest/proto_protobuffs/src/foo_app.erl
Normal file
|
@ -0,0 +1,12 @@
|
|||
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
||||
%% ex: ts=4 sw=4 et
|
||||
-module(foo_app).
|
||||
|
||||
-behaviour(application).
|
||||
|
||||
-export([start/2,
|
||||
stop/1]).
|
||||
|
||||
start(_Type, _Args) -> foo_sup:start_link().
|
||||
|
||||
stop(_State) -> ok.
|
15
inttest/proto_protobuffs/src/foo_sup.erl
Normal file
15
inttest/proto_protobuffs/src/foo_sup.erl
Normal file
|
@ -0,0 +1,15 @@
|
|||
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
||||
%% ex: ts=4 sw=4 et
|
||||
-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]}}.
|
12
inttest/proto_protobuffs/src/test.proto
Normal file
12
inttest/proto_protobuffs/src/test.proto
Normal file
|
@ -0,0 +1,12 @@
|
|||
// -*- c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
// ex: ts=4 sw=4 et
|
||||
|
||||
message m1
|
||||
{
|
||||
optional string str = 1;
|
||||
}
|
||||
|
||||
message m2
|
||||
{
|
||||
optional string str = 1;
|
||||
}
|
Loading…
Reference in a new issue