Changeset 17
- Timestamp:
- 02/12/08 18:51:47 (4 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 3 edited
- 2 moved
-
fix (added)
-
fix/README (added)
-
fix/eg_code.erl (moved) (moved from trunk/src/eg_code.erl)
-
fix/eg_test.erl (moved) (moved from trunk/src/eg_test.erl)
-
src/README (modified) (1 diff)
-
src/modules.erl (added)
-
src/tests.erl (modified) (1 diff)
-
src/tests_test.erl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/README
r16 r17 5 5 6 6 *_test.erl: developer tests 7 eg_*.erl: example code used by tests8 7 other: application code 9 8 -
trunk/src/tests.erl
r15 r17 6 6 -export ([filter_by_attribute/1]). 7 7 8 filter_by_attribute ( Module) ->9 Attributes = Module: module_info (attributes),10 Declarations = lists: flatten ([T || {test, T} <- Attributes]),11 filter_by_attribute ( Module, Declarations, []).8 filter_by_attribute (Binary) -> 9 {ok, {_, [{attributes, Attributes}]}} = beam_lib: chunks (Binary, [attributes]), 10 Declarations = lists: flatten ([T || {test, T} <- Attributes]), 11 filter_by_attribute (Binary, Declarations, []). 12 12 13 filter_by_attribute ( Module, [exports | Tail], Tests) ->14 Exports = Module: module_info (exports),15 Funs = [fun () -> Module: X () end || {X, 0} <- Exports, X /= module_info],16 filter_by_attribute ( Module, Tail, [Funs | Tests]);13 filter_by_attribute (Binary, [exports | Tail], Tests) -> 14 {ok, {Module, [{exports, Exports}]}} = beam_lib: chunks (Binary, [exports]), 15 Funs = [fun () -> Module: X () end || {X, 0} <- Exports, X /= module_info], 16 filter_by_attribute (Binary, Tail, [Funs | Tests]); 17 17 filter_by_attribute (_, [], Tests) -> 18 lists:flatten (Tests). 19 20 18 lists: flatten (Tests). -
trunk/src/tests_test.erl
r15 r17 8 8 9 9 filter_by_attribute_test () -> 10 [] = tests:filter_by_attribute (eg_code), 11 [Ok, Nok] = tests: filter_by_attribute (eg_test), 12 ok = Ok (), 13 {'EXIT', {{badmatch, nok}, _}} = (catch Nok ()), 10 filtering_non_tests_returns_empty_list(), 11 filtering_tests_returns_list_of_funs_from_unloaded_binary (), 14 12 ok. 13 14 filtering_non_tests_returns_empty_list () -> 15 Binary = modules: to_binary ("../fix/eg_code.erl"), 16 [] = tests: filter_by_attribute (Binary). 17 18 filtering_tests_returns_list_of_funs_from_unloaded_binary () -> 19 File_name = "../fix/eg_test.erl", 20 Binary = modules: to_binary (File_name), 21 false = code: is_loaded (eg_test), 22 [Nok, Ok] = tests: filter_by_attribute (Binary), 23 try 24 {module, eg_test} = code: load_binary (eg_test, File_name, Binary), 25 ok = Ok (), 26 {'EXIT', {{badmatch, nok}, _}} = (catch Nok ()) 27 after 28 code: purge (eg_test), 29 code: delete (eg_test) 30 end. 31
Note: See TracChangeset
for help on using the changeset viewer.
