Changeset 92 for trunk


Ignore:
Timestamp:
01/28/10 16:21:51 (2 years ago)
Author:
dom
Message:

File and line is now provided for test failures

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/TODO

    r88 r92  
    77----------------------- 
    88 
     9- does a removed source file get removed from tester? 
     10 
    911Features? 
    1012--------- 
    1113 
    12 - add a "run once" mode for directory_tester 
    13 - print file(line) for test errors too 
    14 - remove or print to text =ERROR REPORT==== from tests which 
    15   voluntarily crash processes 
    1614- detect -include dependencies and recompile all when .hrl changes 
     15- allow giving additional include directories (for 3rd party libraries) 
    1716- run tests in parallel 
    1817- run a single (specific) test 
  • trunk/install

    r90 r92  
    66cd ebin 
    77erl -make 
    8 erl -sname extremeforge_install_tester -noinput & 
     8erl -sname extremeforge_install_tester@$hostname -noinput & 
    99erl -kernel error_logger "{file,\"../install_errors.log\"}" \ 
    10     -sname extremeforge_installer \ 
     10    -sname extremeforge_installer@$hostname \ 
    1111    -noinput \ 
    1212    -run directory_tester run_once ".." extremeforge_install_tester@$hostname \ 
  • trunk/src/modules.erl

    r68 r92  
    99-export ([compile/1]). 
    1010-export ([module_name/1]). 
     11-export ([locate/2]). 
    1112 
    1213to_binary (File_name) -> 
     
    2324 
    2425compile (Fun, Parameter) -> 
    25     Options = [binary, return, warn_unused_import], 
     26    Options = [binary, return, warn_unused_import, debug_info], 
    2627    Fun (Parameter, Options). 
    2728 
     
    3334    String = filename: rootname (filename: basename (Filename)), 
    3435    list_to_atom (String). 
     36 
     37locate ({M, F, A}, Binary) -> 
     38    {ok, {M, Chunks}} = beam_lib: chunks (Binary, [abstract_code, compile_info]), 
     39    [{abstract_code, Code}, {compile_info, Info}] = Chunks, 
     40    {value, {source, Filename}} = lists: keysearch (source, 1, Info), 
     41    {raw_abstract_v1, Forms} = Code, 
     42    Line = locate_line (F, A, Forms), 
     43    {Filename, Line}. 
     44 
     45locate_line (Function, Arity, [{function, Line, Function, Arity,  _} | _]) -> 
     46    Line; 
     47locate_line (Function, Arity, [_ | Forms]) -> 
     48    locate_line (Function, Arity, Forms); 
     49locate_line (_, _, []) -> 
     50    unknown. 
  • trunk/src/modules_test.erl

    r68 r92  
    66-test (exports). 
    77-export ([module_name/0]). 
     8-export ([locate/0]). 
    89 
    910module_name () -> 
     
    1112    hello = modules: module_name ("bla/hello.erl"). 
    1213     
     14locate () -> 
     15    ok = fixtures: use_tree (tree (), fun locate/2). 
     16 
     17tree () -> 
     18    [{file, "eg_code.erl", 
     19      ["-module (eg_code).", 
     20       "-export ([ok/0]).", 
     21       "ok () ->", 
     22       "    ok.", 
     23       "yo () ->", 
     24       "    yo."]}]. 
     25 
     26locate (Root, _) -> 
     27    File = filename: join (Root, "eg_code.erl"), 
     28    Binary = modules: to_binary (File), 
     29    {File, 3} = modules: locate ({eg_code, ok, 0}, Binary), 
     30    ok. 
  • trunk/src/tester.erl

    r90 r92  
    1010    With_notify = dict: store (notify, Notify, dict: new ()), 
    1111    With_tests = dict: store (tests, dict: new (), With_notify), 
    12     State = dict: store (node, Node, With_tests), 
     12    With_binaries = dict: store (binaries, dict: new (), With_tests), 
     13    State = dict: store (node, Node, With_binaries), 
    1314    loop (State). 
    1415 
     
    3435    Test_dict = dict: fetch (tests, State), 
    3536    New_tests = dict: store (Module, Time_stamped_tests, Test_dict), 
    36     dict: store (tests, New_tests, State). 
     37    Binaries_dict = dict: fetch (binaries, State), 
     38    New_binaries = dict: store (Module, Binary, Binaries_dict), 
     39    dict: store (binaries, New_binaries, dict: store (tests, New_tests, State)). 
    3740 
    3841test (State) -> 
     
    7578    Tests = dict: fetch (tests, State), 
    7679    New_tests = dict: erase (Module, Tests), 
    77     dict :store (tests, New_tests, State). 
     80    Binaries = dict: fetch (binaries, State), 
     81    New_binaries = dict: erase (Module, Binaries), 
     82    dict: store (binaries, New_binaries, dict :store (tests, New_tests, State)). 
    7883 
    7984flatten (Tests) -> 
     
    104109    Node = dict: fetch (node, State), 
    105110    Notify = dict: fetch (notify, State), 
     111    Binaries = dict: fetch (binaries, State), 
    106112    fun (Test_definition, {Tester_state, {Run, Passed}}) -> 
    107113            {Module, Function, Stamp} = Test_definition, 
     
    111117                    {'EXIT', Pid, normal} -> 
    112118                        {Passed + 1, first_test_success (Stamp, now())}; 
    113                     {'EXIT', Pid, Reason} -> 
     119                    {'EXIT', Pid, {Error, Stack_trace}} -> 
     120                        Binary = dict: fetch (Module, Binaries), 
     121                        MFA = {Module, Function, 0}, 
     122                        {File, Line} = modules: locate (MFA, Binary), 
     123                        Location = {Module, Function, 0, File, Line}, 
     124                        List = [{error, Error}, 
     125                                {stack_trace, Stack_trace}, 
     126                                {location, Location}], 
     127                        Reason = dict: from_list (List), 
    114128                        Notify (Reason), 
    115129                        {Passed, failed} 
  • trunk/src/tester_test.erl

    r91 r92  
    1717 
    1818run_all (Node) -> 
    19      
    2019    Fun = run_fun (Node), 
    2120    ok = fixtures: use_tree (tree (), Fun). 
     
    3130            deletes_a_test_module  (Node, Root), 
    3231            runs_new_tests_failed_then_successful  (Node, Root), 
     32            provides_failed_test_and_location (Node, Root), 
    3333            stops (Node, Root), 
    3434            ok 
     
    3838    Paths = [modules: to_file_name (M, Root) || M <- Modules], 
    3939    Binaries = [modules: to_binary (P) || P <- Paths], 
    40 %    false = lists: any (fun (M) -> code: is_loaded (M) end, Modules), 
     40    false = lists: any (fun (M) -> code: is_loaded (M) end, Modules), 
    4141    Tester ! {run, Binaries}, 
    4242    Results = receive_all ([]), 
    43 %    false = lists: any (fun (M) -> code: is_loaded (M) end, Modules), 
     43    false = lists: any (fun (M) -> code: is_loaded (M) end, Modules), 
    4444    Results. 
    4545 
     
    5151    Tester = spawn_link (tester, init, [notify_me (), Node]), 
    5252    [{2, 0, 0}, {2, 1, 1}, Error, {2, 2, 1}] = send (Root, [eg_test], Tester), 
    53     {{badmatch, nok}, [{eg_test, nok, 0} | _]} = Error,  
     53    {badmatch, nok} = dict: fetch (error, Error),  
     54    [{eg_test, nok, 0} | _] = dict: fetch (stack_trace, Error), 
    5455    ok. 
    5556 
     
    5758    Tester = spawn_link (tester, init, [notify_me (), Node]), 
    5859    [{1, 0, 0}, Error, {1, 1, 0}] = send (Root, [eg_test_of_code], Tester), 
    59     {undef, [{eg_code, ok, []}, {eg_test_of_code, ok, 0} | _]} = Error, 
     60    undef = dict: fetch (error, Error), 
     61    Stack_trace = dict: fetch (stack_trace, Error), 
     62    [{eg_code, ok, []}, {eg_test_of_code, ok, 0} | _] = Stack_trace, 
    6063    [{1, 0, 0}, {1, 1, 1}] = send (Root, [eg_code], Tester), 
    6164    ok. 
     
    8083    Binary = modules: forms_to_binary (eg_test_form ("nok")), 
    8184    Tester ! {run, [Binary]}, 
    82     Results = receive_all ([]), 
    83     [{1, 0, 0}, _Error, {1, 1, 0}] = Results, 
     85    [{1, 0, 0}, Error, {1, 1, 0}] = receive_all ([]), 
    8486    Correct_binary = modules: forms_to_binary (eg_test_form ("ok")), 
    8587    Tester ! {run, [Correct_binary]}, 
    8688    [{1, 0, 0}, {1, 1, 1}] = receive_all ([]), 
    8789    Tester ! {run, [Binary]}, 
    88     [{1, 0, 0}, _Error, {1, 1, 0}] = receive_all ([]), 
     90    [{1, 0, 0}, Error, {1, 1, 0}] = receive_all ([]), 
    8991    ok. 
    9092 
     
    9496    Tester ! {delete,[eg_code]}, 
    9597    [{1, 0, 0}, Error, {1, 1, 0}] = receive_all ([]), 
    96     {undef, [{eg_code, ok, []}, {eg_test_of_code, ok, 0} | _]} = Error, 
     98    undef = dict: fetch (error, Error), 
     99    [{eg_code, ok, []} | _] = dict: fetch (stack_trace, Error), 
    97100    [{1, 0, 0}, {1, 1, 1}] = send (Root, [eg_code], Tester), 
    98101    ok. 
     
    111114    Result = send (Root, Modules, Tester), 
    112115    [{1, 0, 0}, Error, {1, 1, 0}] = Result, 
    113     {{badmatch, bad_eg_code}, _} = Error, 
    114      
     116    {badmatch, bad_eg_code} = dict: fetch (error, Error), 
    115117    Result_after_new_test = send (Root, [eg_test_not_exports], Tester), 
    116118    [{2, 0, 0}, {2, 1, 1}, Error, {2, 2, 1}] = Result_after_new_test, 
    117  
    118119    New_run = send (Root, [eg_test_of_code], Tester), 
    119120    [{3, 0, 0}, {3, 1, 1}, Error, {3, 2, 1}, {3, 3, 2}] = New_run, 
     121    ok. 
     122 
     123provides_failed_test_and_location (Node, Root) -> 
     124    Tester = spawn_link (tester, init, [notify_me (), Node]), 
     125    [{2, 0, 0}, {2, 1, 1}, Error, {2, 2, 1}] = send (Root, [eg_test], Tester), 
     126    Filename = filename: join (Root, "eg_test.erl"), 
     127    {eg_test, nok, 0, Filename, 6} =  dict: fetch (location, Error), 
    120128    ok. 
    121129 
  • trunk/src/text_printer.erl

    r87 r92  
    4343            testing (Device); 
    4444        {_, tester, Other} -> 
    45             Line = io_lib: fwrite ("~nError: ~p.\n", [Other]), 
    46             io: put_chars (Device, Line), 
     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), 
    4753            testing (Device) 
    4854    end. 
  • trunk/src/text_printer_test.erl

    r87 r92  
    3939    P ! {self (), tester, {4, 2, 2}}, 
    4040    <<".">> = receive_io_request (P), 
    41     P ! {self (), tester, {undef, [{foo, bar, []}, {toto, titi, 0}]}}, 
    42     <<"\nError: {undef,[{foo,bar,[]},{toto,titi,0}]}.\n">> = 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), 
    4349    P ! {self (), tester, {4, 3, 2}}, 
    4450    <<".">> = receive_io_request (P), 
     
    6672    Self = self (), 
    6773    receive 
    68         {io_request, P, Self, {put_chars, Binary}} -> 
     74        {io_request, P, Self, {put_chars, unicode, Binary}} -> 
    6975            P ! {io_reply, Self, ok}, 
    7076            Binary; 
Note: See TracChangeset for help on using the changeset viewer.