Changeset 44


Ignore:
Timestamp:
10/11/08 13:42:55 (4 years ago)
Author:
charpi
Message:

#11 and #12

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shells.erl

    r41 r44  
     1%%% Copyright (c) 2008 Dominic Williams, Nicolas Charpentier 
     2%%% All rights reserved. 
     3%%% See file COPYING. 
    14-module (shells). 
    25-export ([install/1]). 
     
    4346    ok = tester_test: deletes_a_test_module (Test_node), 
    4447    ok = tester_test: notifies_a_message (Test_node), 
     48    ok = tester_test: runs_new_tests_failed_then_successful (Test_node), 
    4549    Caller ! {Caller, done}. 
    4650     
  • trunk/src/tester.erl

    r40 r44  
    2121        {delete, Modules} -> 
    2222            loop (test (unload (Modules, State))); 
     23        {runner_end, New_state} -> 
     24            loop (New_state); 
    2325        Modules -> 
    2426            loop (test (load (Modules, State))) 
     
    3335    Load_args = [Module, File_name, Binary], 
    3436    {module, Module} = rpc: call (Node, code, load_binary, Load_args), 
    35     New_tests = dict: store (Module, Tests, dict: fetch (tests, State)), 
     37    Time_stamped_tests = [{Test, new} || Test <- Tests], 
     38    Test_dict = dict: fetch (tests, State), 
     39    New_tests = dict: store (Module, Time_stamped_tests, Test_dict), 
    3640    dict: store (tests, New_tests, State). 
    3741 
    3842test (State) -> 
    39     Test_dict = dict: fetch (tests, State), 
     43    State_without_pid = stop_running_session (State), 
     44    Test_dict = dict: fetch (tests, State_without_pid), 
    4045    {Total, Tests} = flatten (Test_dict), 
    41     Notify = dict: fetch (notify, State), 
     46    Notify = dict: fetch (notify, State_without_pid), 
    4247    Notify ({Total, 0, 0}), 
    43     lists: foldl (test_fun (State, Total), {0, 0}, Tests), 
    44     State. 
     48    Self = self(), 
     49    Test_session_fun = fun () ->  
     50                               launch_test (Self, Total, Tests, State_without_pid) 
     51                       end, 
     52    Test_session = spawn (Test_session_fun), 
     53    dict: store (test_session, Test_session, State_without_pid). 
     54 
     55stop_running_session (State) -> 
     56    case dict: find (test_session, State) of 
     57        {ok, Session} -> 
     58            exit(Session, kill), 
     59            dict: erase (test_session, State); 
     60        _ -> 
     61            State 
     62    end. 
     63 
     64launch_test (Parent, Total, Tests, State) -> 
     65    process_flag (trap_exit, true), 
     66    Run = lists: foldl (test_fun (State, Total), {State,{0, 0}}, Tests), 
     67    {New_state, _} = Run, 
     68    Parent ! {runner_end, New_state}. 
    4569 
    4670unload (Modules, State) -> 
     
    5882flatten (Tests) -> 
    5983    F = fun (Module, Ts, {Count, List}) -> 
    60                 {Count + length (Ts), [[{Module, T} || T <- Ts] | List]} 
     84                Tests_by_module = [{Module, T, Stamp} || {T, Stamp} <- Ts], 
     85                {Count + length (Ts), [ Tests_by_module | List]} 
    6186        end, 
    6287    {Total, All} = dict: fold (F, {0, []}, Tests), 
    63     {Total, lists: flatten (All)}. 
     88    Sorted_tests = lists: sort (fun new_tests_first/2, lists: flatten (All)), 
     89    {Total, Sorted_tests}. 
    6490 
     91new_tests_first ({_, _ ,new}, {_, _, failed})  -> 
     92    true; 
     93new_tests_first ({_, _ ,failed}, {_, _, new})  -> 
     94    false; 
     95new_tests_first ({_, _ ,new}, _)  -> 
     96    true; 
     97new_tests_first ({_, _, failed}, _) -> 
     98    true; 
     99new_tests_first ({_,_,_},{_,_,new}) -> 
     100    false; 
     101new_tests_first ({_,_,_},{_,_,failed}) -> 
     102    false; 
     103new_tests_first (A,B) -> 
     104    A<B. 
     105     
    65106test_fun (State, Total) -> 
    66107    Node = dict: fetch (node, State), 
    67108    Notify = dict: fetch (notify, State), 
    68     fun ({Module, Function}, {Run, Passed}) -> 
     109    fun (Test_definition, {Tester_state, {Run, Passed}}) -> 
     110            {Module, Function, Stamp} = Test_definition, 
    69111            Pid = spawn_link (Node, Module, Function, []), 
    70             New_passed = 
     112            {New_passed, New_stamp} = 
    71113                receive 
    72114                    {'EXIT', Pid, normal} -> 
    73                         Passed + 1; 
     115                        {Passed + 1, first_test_success (Stamp, now())}; 
    74116                    {'EXIT', Pid, Reason} -> 
    75117                        Notify (Reason), 
    76                         Passed 
     118                        {Passed, failed} 
    77119                end, 
    78120            New_run = Run + 1, 
    79121            Notify ({Total, New_run, New_passed}), 
    80             {New_run, New_passed} 
     122            New_state = update_state (Tester_state, Module, Function, New_stamp), 
     123            {New_state, {New_run, New_passed}} 
    81124    end. 
    82125 
     126first_test_success (Before, Now) when is_atom (Before) -> 
     127    Now; 
     128first_test_success (Stamp, _) -> 
     129    Stamp. 
     130 
     131update_state (State, Module, Function, Stamp) -> 
     132    Test_dict = dict: fetch (tests, State), 
     133    Module_tests = dict:fetch (Module, Test_dict), 
     134    Filtered_tests = proplists: delete (Function, Module_tests), 
     135    Updated_tests = [{Function, Stamp} | Filtered_tests], 
     136    New_tests = dict: store (Module, Updated_tests, Test_dict), 
     137    dict: store (tests, New_tests, State). 
  • trunk/src/tester_test.erl

    r40 r44  
    1010-export ([deletes_a_test_module /1]). 
    1111-export ([notifies_a_message /1]). 
     12-export ([runs_new_tests_failed_then_successful /1]). 
    1213 
    1314start_tester (Node) -> 
    1415    Self = self (), 
    1516    Notify = fun (Event) -> Self ! Event end, 
    16     spawn_link (tester, init, [Notify, Node]). 
     17    extremeforge: start_tester (Node, Notify). 
    1718 
    1819fixture_path (Module) -> 
     
    4546    Tester = start_tester (Node), 
    4647    [{2, 0, 0}, {2, 1, 1}, _, {2, 2, 1}] = send ([eg_test], Tester), 
    47     [{2, 0, 0}, {2, 1, 1}, _, {2, 2, 1}] = send ([eg_code], Tester), 
     48    [{2, 0, 0}, _, {2, 1, 0}, {2, 2, 1}] = send ([eg_code], Tester), 
    4849    Result = send ([eg_test_of_code], Tester), 
    4950    [{3, 0, 0}, {3, 1, 1}, _, {3, 2, 1}, {3, 3, 2}] = Result, 
     
    9495    ok. 
    9596 
     97runs_new_tests_failed_then_successful (Node) -> 
     98    Tester = start_tester (Node), 
     99    Modules = [eg_code, eg_test_of_code_failed], 
     100    Result = send (Modules, Tester), 
     101    [{1, 0, 0}, Error, {1, 1, 0}] = Result, 
     102    {{badmatch, bad_eg_code}, _} = Error, 
     103     
     104    Result_after_new_test = send ([eg_test_not_exports], Tester), 
     105    [{2, 0, 0}, {2, 1, 1}, Error, {2, 2, 1}] = Result_after_new_test, 
     106 
     107    New_run = send ([eg_test_of_code], Tester), 
     108    [{3, 0, 0}, {3, 1, 1}, Error, {3, 2, 1}, {3, 3, 2}] = New_run, 
     109    ok. 
     110 
    96111receive_something (Ms, Delay) -> 
    97112    receive 
Note: See TracChangeset for help on using the changeset viewer.