- Timestamp:
- 02/20/08 16:54:36 (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
-
fix/eg_test.erl (modified) (2 diffs)
-
fix/eg_test_with_fixture.erl (added)
-
src/tests.erl (modified) (2 diffs)
-
src/tests_test.erl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fix/eg_test.erl
r18 r19 5 5 -module (eg_test). 6 6 -test (exports). 7 -export ([ok/0, nok/0 , with_fixture/1]).7 -export ([ok/0, nok/0]). 8 8 9 9 ok () -> … … 13 13 ok = list_to_existing_atom ("nok"). 14 14 15 with_fixture (F) ->16 "data" = F ("data"),17 ok. -
trunk/src/tests.erl
r18 r19 7 7 8 8 filter_by_attribute (Binary) -> 9 {ok, {_, [{attributes, Attributes}]}} = beam_lib: chunks (Binary, [attributes]), 9 {ok, Chunks} = beam_lib: chunks (Binary, [attributes]), 10 {Module, [{attributes, Attributes}]} = Chunks, 10 11 Declarations = lists: flatten ([T || {test, T} <- Attributes]), 11 filter_by_attribute ( Binary, Declarations, []).12 filter_by_attribute (Module, Binary, Declarations, []). 12 13 13 filter_by_attribute (Binary, [exports | Tail], Tests) -> 14 {ok, {Module, [{exports, Exports}]}} = beam_lib: chunks (Binary, [exports]), 14 filter_by_attribute (Module, Binary, [exports | Tail], Tests) -> 15 {ok, Chunks} = beam_lib: chunks (Binary, [exports]), 16 {Module, [{exports, Exports}]} = Chunks, 15 17 Funs = exports_to_funs (Module, Exports, []), 16 filter_by_attribute (Binary, Tail, [Funs | Tests]); 17 filter_by_attribute (_, [], Tests) -> 18 filter_by_attribute (Module, Binary, Tail, [Funs | Tests]); 19 filter_by_attribute (Module, Binary, [{M, F, Ts} | Tail], Tests) -> 20 Funs = [fun (Fix) -> Module:T (Fix) end || T <- Ts], 21 filter_by_attribute (Module, Binary, Tail, [{M, F, Funs} | Tests]); 22 filter_by_attribute (_, _, [], Tests) -> 18 23 lists: flatten (Tests). 19 24 … … 21 26 exports_to_funs (M, Exports, Funs); 22 27 exports_to_funs (M, [{F, 0} | Exports], Funs) -> 23 Fun = fun ( _) -> M: F () end,28 Fun = fun () -> M: F () end, 24 29 exports_to_funs (M, Exports, [Fun | Funs]); 25 30 exports_to_funs (M, [{F, 1} | Exports], Funs) -> -
trunk/src/tests_test.erl
r18 r19 10 10 filtering_non_tests_returns_empty_list(), 11 11 filtering_tests_returns_list_of_funs_from_unloaded_binary (), 12 filtering_fixtured_tests_returns_list_of_fixture_fun_tuples (), 12 13 ok. 13 14 … … 20 21 Binary = modules: to_binary (File_name), 21 22 false = code: is_loaded (eg_test), 22 [ With_fixture,Ok, Nok] = tests: filter_by_attribute (Binary),23 [Ok, Nok] = tests: filter_by_attribute (Binary), 23 24 try 24 25 {module, eg_test} = code: load_binary (eg_test, File_name, Binary), 25 ok = Ok (fun empty_fixture/1), 26 {'EXIT', {{badmatch, nok}, _}} = (catch Nok (fun empty_fixture/1)), 27 ok = With_fixture (fun echo_fixture/1) 26 ok = Ok (), 27 {'EXIT', {{badmatch, nok}, _}} = (catch Nok ()) 28 28 after 29 29 code: purge (eg_test), … … 31 31 end. 32 32 33 empty_fixture (_) -> 34 throw (empty_fixture). 35 36 echo_fixture (X) -> 37 X. 33 filtering_fixtured_tests_returns_list_of_fixture_fun_tuples () -> 34 File_name = "../fix/eg_test_with_fixture.erl", 35 Binary = modules: to_binary (File_name), 36 [{Module, Fixture, Tests}] = tests: filter_by_attribute (Binary), 37 try 38 {module, eg_test_with_fixture} = 39 code: load_binary (eg_test_with_fixture, File_name, Binary), 40 [ok] = Module:Fixture (Tests) 41 after 42 code: purge (eg_test_with_fixture), 43 code: delete (eg_test_with_fixture) 44 end. 45
Note: See TracChangeset
for help on using the changeset viewer.
