File 5138-Add-random_code_SUITE.patch of Package erlang
From 68e3c114882eeaf189607dfbc0ac1ba9a4c637de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Thu, 2 Apr 2020 07:53:01 +0200
Subject: [PATCH 18/19] Add random_code_SUITE
random_code_SUITE will generate and compile random code using
the proper_abstr module (if available).
---
lib/compiler/test/Makefile | 1 +
lib/compiler/test/property_test/compile_prop.erl | 59 ++++++++++++++++++++++++
lib/compiler/test/random_code_SUITE.erl | 57 +++++++++++++++++++++++
3 files changed, 117 insertions(+)
create mode 100644 lib/compiler/test/property_test/compile_prop.erl
create mode 100644 lib/compiler/test/random_code_SUITE.erl
diff --git a/lib/compiler/test/Makefile b/lib/compiler/test/Makefile
index 7974ea2440..31434565c3 100644
--- a/lib/compiler/test/Makefile
+++ b/lib/compiler/test/Makefile
@@ -40,6 +40,7 @@ MODULES= \
match_SUITE \
misc_SUITE \
overridden_bif_SUITE \
+ random_code_SUITE \
receive_SUITE \
record_SUITE \
regressions_SUITE \
diff --git a/lib/compiler/test/property_test/compile_prop.erl b/lib/compiler/test/property_test/compile_prop.erl
new file mode 100644
index 0000000000..5fdd6409d6
--- /dev/null
+++ b/lib/compiler/test/property_test/compile_prop.erl
@@ -0,0 +1,59 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2020. 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.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-module(compile_prop).
+-compile([export_all, nowarn_export_all]).
+
+%% This module only supports proper, as we don't have an eqc license to test
+%% with.
+
+-proptest([proper]).
+
+-ifdef(PROPER).
+
+-define(BEAM_TYPES_INTERNAL, true).
+-include_lib("compiler/src/beam_types.hrl").
+
+-include_lib("proper/include/proper.hrl").
+-define(MOD_eqc, proper).
+
+-import(lists, [duplicate/2,foldl/3]).
+
+-define(REPETITIONS, 1000).
+
+compile() ->
+ numtests(?REPETITIONS, compile_1()).
+
+compile_1() ->
+ Opts = [{resize,true}],
+ ?FORALL(Abstr, proper_abstr:module(Opts),
+ ?WHENFAIL(
+ begin
+ io:format("~ts\n", [[erl_pp:form(F) || F <- Abstr]]),
+ compile(Abstr, [binary,report_errors])
+ end,
+ case compile(Abstr, [binary]) of
+ {error, _Es, _Ws} -> false;
+ _ -> true
+ end)).
+
+compile(Abstr, Opts) ->
+ compile:noenv_forms(Abstr, Opts).
+-endif.
diff --git a/lib/compiler/test/random_code_SUITE.erl b/lib/compiler/test/random_code_SUITE.erl
new file mode 100644
index 0000000000..747a9aebd1
--- /dev/null
+++ b/lib/compiler/test/random_code_SUITE.erl
@@ -0,0 +1,57 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2020. 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.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-module(random_code_SUITE).
+
+-export([all/0, suite/0, groups/0,
+ init_per_suite/1, end_per_suite/1]).
+
+-export([compile/1]).
+
+suite() ->
+ [{ct_hooks,[ts_install_cth]}].
+
+all() ->
+ [{group,property_tests}].
+
+groups() ->
+ [{property_tests,[parallel],
+ [compile]}].
+
+init_per_suite(Config0) ->
+ case ct_property_test:init_per_suite(Config0) of
+ [_|_]=Config ->
+ try proper_abstr:module() of
+ _ ->
+ Config
+ catch
+ error:undef ->
+ {skip,"No proper_abstr module"}
+ end;
+ Other ->
+ Other
+ end.
+
+end_per_suite(Config) ->
+ Config.
+
+compile(Config) ->
+ true = ct_property_test:quickcheck(compile_prop:compile(), Config),
+ ok.
--
2.16.4