From 9d95abb3597eb4e19df40704fe8533b5d384d3e9 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 31 May 2017 19:13:36 +0200 Subject: [ct] Print unicode atoms and strings correctly in common_test logs And use correct encoding when printing to files. --- lib/tools/src/cover.erl | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'lib/tools/src') diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index e2db4f0148..8b39b497ae 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -2414,8 +2414,8 @@ do_analyse_to_file1(Module, OutFile, ErlFile, HTML) -> {ok, InFd} -> case file:open(OutFile, [write,raw,delayed_write]) of {ok, OutFd} -> + Enc = encoding(ErlFile), if HTML -> - Encoding = encoding(ErlFile), Header = ["\n" @@ -2423,13 +2423,14 @@ do_analyse_to_file1(Module, OutFile, ErlFile, HTML) -> "\n" "\n" + html_encoding(Enc),"\"/>\n" "",OutFile,"\n" "" "\n" "
\n"],
-                           ok = file:write(OutFd,Header);
+                            H1Bin = unicode:characters_to_binary(Header,Enc,Enc),
+                            ok = file:write(OutFd,H1Bin);
 		       true -> ok
 		    end,
 		    
@@ -2443,12 +2444,15 @@ do_analyse_to_file1(Module, OutFile, ErlFile, HTML) ->
                                       string:right(integer_to_list(H),  2, $0),
                                       string:right(integer_to_list(Mi), 2, $0),
                                       string:right(integer_to_list(S),  2, $0)]),
-                    ok = file:write(OutFd,
-                               ["File generated from ",ErlFile," by COVER ",
+
+                    H2Bin = unicode:characters_to_binary(
+                              ["File generated from ",ErlFile," by COVER ",
                                 Timestamp,"\n\n"
                                 "**************************************"
                                 "**************************************"
-                                "\n\n"]),
+                                "\n\n"],
+                              Enc, Enc),
+                    ok = file:write(OutFd, H2Bin),
 
 		    Pattern = {#bump{module=Module,line='$1',_='_'},'$2'},
 		    MS = [{Pattern,[{is_integer,'$1'},{'>','$1',0}],[{{'$1','$2'}}]}],
@@ -2752,16 +2756,22 @@ pmap_collect(Mons,Acc) ->
     end.
 
 %%%-----------------------------------------------------------------
-%%% Read encoding from source file
+%%% Decide which encoding to use when analyzing to file.
+%%% The target file contains the file path, so if either the file name
+%%% encoding or the encoding of the source file is utf8, then we need
+%%% to use utf8.
 encoding(File) ->
-    Encoding =
-       case epp:read_encoding(File) of
-           none ->
-               epp:default_encoding();
-           E ->
-               E
-       end,
-    html_encoding(Encoding).
+    case file:native_name_encoding() of
+        latin1 ->
+            case epp:read_encoding(File) of
+                none ->
+                    epp:default_encoding();
+                E ->
+                    E
+            end;
+        utf8 ->
+            utf8
+    end.
 
 html_encoding(latin1) ->
     "iso-8859-1";
-- 
cgit v1.2.3