- Timestamp:
- 10/11/08 13:42:55 (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
-
fix/eg_test_of_code_failed.erl (added)
-
src/shells.erl (modified) (2 diffs)
-
src/tester.erl (modified) (3 diffs)
-
src/tester_test.erl (modified) (3 diffs)
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. 1 4 -module (shells). 2 5 -export ([install/1]). … … 43 46 ok = tester_test: deletes_a_test_module (Test_node), 44 47 ok = tester_test: notifies_a_message (Test_node), 48 ok = tester_test: runs_new_tests_failed_then_successful (Test_node), 45 49 Caller ! {Caller, done}. 46 50 -
trunk/src/tester.erl
r40 r44 21 21 {delete, Modules} -> 22 22 loop (test (unload (Modules, State))); 23 {runner_end, New_state} -> 24 loop (New_state); 23 25 Modules -> 24 26 loop (test (load (Modules, State))) … … 33 35 Load_args = [Module, File_name, Binary], 34 36 {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), 36 40 dict: store (tests, New_tests, State). 37 41 38 42 test (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), 40 45 {Total, Tests} = flatten (Test_dict), 41 Notify = dict: fetch (notify, State ),46 Notify = dict: fetch (notify, State_without_pid), 42 47 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 55 stop_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 64 launch_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}. 45 69 46 70 unload (Modules, State) -> … … 58 82 flatten (Tests) -> 59 83 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]} 61 86 end, 62 87 {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}. 64 90 91 new_tests_first ({_, _ ,new}, {_, _, failed}) -> 92 true; 93 new_tests_first ({_, _ ,failed}, {_, _, new}) -> 94 false; 95 new_tests_first ({_, _ ,new}, _) -> 96 true; 97 new_tests_first ({_, _, failed}, _) -> 98 true; 99 new_tests_first ({_,_,_},{_,_,new}) -> 100 false; 101 new_tests_first ({_,_,_},{_,_,failed}) -> 102 false; 103 new_tests_first (A,B) -> 104 A<B. 105 65 106 test_fun (State, Total) -> 66 107 Node = dict: fetch (node, State), 67 108 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, 69 111 Pid = spawn_link (Node, Module, Function, []), 70 New_passed=112 {New_passed, New_stamp} = 71 113 receive 72 114 {'EXIT', Pid, normal} -> 73 Passed + 1;115 {Passed + 1, first_test_success (Stamp, now())}; 74 116 {'EXIT', Pid, Reason} -> 75 117 Notify (Reason), 76 Passed118 {Passed, failed} 77 119 end, 78 120 New_run = Run + 1, 79 121 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}} 81 124 end. 82 125 126 first_test_success (Before, Now) when is_atom (Before) -> 127 Now; 128 first_test_success (Stamp, _) -> 129 Stamp. 130 131 update_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 10 10 -export ([deletes_a_test_module /1]). 11 11 -export ([notifies_a_message /1]). 12 -export ([runs_new_tests_failed_then_successful /1]). 12 13 13 14 start_tester (Node) -> 14 15 Self = self (), 15 16 Notify = fun (Event) -> Self ! Event end, 16 spawn_link (tester, init, [Notify, Node]).17 extremeforge: start_tester (Node, Notify). 17 18 18 19 fixture_path (Module) -> … … 45 46 Tester = start_tester (Node), 46 47 [{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), 48 49 Result = send ([eg_test_of_code], Tester), 49 50 [{3, 0, 0}, {3, 1, 1}, _, {3, 2, 1}, {3, 3, 2}] = Result, … … 94 95 ok. 95 96 97 runs_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 96 111 receive_something (Ms, Delay) -> 97 112 receive
Note: See TracChangeset
for help on using the changeset viewer.
