Skip to content

Commit

Permalink
Added negative test for module == type usage.
Browse files Browse the repository at this point in the history
Where module is not found in file-dir
  • Loading branch information
Gianfranco Alongi committed Mar 8, 2012
1 parent b7d6ffa commit ed5a401
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Two/Solution/src/port.erl
Expand Up @@ -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) ->
Expand Down
6 changes: 6 additions & 0 deletions Two/Solution/test/port_tests.erl
Expand Up @@ -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,[]),
Expand Down

0 comments on commit ed5a401

Please sign in to comment.