Permalink
Browse files

Added negative test for module == type usage.

Where module is not found in file-dir
  • Loading branch information...
1 parent b7d6ffa commit ed5a4010170d5b9f1dca774f3eb4a8739569b8fc Gianfranco Alongi committed Mar 8, 2012
Showing with 15 additions and 2 deletions.
  1. +9 −2 Two/Solution/src/port.erl
  2. +6 −0 Two/Solution/test/port_tests.erl
View
@@ -7,12 +7,19 @@
number :: integer()
}).
--spec(open(string(),integer(),atom() | string()) -> {ok,gen_tcp:socket()}).
+-spec(open(string(),integer(),atom() | string()) -> {ok,gen_tcp:socket()} | {error,no_such_module}).
open(_,Port,echo) ->
{ok,Sock} = gen_tcp:listen(Port,[{active,false}]),
{ok,#port{type = echo,
socket = Sock,
- number = Port}}.
+ number = Port}};
+open(FileDir,Port,ModuleName) ->
+ {ok,Files} = file:list_dir(FileDir),
+ case lists:member(ModuleName++".erl",Files) of
+ false ->
+ {error,no_such_module}
+ end.
+
-spec(close(#port{}) -> ok).
close(Port) ->
@@ -10,6 +10,12 @@ echo_port_open_close_test() ->
port:close(Openport),
assert_port_closed(Port).
+module_does_not_exist_port_failure_test() ->
+ Port = 50001,
+ Type = "non_existent_module",
+ FileDir = "./test/test_files/",
+ ?assertEqual({error,no_such_module},port:open(FileDir,Port,Type)).
+
%% ------------------------------------------------------------
assert_port_open(Port) ->
{ok,Sock} = gen_tcp:connect("localhost",Port,[]),

0 comments on commit ed5a401

Please sign in to comment.