File 2711-ct_property_test-add-init_tool-1.patch of Package erlang
From 7b3e7b1f32d0ded8b31c66e5cc402e94dc13f37b Mon Sep 17 00:00:00 2001
From: Tristan Sloughter <t@crashfast.com>
Date: Mon, 18 Feb 2019 13:03:01 -0700
Subject: [PATCH] ct_property_test: add init_tool/1
In cases the user does not want ct_property_test to compile properties
init_tool/1 can be used to set the property_test_tool config value.
---
lib/common_test/src/ct_property_test.erl | 42 +++++++++++++++++++-------------
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/lib/common_test/src/ct_property_test.erl b/lib/common_test/src/ct_property_test.erl
index f51f454d08..d884a6d494 100644
--- a/lib/common_test/src/ct_property_test.erl
+++ b/lib/common_test/src/ct_property_test.erl
@@ -32,27 +32,34 @@
%% API
-export([init_per_suite/1,
- quickcheck/2]).
+ init_tool/1,
+ quickcheck/2]).
-include_lib("common_test/include/ct.hrl").
init_per_suite(Config) ->
+ case init_tool(Config) of
+ {skip, _}=Skip ->
+ Skip;
+ Config1 ->
+ Path = property_tests_path("property_test", Config1),
+ case compile_tests(Path, Config1) of
+ error ->
+ {fail, "Property test compilation failed in "++Path};
+ up_to_date ->
+ add_code_pathz(Path),
+ [{property_dir, Path} | Config1]
+ end
+ end.
+
+init_tool(Config) ->
case which_module_exists([eqc,proper,triq]) of
- {ok,ToolModule} ->
- ct:pal("Found property tester ~p",[ToolModule]),
- Path = property_tests_path("property_test", Config),
- case compile_tests(Path,ToolModule) of
- error ->
- {fail, "Property test compilation failed in "++Path};
- up_to_date ->
- add_code_pathz(Path),
- [{property_dir,Path},
- {property_test_tool,ToolModule} | Config]
- end;
-
- not_found ->
- ct:pal("No property tester found",[]),
- {skip, "No property testing tool found"}
+ {ok, ToolModule} ->
+ ct:pal("Found property tester ~p",[ToolModule]),
+ [{property_test_tool, ToolModule} | Config];
+ not_found ->
+ ct:pal("No property tester found",[]),
+ {skip, "No property testing tool found"}
end.
quickcheck(Property, Config) ->
@@ -105,7 +112,8 @@ add_code_pathz(Dir) ->
ok
end.
-compile_tests(Path, ToolModule) ->
+compile_tests(Path, Config) ->
+ ToolModule = proplists:get_value(property_test_tool, Config),
MacroDefs = macro_def(ToolModule),
{ok,Cwd} = file:get_cwd(),
ok = file:set_cwd(Path),
--
2.16.4