summaryrefslogtreecommitdiff
path: root/lib/parsetools/test/yecc_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parsetools/test/yecc_SUITE.erl')
-rw-r--r--lib/parsetools/test/yecc_SUITE.erl73
1 files changed, 55 insertions, 18 deletions
diff --git a/lib/parsetools/test/yecc_SUITE.erl b/lib/parsetools/test/yecc_SUITE.erl
index 5162315076..e76b98f0f5 100644
--- a/lib/parsetools/test/yecc_SUITE.erl
+++ b/lib/parsetools/test/yecc_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2005-2021. All Rights Reserved.
+%% Copyright Ericsson AB 2005-2022. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
%-define(debug, true).
-include_lib("stdlib/include/erl_compile.hrl").
+-include_lib("stdlib/include/assert.hrl").
-ifdef(debug).
-define(config(X,Y), foo).
@@ -40,7 +41,7 @@
-export([app_test/1,
file/1, syntax/1, compile/1, rules/1, expect/1,
- conflicts/1,
+ conflicts/1, deterministic/1,
empty/1, prec/1, yeccpre/1, lalr/1, old_yecc/1,
other_examples/1,
@@ -70,7 +71,7 @@ all() ->
groups() ->
[{checks, [],
- [file, syntax, compile, rules, expect, conflicts]},
+ [file, syntax, compile, rules, expect, conflicts, deterministic]},
{examples, [],
[empty, prec, yeccpre, lalr, old_yecc, other_examples]},
{bugs, [],
@@ -269,7 +270,7 @@ syntax(Config) when is_list(Config) ->
nt -> t.">>),
{ok,_,[{_,[{{2,13},yecc,bad_declaration}]}]} =
yecc:file(Filename, Ret),
- ?line {ok,_,[{_,[{2,yecc,bad_declaration}]}]} =
+ {ok,_,[{_,[{2,yecc,bad_declaration}]}]} =
yecc:file(Filename, [{error_location, line} | Ret]),
%% Syntax error found by yeccparser.
@@ -926,6 +927,43 @@ conflicts(Config) when is_list(Config) ->
file:delete(Filename),
ok.
+deterministic(doc) ->
+ "Check yecc respects the +deterministic flag.";
+deterministic(suite) -> [];
+deterministic(Config) when is_list(Config) ->
+ Dir = ?privdir,
+ Filename = filename:join(Dir, "file.yrl"),
+ Parserfile = filename:join(Dir, "file.erl"),
+ ok = file:write_file(Filename,
+ <<"Nonterminals nt.
+ Terminals t.
+ Rootsymbol nt.
+ nt -> t.">>),
+
+ %% Generated yecc parsers need to include the yeccpre.hrl
+ %% header file, so we'll get a -file attribute corresponding
+ %% to that include. In deterministic mode, that include should
+ %% only use the basename, "yeccpre.hrl", but otherwise, it should
+ %% contain the full path.
+
+ %% Matches when OTP is not installed (e.g. /lib/parsetools/include/yeccpre.hrl)
+ %% and when it is (e.g. /lib/parsetools-2.3.2/include/yeccpre.hrl)
+ AbsolutePathSuffix = "/lib/parsetools.*/include/yeccpre\.hrl",
+
+ ok = yecc:compile(Filename, Parserfile, #options{specific=[deterministic]}),
+ {ok, FormsDet} = epp:parse_file(Parserfile,[]),
+ ?assertMatch(false, search_for_file_attr(AbsolutePathSuffix, FormsDet)),
+ ?assertMatch({value, _}, search_for_file_attr("yeccpre\.hrl", FormsDet)),
+ file:delete(Parserfile),
+
+ ok = yecc:compile(Filename, Parserfile, #options{}),
+ {ok, Forms} = epp:parse_file(Parserfile,[]),
+ ?assertMatch({value, _}, search_for_file_attr(AbsolutePathSuffix, Forms)),
+ file:delete(Parserfile),
+
+ file:delete(Filename),
+ ok.
+
empty(doc) ->
"'$empty'.";
empty(suite) -> [];
@@ -1851,7 +1889,7 @@ otp_7969(Config) when is_list(Config) ->
ok.
otp_8919(doc) ->
- "OTP-8919. Improve formating of Yecc error messages.";
+ "OTP-8919. Improve formatting of Yecc error messages.";
otp_8919(suite) -> [];
otp_8919(Config) when is_list(Config) ->
A1 = erl_anno:new(1),
@@ -2042,7 +2080,7 @@ otp_11286(doc) ->
"OTP-11286. A Unicode filename bug; both Leex and Yecc.";
otp_11286(suite) -> [];
otp_11286(Config) when is_list(Config) ->
- Node = start_node(otp_11286, "+fnu"),
+ {ok, Peer, Node} = ?CT_PEER(["+fnu"]),
Dir = ?privdir,
UName = [1024] ++ "u",
UDir = filename:join(Dir, UName),
@@ -2082,7 +2120,7 @@ otp_11286(Config) when is_list(Config) ->
Opts = [return, warn_unused_vars,{outdir,Dir}],
{ok,_,_} = rpc:call(Node, compile, file, [ErlFile, Opts]),
- true = test_server:stop_node(Node),
+ peer:stop(Peer),
ok.
otp_14285(Config) ->
@@ -2214,17 +2252,6 @@ otp_17535(Config) when is_list(Config) ->
{ok, _, []} = compile:file(ErlFile, [return]),
ok.
-start_node(Name, Args) ->
- [_,Host] = string:tokens(atom_to_list(node()), "@"),
- ct:log("Trying to start ~w@~s~n", [Name,Host]),
- case test_server:start_node(Name, peer, [{args,Args}]) of
- {error,Reason} ->
- ct:fail(Reason);
- {ok,Node} ->
- ct:log("Node ~p started~n", [Node]),
- Node
- end.
-
yeccpre_size() ->
yeccpre_size(default_yeccpre()).
@@ -2295,3 +2322,13 @@ process_list() ->
safe_second_element({_,Info}) -> Info;
safe_second_element(Other) -> Other.
+
+search_for_file_attr(PartialFilePathRegex, Forms) ->
+ lists:search(fun
+ ({attribute, _, file, {FileAttr, _}}) ->
+ case re:run(FileAttr, PartialFilePathRegex) of
+ nomatch -> false;
+ _ -> true
+ end;
+ (_) -> false end,
+ Forms).