summaryrefslogtreecommitdiff
path: root/inttest
diff options
context:
space:
mode:
authorLuis Rascao <luis.rascao@miniclip.com>2015-05-05 22:59:17 +0100
committerLuis Rascao <luis.rascao@miniclip.com>2015-05-08 23:34:50 +0100
commit00c9b39d08e8fcc00286c496b67f11962634e52a (patch)
tree087d5519c70dc06db28c8b9d0f96720d88b9e318 /inttest
parentb9f8dd5f5c427b8c8fb08f35c4b9717473364695 (diff)
downloadrebar-00c9b39d08e8fcc00286c496b67f11962634e52a.tar.gz
Add proto gpb error test case
A specific bad.proto file will cause the mock gpb compiler to fail thus improving rebar's coverage of error scenarios
Diffstat (limited to 'inttest')
-rw-r--r--inttest/proto_gpb/mock/gpb/src/gpb_compile.erl5
-rw-r--r--inttest/proto_gpb/proto.bad/a/b/test3.proto19
-rw-r--r--inttest/proto_gpb/proto.bad/a/test2.proto19
-rw-r--r--inttest/proto_gpb/proto.bad/bad.proto19
-rw-r--r--inttest/proto_gpb/proto.bad/c/d/test5.proto19
-rw-r--r--inttest/proto_gpb/proto.bad/c/test4.proto19
-rw-r--r--inttest/proto_gpb/proto.bad/test.proto19
-rw-r--r--inttest/proto_gpb/proto_gpb_rt.erl23
-rw-r--r--inttest/proto_gpb/rebar.bad.config23
9 files changed, 161 insertions, 4 deletions
diff --git a/inttest/proto_gpb/mock/gpb/src/gpb_compile.erl b/inttest/proto_gpb/mock/gpb/src/gpb_compile.erl
index f7c4407..9692271 100644
--- a/inttest/proto_gpb/mock/gpb/src/gpb_compile.erl
+++ b/inttest/proto_gpb/mock/gpb/src/gpb_compile.erl
@@ -29,7 +29,12 @@
%% Simulate gpb compiling some proto files,
%% but generate only enough of what's needed for testing -- dummy stuff only.
+%% if a bad.proto file is supplied then gpb fails
file(Proto, Opts) ->
+ ok = case filename:basename(Proto) of
+ "bad.proto" -> error;
+ _ -> ok
+ end,
Prefix = proplists:get_value(module_name_prefix, Opts, ""),
Suffix = proplists:get_value(module_name_suffix, Opts, ""),
ProtoBase = filename:basename(Proto, ".proto"),
diff --git a/inttest/proto_gpb/proto.bad/a/b/test3.proto b/inttest/proto_gpb/proto.bad/a/b/test3.proto
new file mode 100644
index 0000000..6e3372f
--- /dev/null
+++ b/inttest/proto_gpb/proto.bad/a/b/test3.proto
@@ -0,0 +1,19 @@
+// -*- c-basic-offset: 4; indent-tabs-mode: nil -*-
+// ex: ts=4 sw=4 et
+
+package test3;
+
+service test3
+{
+ rpc testRpc3(RPC_INPUT3) returns (RPC_OUTPUT3);
+}
+
+message RPC_INPUT3
+{
+ optional string str = 1;
+}
+
+message RPC_OUTPUT3
+{
+ optional string str = 1;
+}
diff --git a/inttest/proto_gpb/proto.bad/a/test2.proto b/inttest/proto_gpb/proto.bad/a/test2.proto
new file mode 100644
index 0000000..6a2d1ac
--- /dev/null
+++ b/inttest/proto_gpb/proto.bad/a/test2.proto
@@ -0,0 +1,19 @@
+// -*- c-basic-offset: 4; indent-tabs-mode: nil -*-
+// ex: ts=4 sw=4 et
+
+package test2;
+
+service test2
+{
+ rpc testRpc2(RPC_INPUT2) returns (RPC_OUTPUT2);
+}
+
+message RPC_INPUT2
+{
+ optional string str = 1;
+}
+
+message RPC_OUTPUT2
+{
+ optional string str = 1;
+}
diff --git a/inttest/proto_gpb/proto.bad/bad.proto b/inttest/proto_gpb/proto.bad/bad.proto
new file mode 100644
index 0000000..ebe2274
--- /dev/null
+++ b/inttest/proto_gpb/proto.bad/bad.proto
@@ -0,0 +1,19 @@
+// -*- c-basic-offset: 4; indent-tabs-mode: nil -*-
+// ex: ts=4 sw=4 et
+
+package test;
+
+service test
+{
+ rpc testRpc(RPC_INPUT) returns (RPC_OUTPUT);
+}
+
+message RPC_INPUT
+ // bug introduced intentionally here
+ optional string str = 1;
+}
+
+message RPC_OUTPUT
+{
+ optional string str = 1;
+}
diff --git a/inttest/proto_gpb/proto.bad/c/d/test5.proto b/inttest/proto_gpb/proto.bad/c/d/test5.proto
new file mode 100644
index 0000000..e94b3bc
--- /dev/null
+++ b/inttest/proto_gpb/proto.bad/c/d/test5.proto
@@ -0,0 +1,19 @@
+// -*- c-basic-offset: 4; indent-tabs-mode: nil -*-
+// ex: ts=4 sw=4 et
+
+package test5;
+
+service test5
+{
+ rpc testRpc5(RPC_INPUT5) returns (RPC_OUTPUT5);
+}
+
+message RPC_INPUT5
+{
+ optional string str = 1;
+}
+
+message RPC_OUTPUT5
+{
+ optional string str = 1;
+}
diff --git a/inttest/proto_gpb/proto.bad/c/test4.proto b/inttest/proto_gpb/proto.bad/c/test4.proto
new file mode 100644
index 0000000..3e1de74
--- /dev/null
+++ b/inttest/proto_gpb/proto.bad/c/test4.proto
@@ -0,0 +1,19 @@
+// -*- c-basic-offset: 4; indent-tabs-mode: nil -*-
+// ex: ts=4 sw=4 et
+
+package test4;
+
+service test4
+{
+ rpc testRpc4(RPC_INPUT4) returns (RPC_OUTPUT4);
+}
+
+message RPC_INPUT4
+{
+ optional string str = 1;
+}
+
+message RPC_OUTPUT4
+{
+ optional string str = 1;
+}
diff --git a/inttest/proto_gpb/proto.bad/test.proto b/inttest/proto_gpb/proto.bad/test.proto
new file mode 100644
index 0000000..9b3cf59
--- /dev/null
+++ b/inttest/proto_gpb/proto.bad/test.proto
@@ -0,0 +1,19 @@
+// -*- c-basic-offset: 4; indent-tabs-mode: nil -*-
+// ex: ts=4 sw=4 et
+
+package test;
+
+service test
+{
+ rpc testRpc(RPC_INPUT) returns (RPC_OUTPUT);
+}
+
+message RPC_INPUT
+{
+ optional string str = 1;
+}
+
+message RPC_OUTPUT
+{
+ optional string str = 1;
+}
diff --git a/inttest/proto_gpb/proto_gpb_rt.erl b/inttest/proto_gpb/proto_gpb_rt.erl
index 09fcde2..d17ba34 100644
--- a/inttest/proto_gpb/proto_gpb_rt.erl
+++ b/inttest/proto_gpb/proto_gpb_rt.erl
@@ -56,20 +56,35 @@ files() ->
{copy, "../../rebar", "rebar"},
{copy, "rebar.config", "rebar.config"},
{copy, "rebar2.config", "rebar2.config"},
+ {copy, "rebar.bad.config", "rebar.bad.config"},
{copy, "include", "include"},
{copy, "src", "src"},
{copy, "proto", "proto"},
+ {copy, "proto.bad", "proto.bad"},
{copy, "mock", "deps"},
{create, "ebin/foo.app", app(foo, ?MODULES ++ ?GENERATED_MODULES)}
].
run(_Dir) ->
% perform test obtaining the .proto files from src dir
- ok = run_from_dir("src", "rebar.config"),
+ ok = run_from_dir(success_expected, "src", "rebar.config"),
% perform test obtaining the .proto files from proto dir
- ok = run_from_dir("proto", "rebar2.config").
-
-run_from_dir(ProtoDir, ConfigFile) ->
+ ok = run_from_dir(success_expected, "proto", "rebar2.config"),
+ % perform a test where a failure is expected
+ ok = run_from_dir(fail_expected, "proto.bad", "rebar.bad.config").
+
+run_from_dir(fail_expected, _ProtoDir, ConfigFile) ->
+ %% we expect a fail to happen, however rebar should not crash
+ %% we make sure of that by scanning the error
+ {error, {stopped, {1, Error}}} = retest_sh:run("./rebar --config "
+ ++ ConfigFile
+ ++ " compile",
+ []),
+ %% no matches of the string 'EXIT' should occur, these
+ %% indicate a rebar crash and not a exit with error
+ 0 = string:str(lists:flatten(Error), "'EXIT'"),
+ ok;
+run_from_dir(success_expected, ProtoDir, ConfigFile) ->
?assertMatch({ok, _}, retest_sh:run("./rebar --config "
++ ConfigFile
++ " clean",
diff --git a/inttest/proto_gpb/rebar.bad.config b/inttest/proto_gpb/rebar.bad.config
new file mode 100644
index 0000000..a7ff5ae
--- /dev/null
+++ b/inttest/proto_gpb/rebar.bad.config
@@ -0,0 +1,23 @@
+%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ts=4 sw=4 ft=erlang et
+
+{erl_opts,
+ [
+ {platform_define, "R13|R14", 'NO_CALLBACK_ATTRIBUTE'}
+ ]}.
+
+{deps,
+ [
+ %% The dependency below to gpb is needed for "rebar compile" to
+ %% work, thus for the inttest to work, but the gpb that is actually
+ %% used in inttest is brought in from the inttest/proto_gpb/mock
+ %% subdirectory.
+ {gpb, ".*"}
+ ]}.
+
+{proto_opts, [
+ {compiler, gpb},
+ {src_dirs, ["proto.bad"]}
+]}.
+
+{gpb_opts, [{module_name_suffix, "_gpb"}]}.