diff options
| author | Tom Davies <todavies5@gmail.com> | 2022-04-28 05:52:59 -0700 |
|---|---|---|
| committer | Tom Davies <tomdavies@fb.com> | 2022-05-06 09:28:12 -0700 |
| commit | ebda708801eec74a8313fef050296b9785c1b8ee (patch) | |
| tree | 5c2efc1f30255f2f0a669893c6eff751ddfe4ee8 /lib/asn1/test | |
| parent | af9b14c25f842ac590bc23f9e9dd84a67f765e10 (diff) | |
| download | erlang-ebda708801eec74a8313fef050296b9785c1b8ee.tar.gz | |
compiler: Make asn1ct_gen respect +deterministic
Makes asn1ct_gen filter out potentially non-deterministic attributes
from generated .erl files when +deterministic is set.
Diffstat (limited to 'lib/asn1/test')
| -rw-r--r-- | lib/asn1/test/asn1_SUITE.erl | 3 | ||||
| -rw-r--r-- | lib/asn1/test/test_compile_options.erl | 48 |
2 files changed, 49 insertions, 2 deletions
diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl index eeb5253c32..2a02f08a95 100644 --- a/lib/asn1/test/asn1_SUITE.erl +++ b/lib/asn1/test/asn1_SUITE.erl @@ -1062,7 +1062,8 @@ test_compile_options(Config) -> ok = test_compile_options:noobj(Config), ok = test_compile_options:record_name_prefix(Config), ok = test_compile_options:verbose(Config), - ok = test_compile_options:maps(Config). + ok = test_compile_options:maps(Config), + ok = test_compile_options:determinism(Config). testDoubleEllipses(Config) -> test(Config, fun testDoubleEllipses/3). testDoubleEllipses(Config, Rule, Opts) -> diff --git a/lib/asn1/test/test_compile_options.erl b/lib/asn1/test/test_compile_options.erl index f9997d37d0..45e8f39d39 100644 --- a/lib/asn1/test/test_compile_options.erl +++ b/lib/asn1/test/test_compile_options.erl @@ -22,10 +22,11 @@ -module(test_compile_options). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). -export([wrong_path/1,comp/2,path/1,noobj/1, - record_name_prefix/1,verbose/1,maps/1]). + record_name_prefix/1,verbose/1,maps/1,determinism/1]). %% OTP-5689 wrong_path(Config) -> @@ -150,6 +151,51 @@ do_maps(Erule, InFile, OutDir) -> ok. +determinism(Config) when is_list(Config) -> + DataDir = proplists:get_value(data_dir,Config), + OutDir = proplists:get_value(priv_dir,Config), + Asn1File = filename:join([DataDir,"Comment.asn"]), + ErlFile = filename:join([OutDir,"Comment.erl"]), + + ContainsNonDeterministicOptions = + fun + ({attribute,_Anno,asn1_info,Elems}) -> + lists:any( + fun + ({options, Opts}) -> + lists:any(fun ({i, _}) -> true; (_) -> false end, Opts) + andalso + lists:any(fun ({outdir, _}) -> true; (_) -> false end, Opts) + andalso + lists:any(fun ({cwd, _}) -> true; (_) -> false end, Opts); + (_) -> + false + end, + Elems); + (_) -> + false + end, + + BaseOptions = [{i,DataDir},{outdir,OutDir},{cwd,DataDir},noobj], + + %% Test deterministic compile + ok = asn1ct:compile(Asn1File, BaseOptions ++ [deterministic]), + {ok, List1} = epp:parse_file(ErlFile, [{includes, [DataDir]}, + {source_name, "Comment.erl"}]), + ?assertNot(lists:any(ContainsNonDeterministicOptions, List1), + "Expected no debugging option values (i, outdir, cwd) in asn1_info attribute " ++ + "in deterministic mode"), + + %% Test non-deterministic compile + ok = asn1ct:compile(Asn1File, BaseOptions), + {ok, List2} = epp:parse_file(ErlFile, [{includes, [DataDir]}, + {source_name, "Comment.erl"}]), + ?assert(lists:any(ContainsNonDeterministicOptions, List2), + "Expected debugging option values (i, outdir, cwd) in asn1_info attribute " ++ + "in non-deterministic mode"), + ok. + + outfiles_check(OutDir) -> outfiles_check(OutDir,outfiles1()). |
