Permalink
Browse files

Added test for compilation error on files and file that causes error

  • Loading branch information...
1 parent ed5a401 commit ece66f446bdad056882ad9575a61aaa5061090ef Gianfranco Alongi committed Mar 8, 2012
View
@@ -7,17 +7,25 @@
number :: integer()
}).
--spec(open(string(),integer(),atom() | string()) -> {ok,gen_tcp:socket()} | {error,no_such_module}).
+-spec(open(string(),integer(),atom() | string()) -> {ok,gen_tcp:socket()} |
+ {error,no_such_module}|
+ {error,compile_error}).
open(_,Port,echo) ->
{ok,Sock} = gen_tcp:listen(Port,[{active,false}]),
{ok,#port{type = echo,
socket = Sock,
number = Port}};
open(FileDir,Port,ModuleName) ->
{ok,Files} = file:list_dir(FileDir),
- case lists:member(ModuleName++".erl",Files) of
+ ErlSource = ModuleName++".erl",
+ case lists:member(ErlSource,Files) of
false ->
- {error,no_such_module}
+ {error,no_such_module};
+ true ->
+ case compile:file(filename:join(FileDir,ErlSource)) of
+ error ->
+ {error,compile_error}
+ end
end.
@@ -16,6 +16,14 @@ module_does_not_exist_port_failure_test() ->
FileDir = "./test/test_files/",
?assertEqual({error,no_such_module},port:open(FileDir,Port,Type)).
+module_does_exist_but_can_not_compile_test() ->
+ Port = 50001,
+ Type = "compilation_error_module",
+ FileDir = "./test/test_files/",
+ ?assertMatch({error,compile_error},port:open(FileDir,Port,Type)).
+
+
+
%% ------------------------------------------------------------
assert_port_open(Port) ->
{ok,Sock} = gen_tcp:connect("localhost",Port,[]),
@@ -0,0 +1,4 @@
+-module(compilation_error_module).
+-export([handle/1]).
+handle(_) ->
+ Unboundvariable.

0 comments on commit ece66f4

Please sign in to comment.