aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2011-12-08 00:35:46 +0100
committerAnders Svensson <[email protected]>2011-12-08 00:52:22 +0100
commitff859b3877f628e9d71373baef7f73f9fb5be2de (patch)
treebe286ccf20b2ed21a0dbfdae82a61e1c29a8c3cd
parentb4ecd2efd32df9d14d3314b705cd1114de7141ae (diff)
downloadotp-ff859b3877f628e9d71373baef7f73f9fb5be2de.tar.gz
otp-ff859b3877f628e9d71373baef7f73f9fb5be2de.tar.bz2
otp-ff859b3877f628e9d71373baef7f73f9fb5be2de.zip
Add compiler testcases for generation and compilation to beam
-rw-r--r--lib/diameter/test/diameter_compiler_SUITE.erl41
1 files changed, 39 insertions, 2 deletions
diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl
index 8f563ff2ab..66d788f6ec 100644
--- a/lib/diameter/test/diameter_compiler_SUITE.erl
+++ b/lib/diameter/test/diameter_compiler_SUITE.erl
@@ -30,13 +30,15 @@
%% testcases
-export([format/1, format/2,
- replace/1, replace/2]).
+ replace/1, replace/2,
+ generate/1, generate/4, generate/0]).
-export([dict/0]). %% fake dictionary module
-define(base, "base_rfc3588.dia").
-define(util, diameter_util).
-define(S, atom_to_list).
+-define(L, integer_to_list).
%% ===========================================================================
@@ -332,7 +334,8 @@ suite() ->
all() ->
[format,
- replace].
+ replace,
+ generate].
%% Error handling testcases will make an erroneous dictionary out of
%% the base dictionary and check that the expected error results.
@@ -348,7 +351,10 @@ end_per_suite(_Config) ->
%% ===========================================================================
%% testcases
+%% format/1
+%%
%% Ensure that parse o format is the identity map.
+
format(Config) ->
Bin = proplists:get_value(base, Config),
[] = ?util:run([{?MODULE, [format, M, Bin]}
@@ -362,6 +368,9 @@ format(Mods, Bin) ->
{Dict, Dict} = {Dict, D}.
%% replace/1
+%%
+%% Ensure the expected success/error when parsing a morphed common
+%% dictionary.
replace(Config) ->
Bin = proplists:get_value(base, Config),
@@ -384,6 +393,34 @@ replace({E, Mods}, Bin) ->
re({RE, Repl}, Bin) ->
re:replace(Bin, RE, Repl, [multiline]).
+%% generate/1
+%%
+%% Ensure success when generating code and compiling.
+
+generate() ->
+ [{timetrap, {seconds, length(?REPLACE)}}].
+
+generate(Config) ->
+ Bin = proplists:get_value(base, Config),
+ Rs = lists:zip(?REPLACE, lists:seq(1, length(?REPLACE))),
+ [] = ?util:run([{?MODULE, [generate, M, Bin, N, T]}
+ || {E,N} <- Rs,
+ {ok, M} <- [norm(E)],
+ T <- [erl, hrl, spec]]).
+
+generate(Mods, Bin, N, Mode) ->
+ B = modify(Bin, Mods ++ [{"@name .*", "@name dict" ++ ?L(N)}]),
+ {ok, Dict} = diameter_dict_util:parse(B, []),
+ File = "dict" ++ integer_to_list(N),
+ {_, ok} = {Dict, diameter_codegen:from_dict("dict",
+ Dict,
+ [{name, File},
+ {prefix, "base"},
+ debug],
+ Mode)},
+ Mode == erl
+ andalso ({ok, _} = compile:file(File ++ ".erl", [return_errors])).
+
%% ===========================================================================
modify(Bin, Mods) ->