- Timestamp:
- 08/22/08 18:46:07 (4 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 5 edited
-
fix/eg_test_fix.erl (deleted)
-
fix/eg_test_fix_nofix.erl (deleted)
-
src/shells.erl (modified) (1 diff)
-
src/tester.erl (modified) (3 diffs)
-
src/tester_test.erl (modified) (2 diffs)
-
src/tests.erl (modified) (1 diff)
-
src/tests_test.erl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shells.erl
r33 r34 28 28 ok = tester_test: reruns_a_test_when_given_module (Test_node), 29 29 ok = tester_test: runs_given_tests (Test_node), 30 ok = tester_test: runs_a_fixtured_test (Test_node),31 30 Caller ! {Caller, done}. 32 31 -
trunk/src/tester.erl
r30 r34 22 22 23 23 load ({File_name, Binary}, State) -> 24 {Module, Functions} = tests: filter_by_attribute (Binary),24 {Module, Tests} = tests: filter_by_attribute (Binary), 25 25 Node = dict: fetch (node, State), 26 26 Load_args = [Module, File_name, Binary], 27 27 {module, Module} = rpc: call (Node, code, load_binary, Load_args), 28 New_tests = dict: store (Module, Functions, dict: fetch (tests, State)),28 New_tests = dict: store (Module, Tests, dict: fetch (tests, State)), 29 29 dict: store (tests, New_tests, State). 30 30 31 31 test (State) -> 32 {Total, Tests} = flatten (dict: fetch (tests, State)), 32 Test_dict = dict: fetch (tests, State), 33 {Total, Tests} = flatten (Test_dict), 33 34 Notify = dict: fetch (notify, State), 34 35 Notify ({Total, 0, 0}), … … 37 38 38 39 flatten (Tests) -> 39 F = fun ( _, Ts, {Count, List}) ->40 {Count + length (Ts), [ Ts| List]}40 F = fun (Module, Ts, {Count, List}) -> 41 {Count + length (Ts), [[{Module, T} || T <- Ts] | List]} 41 42 end, 42 43 {Total, All} = dict: fold (F, {0, []}, Tests), … … 46 47 Node = dict: fetch (node, State), 47 48 Notify = dict: fetch (notify, State), 48 fun ({M , F, A}, {Run, Passed}) ->49 Pid = spawn_link (Node, M , F, A),49 fun ({Module, Function}, {Run, Passed}) -> 50 Pid = spawn_link (Node, Module, Function, []), 50 51 New_passed = 51 52 receive -
trunk/src/tester_test.erl
r33 r34 6 6 -export ([runs_a_test/1, reruns_a_test_when_given_module/1]). 7 7 -export ([runs_given_tests/1]). 8 -export ([runs_a_fixtured_test/1]).9 -test ([{nodes_fix, test_node, [runs_a_test, runs_given_tests]}]).10 -test ([{nodes_fix, test_node, [reruns_a_test_when_given_module]}]).11 8 12 9 start_tester (Node) -> … … 46 43 ok. 47 44 48 runs_a_fixtured_test (Node) ->49 Tester = start_tester (Node),50 [{1, 0, 0}, {1, 1, 1}] = send (eg_test_fix, Tester),51 ok.52 53 45 receive_all (Ms) -> 54 46 receive -
trunk/src/tests.erl
r33 r34 10 10 {Module, [{attributes, Attributes}]} = Chunks, 11 11 Declarations = lists: flatten ([T || {test, T} <- Attributes]), 12 filter_by_attribute (Module, Binary, Declarations, []). 12 Tests = filter (Binary, Declarations, []), 13 {Module, Tests}. 14 15 filter (Binary, [exports | Tail], Acc) -> 16 {ok, Chunks} = beam_lib: chunks (Binary, [exports]), 17 {_, [{exports, Exports}]} = Chunks, 18 Tests = lists: foldl (fun testable_export/2, [], Exports), 19 filter (Binary, Tail, [Tests | Acc]); 20 filter (_, [], Acc) -> 21 lists: flatten (Acc). 22 23 testable_export ({module_info, _}, Fs) -> Fs; 24 testable_export ({F, 0}, Fs) -> [F | Fs]; 25 testable_export (_, Fs) -> Fs. 13 26 14 27 receive_all () -> 15 28 receive_all ([]). 16 17 filter_by_attribute (Module, Binary, [exports | Tail], Tests) ->18 {ok, Chunks} = beam_lib: chunks (Binary, [exports]),19 {Module, [{exports, Exports}]} = Chunks,20 Funs = exports_to_funs (Module, Exports, []),21 filter_by_attribute (Module, Binary, Tail, [Funs | Tests]);22 filter_by_attribute (Module, Binary, [{M, F, Ts} | Tail], Tests) ->23 Funs = [{Module, T} || T <- Ts],24 filter_by_attribute (Module, Binary, Tail, [{M, F, [Funs]} | Tests]);25 filter_by_attribute (Module, _, [], Tests) ->26 {Module, lists: flatten (Tests)}.27 28 exports_to_funs (M, [{module_info, _} | Exports], Funs) ->29 exports_to_funs (M, Exports, Funs);30 exports_to_funs (M, [{F, 0} | Exports], Funs) ->31 exports_to_funs (M, Exports, [{M, F, []} | Funs]);32 exports_to_funs (M, [{_, _} | Exports], Funs) ->33 exports_to_funs (M, Exports, Funs);34 exports_to_funs (_, [], Funs) ->35 Funs.36 29 37 30 receive_all (Ms) -> -
trunk/src/tests_test.erl
r33 r34 9 9 filter_by_attribute () -> 10 10 filtering_non_tests_returns_empty_list(), 11 filtering_tests_returns_list_of_MFA_from_unloaded_binary (), 12 filtering_fixtured_tests_returns_list_of_fixture_fun_tuples (), 13 filtering_understands_mixed_export_and_fixtured_tests (), 11 filtering_tests_returns_list_of_tests_from_unloaded_binary (), 14 12 ok. 15 13 16 14 filtering_non_tests_returns_empty_list () -> 17 Binary = modules: to_binary ("../fix/eg_code.erl"), 15 Binary = modules: to_binary ("../fix/eg_code.erl"), 18 16 {eg_code, []} = tests: filter_by_attribute (Binary). 19 17 20 filtering_tests_returns_list_of_MFA_from_unloaded_binary () -> 21 File_name = "../fix/eg_test.erl", 22 Test = fun ([Ok, Nok]) -> 23 {Ok_m, Ok_f, Ok_a} = Ok, 24 ok = apply (Ok_m, Ok_f, Ok_a), 25 {Nok_m, Nok_f, Nok_a} = Nok, 26 Error = (catch apply (Nok_m, Nok_f, Nok_a)), 27 {'EXIT', {{badmatch, nok}, _}} = Error 28 end, 29 filtering (File_name, eg_test, Test). 30 31 filtering_fixtured_tests_returns_list_of_fixture_fun_tuples () -> 32 File_name = "../fix/eg_test_fix.erl", 33 Test = fun ([{Module, Fixture, [Tests]}]) -> 34 [ok] = Module: Fixture (Tests) 35 end, 36 filtering (File_name, eg_test_fix, Test). 37 38 filtering_understands_mixed_export_and_fixtured_tests () -> 39 File_name = "../fix/eg_test_fix_nofix.erl", 40 Test = fun ([{Module, Fixture, [With]}, Without]) -> 41 {Wo_m, Wo_f, Wo_a} = Without, 42 {'EXIT', {Reason, _}} = (catch apply (Wo_m, Wo_f, Wo_a)), 43 {badmatch, without_fixture_ok} = Reason, 44 [ok] = Module: Fixture (With) 45 end, 46 filtering (File_name, eg_test_fix_nofix, Test). 47 48 filtering (File_name, Module, Test) -> 49 Binary = modules: to_binary (File_name), 50 false = code: is_loaded (Module), 51 {Module, Tests} = tests: filter_by_attribute (Binary), 52 try 53 {module, Module} = code: load_binary (Module, File_name, Binary), 54 Test (Tests) 55 after 56 code: purge (Module), 57 code: delete (Module) 58 end. 18 filtering_tests_returns_list_of_tests_from_unloaded_binary () -> 19 File = "../fix/eg_test.erl", 20 Binary = modules: to_binary (File), 21 false = code: is_loaded (eg_test), 22 {eg_test, [ok, nok]} = tests: filter_by_attribute (Binary), 23 false = code: is_loaded (eg_test).
Note: See TracChangeset
for help on using the changeset viewer.
