File 3811-ssh-ssh_cth-test-running-aid-for-test-case-debugging.patch of Package erlang

From 3113cfda4e985b3f70ec57ca82ab9f6607a7ca41 Mon Sep 17 00:00:00 2001
From: Hans Nilsson <hans@erlang.org>
Date: Fri, 19 Feb 2021 14:47:30 +0100
Subject: [PATCH] ssh: ssh_cth test running aid for test case debugging when
 needed

---
 lib/ssh/test/Makefile    |  1 +
 lib/ssh/test/ssh_cth.erl | 64 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
 create mode 100644 lib/ssh/test/ssh_cth.erl

diff --git a/lib/ssh/test/Makefile b/lib/ssh/test/Makefile
index 04627052e5..a3db492f0f 100644
--- a/lib/ssh/test/Makefile
+++ b/lib/ssh/test/Makefile
@@ -26,6 +26,7 @@ include $(ERL_TOP)/make/$(TARGET)/otp.mk
 # ----------------------------------------------------
 
 MODULES= \
+	ssh_cth \
 	ssh_algorithms_SUITE \
 	ssh_options_SUITE \
 	ssh_basic_SUITE \
diff --git a/lib/ssh/test/ssh_cth.erl b/lib/ssh/test/ssh_cth.erl
new file mode 100644
index 0000000000..09d863cc51
--- /dev/null
+++ b/lib/ssh/test/ssh_cth.erl
@@ -0,0 +1,64 @@
+-module(ssh_cth).
+
+-export([id/1,
+         init/2,
+         pre_init_per_suite/3,
+         pre_end_per_suite/3,
+         pre_init_per_group/4,
+         pre_end_per_group/4,
+         post_end_per_group/5,
+         pre_init_per_testcase/3,
+         pre_end_per_testcase/4
+        ]).
+
+-record(c, {
+          suite, % suite name
+          groups = [], % Group path in reversed order
+          n % test case number
+         }).
+
+id(Opts) ->
+    proplists:get_value(filename, Opts, "/tmp/file.log").
+
+init(_Id, _Opts) ->
+    {ok, #c{n=1}}.
+
+pre_init_per_suite(Suite, Config, CTHState) ->
+    {Config, CTHState#c{suite=Suite}}.
+
+pre_end_per_suite(Suite, Config, State) ->
+    ct:pal("BEGIN ~p:end_per_suite(...)", [Suite]),
+     {Config, State}.
+
+
+pre_init_per_group(_Suite, Group, Config ,State) ->
+     {Config, State#c{groups = (State#c.groups ++ [Group])}}.
+
+pre_end_per_group(Suite, Group, Config, State) ->
+    ct:pal("BEGIN ~p:end_per_group(~p,...)", [Suite,Group]),
+    {Config, State}.
+
+post_end_per_group(_Suite, Group, _Config, Return, State) ->
+     {Return, State#c{groups = lists:reverse(lists:reverse(State#c.groups)--[Group])}}.
+
+
+pre_init_per_testcase(SuiteName, Config, CTHState) ->
+    ct:pal("########## ~p ~p ~s ~p~n", [CTHState#c.suite, CTHState#c.n, groups(Config), SuiteName]),
+    {Config, CTHState#c{n = CTHState#c.n + 1}}.
+
+pre_end_per_testcase(Suite,TC,Config,State) ->
+    ct:pal("BEGIN ~p:end_per_testcase(~p,...)", [Suite,TC]),
+    {Config, State}.
+
+
+groups(Config) ->
+    F = fun(X) -> io_lib:format("~w",[X]) end,
+    io_lib:format("~s", [lists:join("/", lists:map(F,get_groups(Config)))]).
+
+get_groups(Config) ->
+    P = proplists:get_value(tc_group_path, Config, []) ++
+        [proplists:get_value(tc_group_properties, Config, [])],
+    [Name || L <- P,
+             is_list(L),
+             {name,Name} <- L].
+    
-- 
2.26.2

openSUSE Build Service is sponsored by