Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix eunit to print stacktrace correctly if test cases throw any excep…

…tion

R15 adds file and lineno in the result of erlang:get_stacktrace/0, so
eunit should be updated accordingly to accomodate the new stacktrace format.
Fix eunit_lib:print_exception when erlang:get_stacktrace returns {M,F,A,[]}
  • Loading branch information...
commit 73b94a990bb91fd263dace4ccbaef6ff727a9637 1 parent 9a6ad15
Wei Cao authored November 02, 2011 proxyles committed November 02, 2011
25  lib/eunit/src/eunit_lib.erl
@@ -86,9 +86,9 @@ analyze_exit_term(Term) ->
86 86
 
87 87
 is_stacktrace([]) ->
88 88
     true;
89  
-is_stacktrace([{M,F,A}|Fs]) when is_atom(M), is_atom(F), is_integer(A) ->
  89
+is_stacktrace([{M,F,A,Fl}|Fs]) when is_atom(M), is_atom(F), is_integer(A), is_list(Fl) ->
90 90
     is_stacktrace(Fs);
91  
-is_stacktrace([{M,F,As}|Fs]) when is_atom(M), is_atom(F), is_list(As) ->
  91
+is_stacktrace([{M,F,As,Fl}|Fs]) when is_atom(M), is_atom(F), is_list(As), is_list(Fl) ->
92 92
     is_stacktrace(Fs);
93 93
 is_stacktrace(_) ->
94 94
     false.
@@ -96,10 +96,16 @@ is_stacktrace(_) ->
96 96
 format_stacktrace(Trace) ->
97 97
     format_stacktrace(Trace, "in function", "in call from").
98 98
 
99  
-format_stacktrace([{M,F,A}|Fs], Pre, Pre1) when is_integer(A) ->
100  
-    [io_lib:fwrite("  ~s ~w:~w/~w\n", [Pre, M, F, A])
  99
+
  100
+format_stacktrace([{M,F,A,Fl}|Fs], Pre, Pre1) when is_integer(A) ->
  101
+    S = case Fl of
  102
+        [{file, File},{line, Line}]->
  103
+            io_lib:fwrite(" [~s:~w]", [File, Line]);
  104
+        _-> ""
  105
+        end,
  106
+    [io_lib:fwrite("  ~s ~w:~w/~w~s\n", [Pre, M, F, A, S])
101 107
      | format_stacktrace(Fs, Pre1, Pre1)];
102  
-format_stacktrace([{M,F,As}|Fs], Pre, Pre1) when is_list(As) ->
  108
+format_stacktrace([{M,F,As,Fl}|Fs], Pre, Pre1) when is_list(As) ->
103 109
     A = length(As),
104 110
     C = case is_op(M,F,A) of
105 111
 	    true when A =:= 1 ->
@@ -112,8 +118,13 @@ format_stacktrace([{M,F,As}|Fs], Pre, Pre1) when is_list(As) ->
112 118
 	    false ->
113 119
 		io_lib:fwrite("~w(~s)", [F,format_arglist(As)])
114 120
 	end,
115  
-    [io_lib:fwrite("  ~s ~w:~w/~w\n    called as ~s\n",
116  
-		   [Pre,M,F,A,C])
  121
+    S = case Fl of
  122
+        [{file, File},{line, Line}]->
  123
+            io_lib:fwrite(" [~s:~w]", [File, Line]);
  124
+        _-> ""
  125
+        end,
  126
+    [io_lib:fwrite("  ~s ~w:~w/~w~s\n    called as ~s\n",
  127
+		   [Pre,M,F,A,S,C])
117 128
      | format_stacktrace(Fs,Pre1,Pre1)];
118 129
 format_stacktrace([],_Pre,_Pre1) ->
119 130
     "".
4  lib/eunit/src/eunit_test.erl
@@ -41,9 +41,9 @@ get_stacktrace() ->
41 41
 get_stacktrace(Ts) ->
42 42
     eunit_lib:uniq(prune_trace(erlang:get_stacktrace(), Ts)).
43 43
 
44  
-prune_trace([{eunit_data, _, _} | Rest], Tail) ->
  44
+prune_trace([{eunit_data, _, _, _} | Rest], Tail) ->
45 45
     prune_trace(Rest, Tail);
46  
-prune_trace([{?MODULE, _, _} | _Rest], Tail) ->
  46
+prune_trace([{?MODULE, _, _, _} | _Rest], Tail) ->
47 47
     Tail;
48 48
 prune_trace([T | Ts], Tail) ->
49 49
     [T | prune_trace(Ts, Tail)];

0 notes on commit 73b94a9

Please sign in to comment.
Something went wrong with that request. Please try again.