From 17303e17116415e7758e96530814b0a6f3f9a93f Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Thu, 16 Jan 2014 12:19:42 +0100 Subject: Compiler suite fix An error when expecting success wasn't regarded as failure when compiling dictionaries. --- lib/diameter/test/diameter_compiler_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index ed369e8af3..cc423d5bc6 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2013. All Rights Reserved. +%% Copyright Ericsson AB 2010-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -397,7 +397,7 @@ replace({E, Mods}, Bin) -> case {E, parse(B, [{include, here()}]), Mods} of {ok, {ok, Dict}, _} -> Dict; - {_, {error, S}, _} -> + {_, {error, S}, _} when E /= ok -> S end. -- cgit v1.2.3 From 3f79e7bd7e743ffd40b624caf680aef2bdb15dc7 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Thu, 16 Jan 2014 12:57:43 +0100 Subject: Don't format diameter_make:codec/2 errors Instead, add diameter_make:format_error/1 to allow the caller to format if desired, which is what applications like compiler and yecc do. Use this to check that the expected error is the one actually generated in the compiler suite. --- lib/diameter/bin/diameterc | 4 ++-- lib/diameter/doc/src/diameter_make.xml | 18 +++++++++++++++++- lib/diameter/doc/src/seealso.ent | 3 ++- lib/diameter/src/compiler/diameter_make.erl | 14 ++++++++++---- lib/diameter/test/diameter_compiler_SUITE.erl | 4 ++-- 5 files changed, 33 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/diameter/bin/diameterc b/lib/diameter/bin/diameterc index d31f341c36..2c9a8f555c 100755 --- a/lib/diameter/bin/diameterc +++ b/lib/diameter/bin/diameterc @@ -4,7 +4,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2013. All Rights Reserved. +%% Copyright Ericsson AB 2010-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -74,7 +74,7 @@ compile(#argv{file = File, options = Opts, output = Out}) -> ok -> 0; {error, Reason} -> - error_msg(Reason, []), + error_msg(diameter_make:format_error(Reason), []), 1 catch error: Reason -> diff --git a/lib/diameter/doc/src/diameter_make.xml b/lib/diameter/doc/src/diameter_make.xml index 1c1eff6c6a..16ef49d4b2 100644 --- a/lib/diameter/doc/src/diameter_make.xml +++ b/lib/diameter/doc/src/diameter_make.xml @@ -16,7 +16,7 @@
2012 -2013 +2014 Ericsson AB. All Rights Reserved. @@ -175,6 +175,10 @@ Note that a dictionary's &dict_name;, together with the The &dict_name; of a literal input dictionary defaults to dictionary.

+

+A returned error reason can be converted into a readable string using +&format_error;.

+ @@ -206,6 +210,18 @@ The return value is also a parsed dictionary.

+ + + +format_error(Reason) -> string() +Turn an error reason into a readable string. + + +

+Turn an error reason returned by &codec; into a readable string.

+
+
+ diff --git a/lib/diameter/doc/src/seealso.ent b/lib/diameter/doc/src/seealso.ent index 7bf7460351..44541afb9b 100644 --- a/lib/diameter/doc/src/seealso.ent +++ b/lib/diameter/doc/src/seealso.ent @@ -4,7 +4,7 @@ %CopyrightBegin% -Copyright Ericsson AB 2012-2013. All Rights Reserved. +Copyright Ericsson AB 2012-2014. All Rights Reserved. The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in @@ -117,6 +117,7 @@ significant. diameter_make:codec/2'> diameter_make:format/1'> diameter_make:flatten/1'> +diameter_make:format_error/1'> diff --git a/lib/diameter/src/compiler/diameter_make.erl b/lib/diameter/src/compiler/diameter_make.erl index 2f314b7e57..adc7808e49 100644 --- a/lib/diameter/src/compiler/diameter_make.erl +++ b/lib/diameter/src/compiler/diameter_make.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2013. All Rights Reserved. +%% Copyright Ericsson AB 2010-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -33,7 +33,8 @@ -export([codec/2, codec/1, format/1, - flatten/1]). + flatten/1, + format_error/1]). -export_type([opt/0]). @@ -81,8 +82,8 @@ codec(File, Opts) -> case parse(Dict, Opts) of {ok, ParseD} -> make(Path, default(Opts), ParseD); - {error = E, Reason} -> - {E, diameter_dict_util:format_error(Reason)} + {error, _} = E -> + E end. codec(File) -> @@ -115,6 +116,11 @@ flatten([?VERSION = V | Dict]) -> [grouped, import_groups], [enum, import_enums]])]. +%% format_error/1 + +format_error(T) -> + diameter_dict_util:format_error(T). + %% =========================================================================== %% flatten/2 diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index cc423d5bc6..0b053219cd 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -397,8 +397,8 @@ replace({E, Mods}, Bin) -> case {E, parse(B, [{include, here()}]), Mods} of {ok, {ok, Dict}, _} -> Dict; - {_, {error, S}, _} when E /= ok -> - S + {_, {error, {E,_} = T}, _} when E /= ok -> + diameter_make:format_error(T) end. re({RE, Repl}, Bin) -> -- cgit v1.2.3 From 2b802628b59b7208b1c936309807f86745a3b6a0 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Thu, 16 Jan 2014 13:17:33 +0100 Subject: Ensure that Grouped AVP's are fully defined in dictionaries The case in which an AVP was defined as having type Grouped in @avp_types without a corresponding specification in @grouped was missing. --- lib/diameter/src/compiler/diameter_dict_util.erl | 37 +++++++++++++++--------- lib/diameter/test/diameter_compiler_SUITE.erl | 3 ++ 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/diameter/src/compiler/diameter_dict_util.erl b/lib/diameter/src/compiler/diameter_dict_util.erl index 3941f30e03..136bba16cb 100644 --- a/lib/diameter/src/compiler/diameter_dict_util.erl +++ b/lib/diameter/src/compiler/diameter_dict_util.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2013. All Rights Reserved. +%% Copyright Ericsson AB 2010-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -155,6 +155,8 @@ fmt(grouped_avp_has_wrong_type) -> "Grouped AVP ~s at line ~p defined with type ~s at line ~p"; fmt(grouped_avp_not_defined) -> "Grouped AVP ~s on line ~p not defined in @avp_types"; +fmt(grouped_avp_not_grouped) -> + "Grouped AVP ~s on line ~p not defined in @grouped"; fmt(grouped_vendor_id_without_flag) -> "Grouped AVP ~s at line ~p has vendor id " "but definition at line ~p does not specify V flag"; @@ -401,9 +403,9 @@ read(File) -> {ok, iolist_to_binary([File])}. make_dict(Parse, Opts) -> - make_orddict(pass4(pass3(pass2(pass1(reset(make_dict(Parse), - Opts))), - Opts))). + Dict = pass3(pass2(pass1(reset(make_dict(Parse), Opts))), Opts), + ok = examine(Dict), + make_orddict(Dict). %% make_orddict/1 @@ -1168,7 +1170,7 @@ import_avps(Dict, Opts) -> Import = inherit(Dict, Opts), report(imported, Import), - %% pass4/1 tests that all referenced AVP's are either defined + %% examine/1 tests that all referenced AVP's are either defined %% or imported. dict:store(import_avps, @@ -1276,21 +1278,21 @@ dict(Mod) -> end. %% =========================================================================== -%% pass4/1 +%% examine/1 %% %% Sanity checks. -pass4(Dict) -> - dict:fold(fun(K, V, _) -> p4(K, V, Dict) end, ok, Dict), - Dict. +examine(Dict) -> + dict:fold(fun(K, V, _) -> x(K, V, Dict) end, ok, Dict), + ok. %% Ensure enum AVP's have type Enumerated. -p4({enum, Name}, [Line | _], Dict) +x({enum, Name}, [Line | _], Dict) when is_list(Name) -> true = is_enumerated_avp(Name, Dict, Line); %% Ensure all referenced AVP's are either defined locally or imported. -p4({K, {Name, AvpName}}, [Line | _], Dict) +x({K, {Name, AvpName}}, [Line | _], Dict) when (K == grouped orelse K == messages), is_list(Name), is_list(AvpName), @@ -1298,13 +1300,22 @@ p4({K, {Name, AvpName}}, [Line | _], Dict) true = avp_is_defined(AvpName, Dict, Line); %% Ditto. -p4({K, AvpName}, [Line | _], Dict) +x({K, AvpName}, [Line | _], Dict) when K == avp_vendor_id; K == custom_types; K == codecs -> true = avp_is_defined(AvpName, Dict, Line); -p4(_, _, _) -> +%% Ensure that all local AVP's of type Grouped are also present in @grouped. +x({avp_types, Name}, [Line | Toks], Dict) + when 0 < Line, is_list(Name) -> + [{number, _, _Code}, {word, _, Type}, {word, _, _Flags}] = Toks, + "Grouped" == Type + andalso error == dict:find({grouped, Name}, Dict) + andalso ?RETURN(grouped_avp_not_grouped, [Name, Line]), + ok; + +x(_, _, _) -> ok. %% has_enumerated_type/3 diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index 0b053219cd..df4dde6240 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -138,6 +138,9 @@ {grouped_avp_not_defined, "Failed-AVP *.*", ""}, + {grouped_avp_not_grouped, + "Failed-AVP ::=.*\n.*}", + ""}, {grouped_vendor_id_without_flag, "(Failed-AVP .*)>", "\\1 668>"}, -- cgit v1.2.3