Changeset 19 for trunk


Ignore:
Timestamp:
02/20/08 16:54:36 (4 years ago)
Author:
dom
Message:

Change the way fixtured tests are written (see eg_test_with_fixture.erl)

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/fix/eg_test.erl

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

    r18 r19  
    77 
    88filter_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, 
    1011    Declarations = lists: flatten ([T || {test, T} <- Attributes]), 
    11     filter_by_attribute (Binary, Declarations, []). 
     12    filter_by_attribute (Module, Binary, Declarations, []). 
    1213 
    13 filter_by_attribute (Binary, [exports | Tail], Tests) -> 
    14     {ok, {Module, [{exports, Exports}]}} = beam_lib: chunks (Binary, [exports]), 
     14filter_by_attribute (Module, Binary, [exports | Tail], Tests) -> 
     15    {ok, Chunks} = beam_lib: chunks (Binary, [exports]), 
     16    {Module, [{exports, Exports}]} = Chunks, 
    1517    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]); 
     19filter_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]); 
     22filter_by_attribute (_, _, [], Tests) -> 
    1823    lists: flatten (Tests). 
    1924 
     
    2126    exports_to_funs (M, Exports, Funs); 
    2227exports_to_funs (M, [{F, 0} | Exports], Funs) -> 
    23     Fun = fun (_) -> M: F () end, 
     28    Fun = fun () -> M: F () end, 
    2429    exports_to_funs (M, Exports, [Fun | Funs]); 
    2530exports_to_funs (M, [{F, 1} | Exports], Funs) -> 
  • trunk/src/tests_test.erl

    r18 r19  
    1010    filtering_non_tests_returns_empty_list(), 
    1111    filtering_tests_returns_list_of_funs_from_unloaded_binary (), 
     12    filtering_fixtured_tests_returns_list_of_fixture_fun_tuples (), 
    1213    ok. 
    1314 
     
    2021    Binary = modules: to_binary (File_name), 
    2122    false = code: is_loaded (eg_test), 
    22     [With_fixture, Ok, Nok] = tests: filter_by_attribute (Binary), 
     23    [Ok, Nok] = tests: filter_by_attribute (Binary), 
    2324    try 
    2425        {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 ()) 
    2828    after 
    2929        code: purge (eg_test), 
     
    3131    end. 
    3232 
    33 empty_fixture (_) -> 
    34     throw (empty_fixture). 
    35  
    36 echo_fixture (X) -> 
    37     X. 
     33filtering_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.