Changeset 18


Ignore:
Timestamp:
02/13/08 18:49:59 (4 years ago)
Author:
dom
Message:

Allow tests to take a fixture as argument

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/fix/eg_test.erl

    r17 r18  
    55-module (eg_test). 
    66-test (exports). 
    7 -export ([ok/0, nok/0]). 
     7-export ([ok/0, nok/0, with_fixture/1]). 
    88 
    99ok () -> 
     
    1212nok () -> 
    1313    ok = list_to_existing_atom ("nok"). 
     14 
     15with_fixture (F) -> 
     16    "data" = F ("data"), 
     17    ok. 
  • trunk/src/tests.erl

    r17 r18  
    1212 
    1313filter_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], 
     14    {ok, {Module, [{exports, Exports}]}} = beam_lib: chunks (Binary, [exports]), 
     15    Funs = exports_to_funs (Module, Exports, []), 
    1616    filter_by_attribute (Binary, Tail, [Funs | Tests]); 
    1717filter_by_attribute (_, [], Tests) -> 
    1818    lists: flatten (Tests). 
     19 
     20exports_to_funs (M, [{module_info, _} | Exports], Funs) -> 
     21    exports_to_funs (M, Exports, Funs); 
     22exports_to_funs (M, [{F, 0} | Exports], Funs) -> 
     23    Fun = fun (_) -> M: F () end, 
     24    exports_to_funs (M, Exports, [Fun | Funs]); 
     25exports_to_funs (M, [{F, 1} | Exports], Funs) -> 
     26    Fun = fun (Fix) -> M: F (Fix) end, 
     27    exports_to_funs (M, Exports, [Fun | Funs]); 
     28exports_to_funs (_, [], Funs) -> 
     29    Funs. 
  • trunk/src/tests_test.erl

    r17 r18  
    2020    Binary = modules: to_binary (File_name), 
    2121    false = code: is_loaded (eg_test), 
    22     [Nok, Ok] = tests: filter_by_attribute (Binary), 
     22    [With_fixture, Ok, Nok] = tests: filter_by_attribute (Binary), 
    2323    try 
    2424        {module, eg_test} = code: load_binary (eg_test, File_name, Binary), 
    25         ok = Ok (), 
    26         {'EXIT', {{badmatch, nok}, _}} = (catch Nok ()) 
     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) 
    2728    after 
    2829        code: purge (eg_test), 
     
    3031    end. 
    3132 
     33empty_fixture (_) -> 
     34    throw (empty_fixture). 
     35 
     36echo_fixture (X) -> 
     37    X. 
Note: See TracChangeset for help on using the changeset viewer.