Permalink
Browse files

Added negative test for directory reading

  • Loading branch information...
1 parent ac5700f commit eb2a6883520d8c3585b4a1951420e87d2da3aab4 Gianfranco Alongi committed Feb 19, 2012
Showing with 10 additions and 2 deletions.
  1. +4 −2 One/Solution/src/ros_reader.erl
  2. +6 −0 One/Solution/test/ros_reader_tests.erl
@@ -11,11 +11,13 @@ read_file(File) ->
R -> R
end.
--spec(read_dir(string()) -> {ok,[{string(),term()}]}).
+-spec(read_dir(string()) -> {ok,[{string(),term()}]} | {error,no_such_dir}).
read_dir(Dir) ->
case file:list_dir(Dir) of
{ok,Files} ->
Res = [{File, read_file(filename:join(Dir,File))} || File <- Files ],
- {ok,lists:sort(Res)}
+ {ok,lists:sort(Res)};
+ {error,enoent} ->
+ {error,no_such_dir}
end.
@@ -15,5 +15,11 @@ ros_read_dir_test() ->
[{"file_a.ros",ResultA},
{"file_b.ros",ResultB}]},
ros_reader:read_dir(Dir)).
+
+ros_read_negative_test() ->
+ Dir = "./test/non_existent/",
+ ?assertMatch({error,no_such_dir},
+ ros_reader:read_dir(Dir)).
+

0 comments on commit eb2a688

Please sign in to comment.