File 1571-Add-documentation-and-test-for-shell_docs_ansi-param.patch of Package erlang

From d548400e846ab7ec0bed1d1ee53ef761a631c670 Mon Sep 17 00:00:00 2001
From: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com>
Date: Mon, 26 Aug 2024 12:33:09 +0300
Subject: [PATCH 1/2] Add documentation and test for shell_docs_ansi parameter

---
 lib/kernel/doc/kernel_app.md         |  5 +++
 lib/stdlib/test/shell_docs_SUITE.erl | 46 +++++++++++++++++++++++++---
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/lib/kernel/doc/kernel_app.md b/lib/kernel/doc/kernel_app.md
index 432d678823..d94146f5da 100644
--- a/lib/kernel/doc/kernel_app.md
+++ b/lib/kernel/doc/kernel_app.md
@@ -417,6 +417,11 @@ For more information about configuration parameters, see file
 
   Defaults to `false`.
 
+- **`shell_docs_ansi = boolean()`{: #shell_docs_ansi }** - Specifies whether
+  the documentation rendered in the shell should use ANSI escape codes.
+
+  See also `t:shell_docs:config/0`.
+
 - **`shell_history = enabled | disabled | module()`{: #shell_history }** -
   Specifies whether shell history should be logged to disk between usages of
   `erl` (`enabled`), not logged at all (`disabled`), or a user-specified module
diff --git a/lib/stdlib/test/shell_docs_SUITE.erl b/lib/stdlib/test/shell_docs_SUITE.erl
index dd613d15eb..5fab9753b5 100644
--- a/lib/stdlib/test/shell_docs_SUITE.erl
+++ b/lib/stdlib/test/shell_docs_SUITE.erl
@@ -22,9 +22,9 @@
 -moduledoc false.
 
 -export([all/0, suite/0, groups/0, init_per_suite/1, end_per_suite/1,
-   init_per_group/2, end_per_group/2]).
+   init_per_group/2, end_per_group/2, init_per_testcase/2, end_per_testcase/2]).
 
--export([render/1, links/1, normalize/1, render_prop/1,render_non_native/1]).
+-export([render/1, links/1, normalize/1, render_prop/1, render_non_native/1, ansi/1]).
 -export([render_function/1, render_type/1, render_callback/1]).
 
 -export([render_all/1, update_render/0, update_render/1]).
@@ -40,7 +40,8 @@ suite() ->
 all() ->
     [ {group, render},
       {group, prop},
-      {group, render_smoke}
+      {group, render_smoke},
+      ansi
     ].
 
 groups() ->
@@ -66,8 +67,22 @@ init_per_group(prop, Config) ->
 init_per_group(_GroupName, Config) ->
     Config.
 
-end_per_group(_GroupName, Config) ->
-    Config.
+end_per_group(_GroupName, _Config) ->
+    ok.
+
+init_per_testcase(_TestCase, Config) ->
+    Env = [{App, Key, application:get_env(App, Key)}
+           || {App, Key} <- [{kernel, shell_docs_ansi}]],
+    [{env, Env} | Config].
+
+end_per_testcase(_TestCase, Config) ->
+    lists:foreach(
+      fun({App, Key, undefined}) ->
+              application:unset_env(App, Key);
+         ({App, Key, {ok, Val}}) ->
+              application:set_env(App, Key, Val)
+      end,
+      proplists:get_value(env, Config)).
 
 %% We keep the docs of a couple of complex modules
 %% in the data_dir in order to compare then with the original
@@ -537,3 +552,24 @@ sync(N) ->
     ok ->
       sync(N-1)
   end.
+
+ansi(_Config) ->
+    {ok, Docs} = code:get_doc(?MODULE),
+
+    HasESC =
+        fun(Config) ->
+                Doc = shell_docs:render(?MODULE, Docs, Config),
+                string:find(Doc, "\e") =/= nomatch
+        end,
+
+    application:set_env(kernel, shell_docs_ansi, true),
+    ?assert(HasESC(#{})),
+    ?assertNot(HasESC(#{ansi => false})),
+    ?assert(HasESC(#{ansi => true})),
+
+    application:set_env(kernel, shell_docs_ansi, false),
+    ?assertNot(HasESC(#{})),
+    ?assertNot(HasESC(#{ansi => false})),
+    ?assert(HasESC(#{ansi => true})),
+
+    ok.
-- 
2.43.0

openSUSE Build Service is sponsored by