| 1 | %%% Copyright (C) Dominic Williams |
|---|
| 2 | %%% All rights reserved. |
|---|
| 3 | %%% See file COPYING. |
|---|
| 4 | |
|---|
| 5 | -module (text_printer). |
|---|
| 6 | -export ([init/1]). |
|---|
| 7 | |
|---|
| 8 | init (Device) -> |
|---|
| 9 | wait (Device). |
|---|
| 10 | |
|---|
| 11 | wait (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 | |
|---|
| 23 | compiling (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 | |
|---|
| 36 | testing (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 | |
|---|
| 56 | warnings (Ws) -> items (warning, Ws). |
|---|
| 57 | errors (Es) -> items (error, Es). |
|---|
| 58 | |
|---|
| 59 | items (Label, [{File, Xs} | Tail]) -> |
|---|
| 60 | Item = [[File, item (Label, X), $\n] || X <- Xs], |
|---|
| 61 | [Item | items (Label, Tail)]; |
|---|
| 62 | items (_, []) -> |
|---|
| 63 | []. |
|---|
| 64 | |
|---|
| 65 | item (Label, {Line, Stage, Message}) -> |
|---|
| 66 | io_lib: fwrite ("(~p): ~s: ~s.", [Line, Label, Stage: format_error (Message)]). |
|---|
| 67 | |
|---|
| 68 | end_compile (Successful, Total) -> |
|---|
| 69 | Compiled = io_lib: fwrite ("~p/~p successfully compiled.~n", [Successful, Total]), |
|---|
| 70 | [Compiled, cannot_test (Successful, Total)]. |
|---|
| 71 | |
|---|
| 72 | cannot_test (Total, Total) -> |
|---|
| 73 | []; |
|---|
| 74 | cannot_test (_, _) -> |
|---|
| 75 | "Cannot run tests.\n". |
|---|
| 76 | |
|---|
| 77 | end_tests (Successful, Total) -> |
|---|
| 78 | io_lib: fwrite ("~p/~p successfully tested.~n", [Successful, Total]). |
|---|