Changeset 68
- Timestamp:
- 07/14/09 09:37:03 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 5 edited
-
compiler.erl (modified) (5 diffs)
-
compiler_test.erl (modified) (7 diffs)
-
modules.erl (modified) (2 diffs)
-
modules_test.erl (added)
-
shells.erl (modified) (1 diff)
-
shells_tests.erl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/compiler.erl
r65 r68 17 17 receive_files (Notify, Watcher, Modules, New) -> 18 18 receive 19 {Watcher, {{file, ".erl"}, File, Event}} when Event == found; Event == changed->19 {Watcher, {{file, ".erl"}, File, Event}} -> 20 20 receive_files (Notify, Watcher, Modules, dict: store (File, Event, New)); 21 21 {Watcher, _} -> … … 29 29 compile (Notify, Watcher, _, Modules) -> 30 30 notify_totals (Modules, Notify), 31 Init = {Modules, Notify, [] },32 {Processed, _, Binaries } = dict: fold (fun process/3, Init, Modules),33 notify_ binaries (Binaries, Notify),31 Init = {Modules, Notify, [], []}, 32 {Processed, _, Binaries, Removed} = dict: fold (fun process/3, Init, Modules), 33 notify_end (Binaries, Removed, Notify), 34 34 loop (Notify, Watcher, Processed). 35 35 36 process (File, Event, {Modules, Notify, Binaries}) when Event == found;37 Event == changed -> 36 process (File, Event, Acc) when Event == found; Event == changed -> 37 {Modules, Notify, Binaries, Removed} = Acc, 38 38 Result = modules: compile (File), 39 39 notify_result (Result, Notify), … … 41 41 notify_totals (New_modules, Notify), 42 42 New_binaries = binaries (Result, Binaries), 43 {New_modules, Notify, New_binaries}; 43 {New_modules, Notify, New_binaries, Removed}; 44 process (File, Event, Acc) when Event == lost -> 45 {Modules, Notify, Binaries, Removed} = Acc, 46 New_modules = dict: erase (File, Modules), 47 New_removed = [modules: module_name (File) | Removed], 48 {New_modules, Notify, Binaries, New_removed}; 44 49 process (_, _, Acc) -> 45 50 Acc. … … 52 57 Notify (dict: fold (fun count/3, {0, 0, 0}, Modules)). 53 58 59 count (_, lost, Acc) -> 60 Acc; 54 61 count (_, {ok, _, _, _}, {Total, Compiled, Successful}) -> 55 62 {Total + 1, Compiled + 1, Successful + 1}; … … 73 80 errors. 74 81 75 notify_ binaries (errors, _) ->82 notify_end (errors, _, _) -> 76 83 pass; 77 notify_ binaries (Bs, Notify) when is_list (Bs) ->78 Notify ({ binaries, Bs}).84 notify_end (Binaries, Removed, Notify) -> 85 Notify ({{binaries, Binaries}, {removed, Removed}}). -
trunk/src/compiler_test.erl
r67 r68 10 10 -export ([stops/0]). 11 11 -export ([can_start_empty_and_add_files/0]). 12 -export ([notifies_removed_files/0]). 13 -export ([notifies_removed_files_even_if_never_compiled/0]). 12 14 -include_lib("stdlib/include/ms_transform.hrl"). 13 15 … … 40 42 ok = fixtures: use_tree ([], F). 41 43 44 notifies_removed_files () -> 45 F = fun notifies_removed_files/2, 46 ok = fixtures: use_tree (good_erl_tree (), F). 47 48 notifies_removed_files_even_if_never_compiled () -> 49 F = fun notifies_removed_files_even_if_never_compiled/2, 50 Tree = [{file, "hello.erl", "rubbish"}], 51 ok = fixtures: use_tree (Tree, F). 52 42 53 provides_binaries_when_all_compiled (Root, _) -> 43 54 Compiler = spawn_link (compiler, init, [notify_me (), Root]), … … 46 57 Compiler ! stop, 47 58 ok = check (Ms, unknown), 48 { binaries, Bs} = lists: last (Ms),59 {{binaries, Bs}, _} = lists: last (Ms), 49 60 Chunks = [ beam_lib: chunks (B, [exports]) || B <- Bs], 50 61 Modules = [M || {ok, {M, [{exports, [_, _, {run, 0}]}]}} <- Chunks], … … 60 71 ok = file: write_file (File, Bin), 61 72 Compiler ! check, 62 [{2, 1, 1}, {2, 2, 2}, { binaries, [B]}] = receive_all (),73 [{2, 1, 1}, {2, 2, 2}, {{binaries, [B]}, _}] = receive_all (), 63 74 Compiler ! stop, 64 75 {ok, {hello, _}} = beam_lib: chunks (B, [exports]), … … 73 84 ok = file: write_file (File, Bin), 74 85 Compiler ! check, 75 [{1, 0, 0}, {1, 1, 1}, { binaries, [_]}] = receive_all (),86 [{1, 0, 0}, {1, 1, 1}, {{binaries, [_]}, _}] = receive_all (), 76 87 Compiler ! stop, 77 88 ok. 78 89 79 %% More tests: 80 %% - remove a file 90 notifies_removed_files (Root, [F, _]) -> 91 Compiler = spawn_link (compiler, init, [notify_me (), Root]), 92 Compiler ! check, 93 receive_all (), 94 {file, File, _} = F, 95 ok = file: delete (filename: join (Root, File)), 96 Compiler ! check, 97 [{1, 1, 1}, {{binaries, []}, {removed, [hello]}}] = receive_all (), 98 Compiler ! {self (), stop}, 99 ok. 100 101 notifies_removed_files_even_if_never_compiled (Root, [F]) -> 102 Compiler = spawn_link (compiler, init, [notify_me (), Root]), 103 Compiler ! check, 104 [{1, 0, 0}, {_, _}, {1, 1, 0}] = receive_all (), 105 {file, File, _} = F, 106 Filename = filename: join (Root, File), 107 Module = modules: module_name (Filename), 108 ok = file: delete (Filename), 109 Compiler ! check, 110 [{0, 0, 0}, {{binaries, []}, {removed, [Module]}}] = receive_all (), 111 Compiler ! {self (), stop}, 112 ok. 81 113 82 114 check ([{Total, 0, 0} | _] = Xs, unknown) -> … … 93 125 check ([{Total, Total, N}], Total) when N < Total -> 94 126 ok; 95 check ([{Total, Total, Total}, { binaries, _}], Total) ->127 check ([{Total, Total, Total}, {{binaries, _}, {removed, _}}], Total) -> 96 128 ok. 97 129 … … 110 142 receive 111 143 {Total, Total, Total} = Ts -> 112 receive { binaries, _} = Bs ->144 receive {{binaries, _}, {removed, _}} = Bs -> 113 145 lists: reverse ([Bs, Ts | Ms]) 114 146 end; -
trunk/src/modules.erl
r61 r68 8 8 -export ([forms_to_binary/1]). 9 9 -export ([compile/1]). 10 -export ([module_name/1]). 10 11 11 12 to_binary (File_name) -> … … 27 28 compile (File) -> 28 29 compile (fun compile: file/2, File). 30 31 module_name (Filename) -> 32 {extension, ".erl"} = {extension, filename: extension (Filename)}, 33 String = filename: rootname (filename: basename (Filename)), 34 list_to_atom (String). -
trunk/src/shells.erl
r64 r68 11 11 receive {Self, done} -> ok; 12 12 M -> io:fwrite ("tests_crash: ~p~n", [M]) 13 after 20000 -> throw ("tests timed out~n")13 after 30000 -> throw ("tests timed out~n") 14 14 end 15 15 -
trunk/src/shells_tests.erl
r64 r68 13 13 Modules = [fixtures_test, fixtures, 14 14 directory_watcher_test, directory_watcher, 15 compiler_test, compiler, modules], 15 compiler_test, compiler, 16 modules_test, modules], 16 17 ok = hand_send_to_tester (Modules, Test_node), 17 18 Caller ! {Caller, done}.
Note: See TracChangeset
for help on using the changeset viewer.
