File 7313-compiler-Update-property-tests-to-use-ct-property-fr.patch of Package erlang
From 3c1cad2076c26b6ba6bff3934564a50fc994dc11 Mon Sep 17 00:00:00 2001
From: Dan Gudmundsson <dgud@erlang.org>
Date: Mon, 2 Mar 2026 17:01:04 +0100
Subject: [PATCH 3/6] compiler: Update property tests to use ct property
framwork
Make the tests run with Quickcheck, the
`random_code_SUITE.erl` (compile_prop) requires
'proper_erlang_abstract_code' module to work, so that is skipped
if Quickcheck is used.
---
.../test/property_test/beam_types_prop.erl | 52 +++++++----------
.../test/property_test/compile_prop.erl | 58 ++++++++++++-------
lib/compiler/test/random_code_SUITE.erl | 21 ++++---
3 files changed, 72 insertions(+), 59 deletions(-)
diff --git a/lib/compiler/test/property_test/compile_prop.erl b/lib/compiler/test/property_test/compile_prop.erl
index 460fa5f363..e15a31307e 100644
--- a/lib/compiler/test/property_test/compile_prop.erl
+++ b/lib/compiler/test/property_test/compile_prop.erl
@@ -23,33 +23,43 @@
-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.
+%% This module only supports proper, it requires
+%% the 'proper_erlang_abstract_code' functionality
--proptest([proper]).
-
--ifdef(PROPER).
+-include_lib("common_test/include/ct_property_test.hrl").
-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]).
-compile() ->
+-ifdef(PROPER).
+
+prop_compile() ->
%% {weight, {yes_multi_field_init, 0}}
Opts = [{weight, {yes_multi_field_init, 0}},
{resize,true}],
?FORALL(Abstr, proper_erlang_abstract_code:module(Opts),
- compile(Abstr)).
+ compile(noenv_forms, Abstr, compiler_variants())).
+
+-else.
+-ifdef(EQC).
-compile(Forms) ->
- compile(Forms, compiler_variants()).
+prop_compile() ->
+ Opts = [{macros, false}],
+ ?FORALL(String, eqc_erlang_program:module(eqc_generated_module, Opts),
+ begin
+ ok = file:write_file("eqc_generated_module.erl", String),
+ compile(noenv_file, "eqc_generated_module.erl", compiler_variants())
+ end).
-compile(Forms, [Opts|OptsL]) ->
- case spawn_compile(Forms, [return, binary | Opts]) of
+-endif.
+-endif.
+
+
+compile(Function, FileOrForms, [Opts|OptsL]) ->
+ AllOpts = [report_errors, return, binary, {feature,compr_assign,enable} | Opts],
+ case spawn_compile(Function, FileOrForms, AllOpts) of
{ok,_Mod,Bin,_EsWs} when is_binary(Bin) ->
%% Uncomment the following lines to print
%% the generated source code.
@@ -59,20 +69,26 @@ compile(Forms, [Opts|OptsL]) ->
%% Uncomment the following line to print the
%% generated abstract code.
%% io:format("<abstr>\n~p\n</abstr>\n", [Forms]),
- compile(Forms, OptsL);
+ compile(Function, FileOrForms, OptsL);
Err ->
io:format("compile: ~p\n", [Err]),
io:format("with options ~p\n", [Opts]),
- io:format("<S>\n~ts\n</S>\n",
- [[erl_pp:form(F) || F <- Forms]]),
+ case Function of
+ noenv_file ->
+ {ok, Str} = file:read_file(FileOrForms),
+ io:format("~s",[Str]);
+ noenv_forms ->
+ io:format("<S>\n~ts\n</S>\n",
+ [[erl_pp:form(F) || F <- FileOrForms]])
+ end,
false
end;
-compile(_Forms, []) ->
+compile(_, _FileOrForms, []) ->
true.
-spawn_compile(Forms, Options) ->
+spawn_compile(Compile, Forms, Options) ->
{Pid,Ref} = spawn_monitor(fun() ->
- exit(compile:noenv_forms(Forms, Options))
+ exit(compile:Compile(Forms, Options))
end),
receive
{'DOWN',Ref,process,Pid,Ret} ->
@@ -95,5 +111,3 @@ compiler_variants() ->
[no_copt,no_bool_opt,no_share_opt,no_bsm_opt,no_fun_opt,
no_ssa_opt,no_recv_opt,ssalint,clint0]
].
-
--endif.
diff --git a/lib/compiler/test/random_code_SUITE.erl b/lib/compiler/test/random_code_SUITE.erl
index 38bc86c5d4..1493865301 100644
--- a/lib/compiler/test/random_code_SUITE.erl
+++ b/lib/compiler/test/random_code_SUITE.erl
@@ -38,9 +38,11 @@ all() ->
init_per_suite(Config0) ->
case ct_property_test:init_per_suite(Config0) of
[_|_]=Config ->
- try proper_erlang_abstract_code:module() of
+ try proplists:get_value(property_test_tool, Config) of
+ Prop when Prop =:= proper; Prop =:= eqc ->
+ Config;
_ ->
- Config
+ {skip,"No proper_erlang_abstract_code module"}
catch
error:undef ->
{skip,"No proper_erlang_abstract_code module"}
@@ -52,7 +54,7 @@ init_per_suite(Config0) ->
end_per_suite(Config) ->
Config.
-compile(_Config) ->
+compile(Config) ->
NumTests = case os:getenv("ERL_RANDOM_CODE_NUMTESTS") of
false ->
?NUMTESTS;
@@ -60,11 +62,16 @@ compile(_Config) ->
list_to_integer(NumTests0)
end,
- %% Conservatively assume that we can run 10 tests each
+ %% Conservatively assume that we can run 5 tests each
%% second.
- TimeTrap = {seconds, (60 + (NumTests+9) div 10)},
+ TimeTrap = {seconds, (60 + (NumTests+4) div 5)},
ct:timetrap(TimeTrap),
io:format("~p tests\n", [NumTests]),
- true = proper:quickcheck(compile_prop:compile(),
- [quiet,{numtests,NumTests}]),
+ case proplists:get_value(property_test_tool, Config) of
+ proper ->
+ Opts = [quiet,{numtests,NumTests}],
+ true = proper:quickcheck(compile_prop:prop_compile(),Opts);
+ eqc -> %% Half the number of tests for eqc
+ [] = eqc:module({numtests,?NUMTESTS div 2}, compile_prop)
+ end,
ok.
--
2.51.0