Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit ece66f446bdad056882ad9575a61aaa5061090ef 1 parent ed5a401
Gianfranco Alongi authored
View
14 Two/Solution/src/port.erl
@@ -7,7 +7,9 @@
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,
@@ -15,9 +17,15 @@ open(_,Port,echo) ->
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.
View
8 Two/Solution/test/port_tests.erl
@@ -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,[]),
View
4 Two/Solution/test/test_files/compilation_error_module.erl
@@ -0,0 +1,4 @@
+-module(compilation_error_module).
+-export([handle/1]).
+handle(_) ->
+ Unboundvariable.
Please sign in to comment.
Something went wrong with that request. Please try again.