Changeset 49


Ignore:
Timestamp:
04/14/09 12:56:28 (3 years ago)
Author:
dom
Message:

Added caracterisation tests to directory_watcher, then handled bad (fake) symlinks like those Emacs creates (with Charpi)

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/directory_watcher.erl

    r48 r49  
    2828 
    2929read_state (Filename, State) -> 
    30     {ok, Info} = file: read_file_info (Filename), 
    31     [{Filename, value (Info#file_info.type, Filename)} | State]. 
     30    case file: read_file_info (Filename) of 
     31        {ok, Info} -> 
     32            [{Filename, value (Info#file_info.type, Filename)} | State]; 
     33        _ -> 
     34            State 
     35    end. 
    3236 
    3337value (regular, Filename) -> 
  • trunk/src/directory_watcher_test.erl

    r48 r49  
    1 %%% Copyright (C) 2009 Dominic Williams 
     1%%% Copyright (C) 2009 Dominic Williams, Nicolas Charpentier 
    22%%% All rights reserved. 
    33%%% See file COPYING. 
     
    77-export ([tests_from_empty/0]). 
    88-export ([tests_from_non_existent/0]). 
     9-export ([tests_with_several/0]). 
     10-export ([bad_symlinks_are_ignored/0]). 
    911 
    1012tests_from_empty () -> 
     
    2527    ok. 
    2628 
     29tests_with_several () -> 
     30    Tree = [{file, "foo.txt", "Hello"}, 
     31            {file, "bar.txt", "G'day"}, 
     32            {file, "toto.erl", "-module(toto)."}], 
     33    ok = fixtures: use_tree (Tree, fun tests_with_several/2). 
     34 
     35bad_symlinks_are_ignored () -> 
     36    ok = fixtures: use_tree ([], fun bad_symlinks_are_ignored/2). 
     37 
     38bad_symlinks_are_ignored (Dir, _) -> 
     39    Watcher = spawn_link (directory_watcher, init, [Dir, notify (), ignore]), 
     40    Link = filename: join (Dir, "titi.erl"), 
     41    Destination = filename: join (Dir, "nofile"), 
     42    case file: make_symlink (Destination, Link) of 
     43        ok -> 
     44            Watcher ! check, 
     45            timeout = receive_one (); 
     46        {error, enotsup} -> 
     47            ok 
     48    end, 
     49    ok. 
     50     
    2751tests_from_empty (Dir, []) -> 
    2852    State = make_ref (), 
     
    5074    {watcher, unknown, Subdir, lost, State} = receive_one (), 
    5175 
     76    rewrite_same_data (Filename), 
     77    Watcher ! check, 
     78    timeout = receive_one (), 
     79 
    5280    ok = file: write_file (Filename, list_to_binary ("Bye")), 
    5381    Watcher ! check, 
     
    5886    {Watcher, bye} = receive_one (), 
    5987    false = is_process_alive (Watcher), 
     88    ok. 
     89 
     90rewrite_same_data (Filename) -> 
     91    ok = file: write_file (Filename, list_to_binary ("Hello")). 
     92 
     93tests_with_several (Dir, Tree) -> 
     94    [Foo, Bar, Toto] = [filename: join (Dir, Name) || {file, Name, _} <- Tree], 
     95    State = make_ref (), 
     96    Watcher = spawn_link (directory_watcher, init, [Dir, notify (), State]), 
     97    {watcher, {file, ".txt"}, Bar, found, State} = receive_one (), 
     98    {watcher, {file, ".txt"}, Foo, found, State} = receive_one (), 
     99    {watcher, {file, ".erl"}, Toto, found, State} = receive_one (), 
     100     
     101    ok = file: write_file (Foo, list_to_binary ("Bye")), 
     102    Watcher ! check, 
     103    {watcher, {file, ".txt"}, Foo, changed, State} = receive_one (), 
     104     
     105    ok = file: write_file (Foo, list_to_binary ("Not yet")), 
     106    ok = file: write_file (Bar, list_to_binary ("Bye")), 
     107    Watcher ! check, 
     108    {watcher, {file, ".txt"}, Bar, changed, State} = receive_one (), 
     109    Watcher ! check, 
     110    {watcher, {file, ".txt"}, Foo, changed, State} = receive_one (), 
    60111    ok. 
    61112                                
Note: See TracChangeset for help on using the changeset viewer.