Skip to content
Browse files

Test to see that we can declare a type that has compilation warnings

  • Loading branch information...
1 parent ece66f4 commit 65632a9e2391d042785b6c502695f20df6a510b3 Gianfranco Alongi committed
View
16 Two/Solution/src/port.erl
@@ -2,12 +2,12 @@
-export([open/3,
close/1
]).
--record(port,{type :: echo,
+-record(port,{type :: echo | string(),
socket :: gen_tcp:socket(),
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}|
{error,compile_error}).
open(_,Port,echo) ->
@@ -22,9 +22,17 @@ open(FileDir,Port,ModuleName) ->
false ->
{error,no_such_module};
true ->
- case compile:file(filename:join(FileDir,ErlSource)) of
+ case compile:file(filename:join(FileDir,ErlSource),[report_warnings,
+ report_errors,
+ binary]) of
error ->
- {error,compile_error}
+ {error,compile_error};
+ {ok,Module,Binary} ->
+ {module,Module} = code:load_binary(Module,ErlSource,Binary),
+ {ok,Sock} = gen_tcp:listen(Port,[{active,false}]),
+ {ok,#port{type = ModuleName,
+ socket = Sock,
+ number = Port}}
end
end.
View
12 Two/Solution/test/port_tests.erl
@@ -11,17 +11,25 @@ echo_port_open_close_test() ->
assert_port_closed(Port).
module_does_not_exist_port_failure_test() ->
- Port = 50001,
+ Port = 50002,
Type = "non_existent_module",
FileDir = "./test/test_files/",
?assertEqual({error,no_such_module},port:open(FileDir,Port,Type)).
module_does_exist_but_can_not_compile_test() ->
- Port = 50001,
+ Port = 50003,
Type = "compilation_error_module",
FileDir = "./test/test_files/",
?assertMatch({error,compile_error},port:open(FileDir,Port,Type)).
+module_does_exist_and_compilation_warning_open_test() ->
+ Port = 50004,
+ Type = "compilation_warning_module",
+ FileDir = "./test/test_files/",
+ {ok,Openport} = port:open(FileDir,Port,Type),
+ assert_port_open(Port),
+ port:close(Openport),
+ assert_port_closed(Port).
%% ------------------------------------------------------------
View
4 Two/Solution/test/test_files/compilation_warning_module.erl
@@ -0,0 +1,4 @@
+-module(compilation_warning_module).
+-export([handle/1]).
+handle(UnusedVariable) ->
+ ok.

0 comments on commit 65632a9

Please sign in to comment.
Something went wrong with that request. Please try again.