From d7391d973f453de4749857291680380b60330bc7 Mon Sep 17 00:00:00 2001
From: Peter Andersson <peppe@erlang.org>
Date: Wed, 21 Sep 2011 23:14:34 +0200
Subject: Fix problem with error message not being printed correctly

---
 lib/test_server/src/test_server.erl | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/lib/test_server/src/test_server.erl b/lib/test_server/src/test_server.erl
index ea55b22603..ae54925c2e 100644
--- a/lib/test_server/src/test_server.erl
+++ b/lib/test_server/src/test_server.erl
@@ -746,6 +746,9 @@ run_test_case_msgloop(Ref, Pid, CaptureStdout, Terminate, Comment, CurrConf) ->
 			Other
 		end,
 	    run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate1,NewComment2,CurrConf);
+	{read_comment,From} ->
+	    From ! {self(),read_comment,Comment},
+	    run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
 	{set_curr_conf,NewCurrConf} ->
 	    run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,NewCurrConf);
 	{'EXIT',Pid,{Ref,Time,Value,Loc,Opts}} ->
@@ -1443,9 +1446,13 @@ do_end_per_testcase(Mod,EndFunc,Func,Conf) ->
 	{'$test_server_ok',_} ->
 	    ok;
 	{'EXIT',Reason} = Why ->
-	    comment(io_lib:format("<font color=\"red\">"
+	    Comment0 = case read_comment() of
+			   ""  -> "";
+			   Cmt -> Cmt ++ "<br>"
+		       end,
+	    comment(io_lib:format("~s<font color=\"red\">"
 				  "WARNING: ~w crashed!"
-				  "</font>\n",[EndFunc])),
+				  "</font>\n",[Comment0,EndFunc])),
 	    group_leader() ! {printout,12,
 			      "WARNING: ~w crashed!\n"
 			      "Reason: ~p\n"
@@ -1455,9 +1462,13 @@ do_end_per_testcase(Mod,EndFunc,Func,Conf) ->
 				 mod_loc(get_loc()))]},
 	    {failed,{Mod,end_per_testcase,Why}};
 	Other ->
-	    comment(io_lib:format("<font color=\"red\">"
+	    Comment0 = case read_comment() of
+			   ""  -> "";
+			   Cmt -> Cmt ++ "<br>"
+		       end,
+	    comment(io_lib:format("~s<font color=\"red\">"
 				  "WARNING: ~w thrown!"
-				  "</font>\n",[EndFunc])),
+				  "</font>\n",[Comment0,EndFunc])),
 	    group_leader() ! {printout,12,
 			      "WARNING: ~w thrown!\n"
 			      "Reason: ~p\n"
@@ -2363,6 +2374,22 @@ comment(String) ->
     group_leader() ! {comment,String},
     ok.
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% read_comment() -> string()
+%%
+%% Read the current comment string stored in
+%% state during test case execution.
+read_comment() ->
+    MsgLooper = group_leader(),
+    MsgLooper ! {read_comment,self()},
+    receive
+	{MsgLooper,read_comment,Comment} ->
+	    Comment
+    after
+	5000 ->
+	    ""
+    end.
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %% os_type() -> OsType
 %%
-- 
cgit v1.2.3