| 1 | %%% Copyright (C) Dominic Williams |
|---|
| 2 | %%% All rights reserved. |
|---|
| 3 | %%% See file COPYING. |
|---|
| 4 | |
|---|
| 5 | -module(text_printer_test). |
|---|
| 6 | -test (exports). |
|---|
| 7 | -export ([compile_output/0]). |
|---|
| 8 | -export ([test_output/0]). |
|---|
| 9 | -export ([file_deletion/0]). |
|---|
| 10 | |
|---|
| 11 | compile_output () -> |
|---|
| 12 | P = spawn_link (text_printer, init, [self ()]), |
|---|
| 13 | P ! {self (), compiler, {4, 0, 0}}, |
|---|
| 14 | <<"Compiling 4: ">> = receive_io_request (P), |
|---|
| 15 | P ! {self (), compiler, {4, 1, 1}}, |
|---|
| 16 | <<".">> = receive_io_request (P), |
|---|
| 17 | P ! {self (), compiler, {4, 2, 2}}, |
|---|
| 18 | <<".">> = receive_io_request (P), |
|---|
| 19 | P ! {self (), compiler, {[], [warning ()]}}, |
|---|
| 20 | <<"\n/dir/file.erl(12): warning: function foo/1 is unused.\n">> = receive_io_request (P), |
|---|
| 21 | P ! {self (), compiler, {4, 3, 3}}, |
|---|
| 22 | <<".">> = receive_io_request (P), |
|---|
| 23 | P ! {self (), compiler, {[error ()], []}}, |
|---|
| 24 | <<"\n/dir/file2.erl(15): error: syntax error before: '->'.\n">> = receive_io_request (P), |
|---|
| 25 | P ! {self (), compiler, {4, 4, 3}}, |
|---|
| 26 | <<".\n3/4 successfully compiled.\nCannot run tests.\n">> = receive_io_request (P), |
|---|
| 27 | P ! {self (), compiler, {4, 3, 2}}, |
|---|
| 28 | <<"Compiling 1: ">> = receive_io_request (P), |
|---|
| 29 | P ! {self (), compiler, {4, 4, 4}}, |
|---|
| 30 | <<".\n4/4 successfully compiled.\n">> = receive_io_request (P), |
|---|
| 31 | ok. |
|---|
| 32 | |
|---|
| 33 | test_output () -> |
|---|
| 34 | P = spawn_link (text_printer, init, [self ()]), |
|---|
| 35 | P ! {self (), tester, {4, 0, 0}}, |
|---|
| 36 | <<"Testing 4: ">> = receive_io_request (P), |
|---|
| 37 | P ! {self (), tester, {4, 1, 1}}, |
|---|
| 38 | <<".">> = receive_io_request (P), |
|---|
| 39 | P ! {self (), tester, {4, 2, 2}}, |
|---|
| 40 | <<".">> = receive_io_request (P), |
|---|
| 41 | Error = {error, {undef, [{foo, bar, []}, {toto, titi, 0}]}}, |
|---|
| 42 | Stack = {stack_trace, [{eg_test, ok, 0}, {test_runner, run, 0}]}, |
|---|
| 43 | Locat = {location, {eg_test, ok, 0, "/dir/eg_test.erl", 12}}, |
|---|
| 44 | Dict = dict: from_list ([Error, Stack, Locat]), |
|---|
| 45 | P ! {self (), tester, Dict}, |
|---|
| 46 | <<"\n/dir/eg_test.erl(12): failure in {eg_test, ok, 0}" |
|---|
| 47 | "\n Error: {undef,[{foo,bar,[]},{toto,titi,0}]}" |
|---|
| 48 | "\n Stack: [{eg_test,ok,0},{test_runner,run,0}]\n">> = receive_io_request (P), |
|---|
| 49 | P ! {self (), tester, {4, 3, 2}}, |
|---|
| 50 | <<".">> = receive_io_request (P), |
|---|
| 51 | P ! {self (), tester, {4, 4, 3}}, |
|---|
| 52 | <<".\n3/4 successfully tested.\n">> = receive_io_request (P), |
|---|
| 53 | ok. |
|---|
| 54 | |
|---|
| 55 | file_deletion () -> |
|---|
| 56 | P = spawn_link (text_printer, init, [self ()]), |
|---|
| 57 | P ! {self (), compiler, {2, 2, 2}}, |
|---|
| 58 | timeout = receive_io_request (P), |
|---|
| 59 | P ! {self (), tester, {1, 0, 0}}, |
|---|
| 60 | <<"Testing 1: ">> = receive_io_request (P), |
|---|
| 61 | P ! {self (), tester, {1, 1, 1}}, |
|---|
| 62 | <<".\n1/1 successfully tested.\n">> = receive_io_request (P), |
|---|
| 63 | ok. |
|---|
| 64 | |
|---|
| 65 | warning () -> |
|---|
| 66 | {"/dir/file.erl", [{12, erl_lint, {unused_function,{foo,1}}}]}. |
|---|
| 67 | |
|---|
| 68 | error () -> |
|---|
| 69 | {"/dir/file2.erl", [{15, erl_parse, ["syntax error before: ",["'->'"]]}]}. |
|---|
| 70 | |
|---|
| 71 | receive_io_request (P) -> |
|---|
| 72 | Self = self (), |
|---|
| 73 | receive |
|---|
| 74 | {io_request, P, Self, {put_chars, unicode, Binary}} -> |
|---|
| 75 | P ! {io_reply, Self, ok}, |
|---|
| 76 | Binary; |
|---|
| 77 | {io_request, P, Self, {put_chars, Binary}} -> |
|---|
| 78 | P ! {io_reply, Self, ok}, |
|---|
| 79 | Binary; |
|---|
| 80 | M -> M |
|---|
| 81 | after 1000 -> timeout |
|---|
| 82 | end. |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|