diff options
author | zadean <[email protected]> | 2019-08-19 14:47:32 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2019-08-22 14:08:40 +0200 |
commit | 19697637a41f7e5199f017abae44bac5e7367c57 (patch) | |
tree | be3c92979dafb9ce40e125b7229da0da426e690d | |
parent | 98462d8ec91dc34a06f5a2801c906ca1a0dd4ba1 (diff) | |
download | otp-19697637a41f7e5199f017abae44bac5e7367c57.tar.gz otp-19697637a41f7e5199f017abae44bac5e7367c57.tar.bz2 otp-19697637a41f7e5199f017abae44bac5e7367c57.zip |
Update test suite
Add record with exact and associated map types to type_specs.erl. The
record forces the erl_parse format for map types to be retained.
Add test wrapped_subtrees to the test suite. It ensures that each
erl_parse node it encounters can be wrapped and accessed with
erl_syntax:subtrees/1 without error.
-rw-r--r-- | lib/syntax_tools/test/syntax_tools_SUITE.erl | 36 | ||||
-rw-r--r-- | lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl | 3 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/syntax_tools/test/syntax_tools_SUITE.erl b/lib/syntax_tools/test/syntax_tools_SUITE.erl index 43c17e9f1f..cabd29cb56 100644 --- a/lib/syntax_tools/test/syntax_tools_SUITE.erl +++ b/lib/syntax_tools/test/syntax_tools_SUITE.erl @@ -26,6 +26,7 @@ %% Test cases -export([app_test/1,appup_test/1,smoke_test/1,revert/1,revert_map/1, + wrapped_subtrees/1, t_abstract_type/1,t_erl_parse_type/1,t_epp_dodger/1, t_comment_scan/1,t_igor/1,t_erl_tidy/1]). @@ -33,6 +34,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [app_test,appup_test,smoke_test,revert,revert_map, + wrapped_subtrees, t_abstract_type,t_erl_parse_type,t_epp_dodger, t_comment_scan,t_igor,t_erl_tidy]. @@ -124,6 +126,40 @@ revert_map(Config) when is_list(Config) -> ?t:timetrap_cancel(Dog). +%% Read with erl_parse, wrap each tree node with erl_syntax and check that +%% erl_syntax:subtrees can access the wrapped node. +wrapped_subtrees(Config) when is_list(Config) -> + Dog = ?t:timetrap(?t:minutes(2)), + Wc = filename:join([code:lib_dir(stdlib),"src","*.erl"]), + Fs = filelib:wildcard(Wc) ++ test_files(Config), + Path = [filename:join(code:lib_dir(stdlib), "include"), + filename:join(code:lib_dir(kernel), "include")], + io:format("~p files\n", [length(Fs)]), + Map = fun (File) -> wrapped_subtrees_file(File, Path) end, + case p_run(Map, Fs) of + 0 -> ok; + N -> ?t:fail({N,errors}) + end, + ?t:timetrap_cancel(Dog). + +wrapped_subtrees_file(File, Path) -> + case epp:parse_file(File, Path, []) of + {ok,Fs0} -> + lists:foreach(fun wrap_each/1, Fs0) + end. + +wrap_each(Tree) -> + % only `wrap` top-level erl_parse node + Tree1 = erl_syntax:set_pos(Tree, erl_syntax:get_pos(Tree)), + % assert ability to access subtrees of wrapped node with erl_syntax:subtrees/1 + case erl_syntax:subtrees(Tree1) of + [] -> ok; + List -> + GrpsF = fun(Group) -> + lists:foreach(fun wrap_each/1, Group) + end, + lists:foreach(GrpsF, List) + end. %% api tests diff --git a/lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl b/lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl index e4f8a1c3de..b23acdb39e 100644 --- a/lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl +++ b/lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl @@ -37,6 +37,9 @@ -record(par, {a :: undefined | ?MODULE}). +-record(mt, {e :: #{any() := any()}, + a :: #{any() => any()}}). + -record(r0, {}). -record(r, |