- Timestamp:
- 06/17/08 13:58:49 (4 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
-
shells.erl (modified) (2 diffs)
-
tester.erl (modified) (1 diff)
-
tester_test.erl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shells.erl
r28 r30 3 3 4 4 install ([Test_node]) -> 5 process_flag(trap_exit, false),% called with erl -s shells install5 %xs process_flag(trap_exit, false), % called with erl -s shells install 6 6 try 7 tests (Test_node) 7 Self = self (), 8 spawn_link (fun () -> tests (Test_node, Self) end), 9 receive {Self, done} -> ok; 10 M -> io:fwrite ("tests_crash: ~p~n", [M]) 11 end 8 12 9 13 catch C:E-> … … 14 18 rpc: call (Test_node, init, stop, []) 15 19 end, 16 receive_all (),20 receive_all (), 17 21 io: fwrite ("done~n", []). 18 22 19 tests (Test_node ) ->23 tests (Test_node, Caller) -> 20 24 io: fwrite ("Running local developer tests~n", []), 21 25 ok = tests_test: filter_by_attribute (), 22 26 io: fwrite ("Running developer tests on test node: ~p~n", [Test_node]), 23 ok = tester_test: runs_given_tests (Test_node). 27 ok = tester_test: runs_a_test (Test_node), 28 ok = tester_test: runs_given_tests (Test_node), 29 Caller ! {Caller, done}. 24 30 25 receive_all() -> 26 receive M -> 31 receive_all () -> 32 receive 33 {'EXIT', _, normal} -> 34 receive_all (); 35 M -> 27 36 io:fwrite("Received ~p~n", [M]), 28 receive_all ()37 receive_all () 29 38 after 500 -> 30 39 done -
trunk/src/tester.erl
r28 r30 8 8 init (Notify, Node) -> 9 9 process_flag (trap_exit, true), 10 loop (Notify, Node). 10 With_notify = dict: store (notify, Notify, dict: new ()), 11 With_tests = dict: store (tests, dict: new (), With_notify), 12 State = dict: store (node, Node, With_tests), 13 loop (State). 11 14 12 loop ( Notify, Node) ->15 loop (State) -> 13 16 receive 14 { File_name, Binary}->15 test (File_name, Binary, Notify, Node);17 {_, _} = Module -> 18 loop (test (load (Module, State))); 16 19 _ -> 17 loop ( Notify, Node)20 loop (State) 18 21 end. 19 22 20 test (File_name, Binary, Notify, Node) -> 21 {Module, Tests} = tests: filter_by_attribute (Binary), 22 {module, Module} = rpc: call (Node, code, load_binary, [Module, File_name, Binary]), 23 Total = length (Tests), 23 load ({File_name, Binary}, State) -> 24 {Module, Functions} = tests: filter_by_attribute (Binary), 25 Node = dict: fetch (node, State), 26 Load_args = [Module, File_name, Binary], 27 {module, Module} = rpc: call (Node, code, load_binary, Load_args), 28 New_tests = dict: store (Module, Functions, dict: fetch (tests, State)), 29 dict: store (tests, New_tests, State). 30 31 test (State) -> 32 {Total, Tests} = flatten (dict: fetch (tests, State)), 33 Notify = dict: fetch (notify, State), 24 34 Notify ({Total, 0, 0}), 25 test (Total, 0, 0, Tests, Notify, Node). 35 lists: foldl (test_fun (State, Total), {0, 0}, Tests), 36 State. 26 37 27 test (Total, Run, Passed, [{M, F, A} | Tests], Notify, Node) -> 28 Pid = spawn_link (Node, M, F, A), 29 New_passed = 30 receive 31 {'EXIT', Pid, normal} -> 32 Passed + 1; 33 {'EXIT', Pid, Reason} -> 34 Notify (Reason), 35 Passed 38 flatten (Tests) -> 39 F = fun (_, Ts, {Count, List}) -> 40 {Count + length (Ts), [Ts | List]} 36 41 end, 37 New_run = Run + 1, 38 Notify ({Total, New_run, New_passed}), 39 test (Total, New_run, New_passed, Tests, Notify, Node); 40 test (_, _, _, [], _, _) -> 41 bye. 42 {Total, All} = dict: fold (F, {0, []}, Tests), 43 {Total, lists: flatten (All)}. 44 45 test_fun (State, Total) -> 46 Node = dict: fetch (node, State), 47 Notify = dict: fetch (notify, State), 48 fun ({M, F, A}, {Run, Passed}) -> 49 Pid = spawn_link (Node, M, F, A), 50 New_passed = 51 receive 52 {'EXIT', Pid, normal} -> 53 Passed + 1; 54 {'EXIT', Pid, Reason} -> 55 Notify (Reason), 56 Passed 57 end, 58 New_run = Run + 1, 59 Notify ({Total, New_run, New_passed}), 60 {New_run, New_passed} 61 end. 62 -
trunk/src/tester_test.erl
r28 r30 4 4 5 5 -module (tester_test). 6 -export ([runs_ given_tests/1]).7 -test ([{nodes_fix, test_node, [runs_ given_tests]}]).6 -export ([runs_a_test/1, runs_given_tests/1]). 7 -test ([{nodes_fix, test_node, [runs_a_test, runs_given_tests]}]). 8 8 9 runs_ given_tests(Node) ->9 runs_a_test (Node) -> 10 10 Self = self (), 11 11 Notify = fun (Event) -> Self ! Event end, … … 14 14 false = code: is_loaded (eg_test), 15 15 Tester ! {"../fix/eg_test.erl", Binary}, 16 [{2, 0, 0}, {2, 1, 1}, Error, {2, 2, 1}] = tests: receive_all (),16 [{2, 0, 0}, {2, 1, 1}, Error, {2, 2, 1}] = receive_all ([]), 17 17 {{badmatch, nok}, [{eg_test, nok, 0} | _]} = Error, 18 18 false = code: is_loaded (eg_test), 19 19 ok. 20 21 runs_given_tests (Node) -> 22 Self = self (), 23 Notify = fun (Event) -> Self ! Event end, 24 Tester = spawn_link (tester, init, [Notify, Node]), 25 Test_binary = modules: to_binary ("../fix/eg_test_of_code.erl"), 26 Code_binary = modules: to_binary ("../fix/eg_code.erl"), 27 false = code: is_loaded (eg_test_of_code), 28 false = code: is_loaded (eg_code), 29 Tester ! {"../fix/eg_test_of_code.erl", Test_binary}, 30 [{1, 0, 0}, Error, {1, 1, 0}] = receive_all ([]), 31 {undef, [{eg_code, ok, []}, {eg_test_of_code, ok, 0} | _]} = Error, 32 false = code: is_loaded (eg_test), 33 Tester ! {"../fix/eg_code.erl", Code_binary}, 34 [{1, 0, 0}, {1, 1, 1}] = receive_all ([]), 35 ok. 20 36 21 37 receive_all (Ms) -> 38 receive 39 {Run, Run, Passed} -> 40 lists: reverse ([{Run, Run, Passed} | Ms]); 41 M -> 42 receive_all ([M | Ms]) 43 end. 44 22 45 %%% Test to be added: 23 46 %%% with several modules, including non-test ones
Note: See TracChangeset
for help on using the changeset viewer.
