Changeset 17


Ignore:
Timestamp:
02/12/08 18:51:47 (4 years ago)
Author:
dom
Message:

Make test filter work on unloaded binary

Location:
trunk
Files:
3 added
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/README

    r16 r17  
    55 
    66*_test.erl: developer tests 
    7 eg_*.erl: example code used by tests 
    87other: application code 
    98 
  • trunk/src/tests.erl

    r15 r17  
    66-export ([filter_by_attribute/1]). 
    77 
    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, []). 
     8filter_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, []). 
    1212 
    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]); 
     13filter_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]); 
    1717filter_by_attribute (_, [], Tests) -> 
    18     lists:flatten (Tests). 
    19      
    20      
     18    lists: flatten (Tests). 
  • trunk/src/tests_test.erl

    r15 r17  
    88 
    99filter_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 (), 
    1412    ok. 
     13 
     14filtering_non_tests_returns_empty_list () -> 
     15    Binary = modules: to_binary ("../fix/eg_code.erl"),  
     16    [] = tests: filter_by_attribute (Binary). 
     17 
     18filtering_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.