File 6851-Update-script-to-take-update_tests-argument.patch of Package erlang

From b56ee2f1aec82193cc47e897ae650b014d2dabb7 Mon Sep 17 00:00:00 2001
From: Dan Gudmundsson <dgud@erlang.org>
Date: Thu, 2 Mar 2023 16:12:48 +0100
Subject: [PATCH 1/3] Update script to take 'update_tests' argument

Make it possible to update the binary testfile when updating version.
---
 lib/stdlib/uc_spec/README-UPDATE.txt       |  7 ++++-
 lib/stdlib/uc_spec/gen_unicode_mod.escript | 32 +++++++++++++++-------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/lib/stdlib/uc_spec/README-UPDATE.txt b/lib/stdlib/uc_spec/README-UPDATE.txt
index 8af7b54a07..42ca52b987 100644
--- a/lib/stdlib/uc_spec/README-UPDATE.txt
+++ b/lib/stdlib/uc_spec/README-UPDATE.txt
@@ -35,7 +35,12 @@ this very same file (lib/stdlib/uc_spec/README-UPDATE.txt).
 Remember to update these instructions if a new file is added or any other change
 is required for future version updates.
 
-6. Run the test for the Unicode suite from the OTP repository root dir.
+6. Check if the test file needs to be updated:
+   (cd $ERL_TOP/lib/stdlib/uc_spec; escript gen_unicode_mod.escript update_tests)
+   If ../test/unicode_util_SUITE_data/unicode_table.bin is updated include it in
+   the commit.
+
+7. Run the test for the Unicode suite from the OTP repository root dir.
    $ export ERL_TOP=$PWD
    $ export PATH=$ERL_TOP/bin:$PATH
    $ ./otp_build all -a && ./otp_build tests
diff --git a/lib/stdlib/uc_spec/gen_unicode_mod.escript b/lib/stdlib/uc_spec/gen_unicode_mod.escript
index 6f55f6da45..d0a2974601 100644
--- a/lib/stdlib/uc_spec/gen_unicode_mod.escript
+++ b/lib/stdlib/uc_spec/gen_unicode_mod.escript
@@ -26,7 +26,7 @@
 -record(cp, {name, class, dec, comp, cs, cat}).
 -define(MOD, "unicode_util").
 
-main(_) ->
+main(Args) ->
     %%  Parse main table
     UD = file_open("../uc_spec/UnicodeData.txt"),
     Data0 = foldl(fun parse_unicode_data/2, [], UD),
@@ -66,8 +66,13 @@ main(_) ->
     ok = file:close(WidthF),
 
     %% Make module
+    UpdateTests = case Args of
+                      ["update_tests"] -> true;
+                      _ -> false
+                  end,
+
     {ok, Out} = file:open(?MOD++".erl", [write]),
-    gen_file(Out, Data, ExclData, maps:from_list(Props), WideCs),
+    gen_file(Out, Data, ExclData, maps:from_list(Props), WideCs, UpdateTests),
     ok = file:close(Out),
     ok.
 
@@ -216,7 +221,7 @@ is_default_width(Index, WD) ->
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-gen_file(Fd, Data, ExclData, Props, WideCs) ->
+gen_file(Fd, Data, ExclData, Props, WideCs, UpdateTests) ->
     gen_header(Fd),
     gen_static(Fd),
     gen_norm(Fd),
@@ -225,7 +230,7 @@ gen_file(Fd, Data, ExclData, Props, WideCs) ->
     gen_gc(Fd, Props),
     gen_compose_pairs(Fd, ExclData, Data),
     gen_case_table(Fd, Data),
-    gen_unicode_table(Fd, Data),
+    gen_unicode_table(Fd, Data, UpdateTests),
     gen_width_table(Fd, WideCs),
     ok.
 
@@ -929,7 +934,7 @@ case_data(_, _) ->
 def_cp([], CP) -> CP;
 def_cp(CP, _) -> CP.
 
-gen_unicode_table(Fd, Data) ->
+gen_unicode_table(Fd, Data, UpdateTests) ->
     FixCanon = fun(_, #cp{class=CCC, dec=Dec, comp=Comp, cat=Cat}) ->
                        Canon  = decompose(Dec,Data),
                        #{ccc=>CCC, canonical=>Canon, compat=>Comp, cat=>Cat}
@@ -948,11 +953,18 @@ gen_unicode_table(Fd, Data) ->
                                          end, Dict0),
 
     %% Export testfile
-    %% Dict1 = lists:map(fun({Id,{CCC, Canon, Compat, Cat}}) ->
-    %%                           {_, ECat} = lists:keyfind(Cat, 1, category_translate()),
-    %%                           {Id, {CCC, Canon, Compat, ECat}}
-    %%                   end, Dict0),
-    %% file:write_file("../test/unicode_util_SUITE_data/unicode_table.bin", term_to_binary(Dict1, [compressed])),
+    case UpdateTests of
+        true ->
+            Dict1 = lists:map(fun({Id,{CCC, Canon, Compat, Cat}}) ->
+                                      {_, ECat} = lists:keyfind(Cat, 1, category_translate()),
+                                      {Id, {CCC, Canon, Compat, ECat}}
+                              end, Dict0),
+            TestFile = "../test/unicode_util_SUITE_data/unicode_table.bin",
+            io:format("Updating: ~s~n", [TestFile]),
+            file:write_file(TestFile, term_to_binary(Dict1, [compressed]));
+        false ->
+            ignore
+    end,
 
     [io:format(Fd, "unicode_table(~w) -> ~w;~n", [CP, Map]) || {CP,Map} <- NonDef],
     io:format(Fd, "unicode_table(_) -> ~w.~n~n",[Def]),
-- 
2.35.3

openSUSE Build Service is sponsored by