source: trunk/src/text_printer.erl @ 92

Revision 92, 2.3 KB checked in by dom, 2 years ago (diff)

File and line is now provided for test failures

Line 
1%%% Copyright (C) Dominic Williams
2%%% All rights reserved.
3%%% See file COPYING.
4
5-module (text_printer).
6-export ([init/1]).
7
8init (Device) ->
9    wait (Device).
10
11wait (Device) ->
12    receive
13        {_, compiler, {Total, Done, _}} when Total > Done ->
14            io: put_chars (Device, io_lib: fwrite ("Compiling ~p: ", [Total - Done])),
15            compiling (Device);
16        {_, tester, {Total, Done, _}} when Total > Done ->
17            io: put_chars (Device, io_lib: fwrite ("Testing ~p: ", [Total - Done])),
18            testing (Device);
19        _ ->
20            wait (Device)
21    end.
22
23compiling (Device) ->
24    receive
25        {_, compiler, {Total, Total, Successful}} ->
26            io: put_chars (Device, [".\n" | end_compile (Successful, Total)]),
27            wait (Device);
28        {_, compiler, {_, _, _}} ->
29            io: put_chars (Device, "."),
30            compiling (Device);
31        {_, compiler, {Errors, Warnings}} ->
32            io: put_chars (Device, [$\n | [errors (Errors), warnings (Warnings)]]),
33            compiling (Device)
34    end.
35
36testing (Device) ->
37    receive
38        {_, tester, {Total, Total, Successful}} ->
39            io: put_chars (Device, [".\n" | end_tests (Successful, Total)]),
40            wait (Device);
41        {_, tester, {_, _, _}} ->
42            io: put_chars (Device, "."),
43            testing (Device);
44        {_, tester, Other} ->
45            Error = dict: fetch (error, Other),
46            Stack = dict: fetch (stack_trace, Other),
47            {M, F, A, File, Line} = dict: fetch (location, Other),
48            Output = io_lib: fwrite (
49                     "~n~s(~p): failure in {~p, ~p, ~p}~n"
50                     "   Error: ~p~n"
51                     "   Stack: ~p~n", [File, Line, M, F, A, Error, Stack]),
52            io: put_chars (Device, Output),
53            testing (Device)
54    end.
55
56warnings (Ws) -> items (warning, Ws).
57errors (Es) -> items (error, Es).
58
59items (Label, [{File, Xs} | Tail]) ->
60    Item = [[File, item (Label, X), $\n] || X <- Xs],
61    [Item | items (Label, Tail)];
62items (_, []) ->
63    [].
64
65item (Label, {Line, Stage, Message}) ->
66    io_lib: fwrite ("(~p): ~s: ~s.", [Line, Label, Stage: format_error (Message)]).
67
68end_compile (Successful, Total) ->
69    Compiled = io_lib: fwrite ("~p/~p successfully compiled.~n", [Successful, Total]),
70    [Compiled, cannot_test (Successful, Total)].
71
72cannot_test (Total, Total) ->
73    [];
74cannot_test (_, _) ->
75    "Cannot run tests.\n".
76
77end_tests (Successful, Total) ->
78    io_lib: fwrite ("~p/~p successfully tested.~n", [Successful, Total]).
Note: See TracBrowser for help on using the repository browser.