Permalink
Browse files

make sure "rebar eunit" passes

When using yaws as an app dependency for another application built with
rebar, I noticed that testing that application with "rebar eunit" would
fail while testing yaws. It was easy to work around with "rebar eunit
skip_deps=true" but yaws really should pass its tests when tested via
rebar.

Change rebar.config to add ibrowse as a dependency. It's used only for
testing, but rebar doesn't support test-only dependencies, plus it's
filtered out during release generation anyway.

Modify some of the test files to be able to find ibrowse include files
regardless of whether they're built via make or via rebar. Also rename all
non-eunit test functions ending in "_test" so they don't confuse eunit. Also
had to move the embedded_yaws_id_dir test from eunit to t2 because it fails
under "rebar eunit" when yaws is a dependency for another app. It fails
because it calls into the yaws_api:embedded_start_conf function which tries
to call application:load(yaws), but paths aren't properly set up to allow
that to work under these testing circumstances.

Note that not all tests currently run under rebar; building with make and
then running "make test" results in many more tests being executed. Fixing
this will come later.
  • Loading branch information...
1 parent d0a90a9 commit 66f50e67727f7edc8ec4b93676b2605b200b13f1 @vinoski vinoski committed Aug 24, 2012
View
1 .gitignore
@@ -72,3 +72,4 @@ yaws_logs
rel/yaws
dialyzer_warnings
deps/*
+.eunit/*
View
5 rebar.config
@@ -22,3 +22,8 @@
{pre_hooks, [{compile, "./scripts/rebar-pre-script"},
{clean, "./scripts/rebar-pre-script clean"}]}.
+
+{deps,
+ [
+ {ibrowse, ".*", {git, "git://github.com/cmullaparthi/ibrowse.git", "HEAD"}}
+ ]}.
View
1 test/eunit/Makefile
@@ -3,7 +3,6 @@ include ../support/include.mk
OBJ := multipart_post_parsing.beam \
yaws_session_server_test.beam \
ehtml_test.beam \
- embedded_yaws_id_dir.beam \
cookies.beam \
headers.beam
View
16 test/eunit/cookies.erl
@@ -284,12 +284,24 @@ set_cookie_expires_test() ->
ok.
real_cookies_test() ->
- {ok, Io} = file:open("cookies.dump", read),
+ {ok, Io} = case file:open("cookies.dump", read) of
+ {error, _} ->
+ %% handle eunit testing under rebar
+ file:open("../test/eunit/cookies.dump", read);
+ Else ->
+ Else
+ end,
?assertEqual(ok, parse_cookies(Io, file:read_line(Io), 1)),
ok.
real_setcookies_test() ->
- {ok, Io} = file:open("setcookies.dump", read),
+ {ok, Io} = case file:open("setcookies.dump", read) of
+ {error, _} ->
+ %% handle eunit testing under rebar
+ file:open("../test/eunit/setcookies.dump", read);
+ Else ->
+ Else
+ end,
?assertEqual(ok, parse_set_cookies(Io, file:read_line(Io), 1)),
ok.
View
24 test/eunit/embedded_yaws_id_dir.erl
@@ -1,24 +0,0 @@
--module(embedded_yaws_id_dir).
-
--include_lib("eunit/include/eunit.hrl").
-
-id_dir_test() ->
- Id = "id_dir_test",
- GconfList = [{id, Id},
- {logdir, "./logs"},
- {ebin_dir, ["./ebin"]}],
- Docroot = yaws:tmpdir(),
- SconfList = [{port, 9999},
- {servername, Id},
- {listen, {127,0,0,1}},
- {docroot, Docroot}],
- {ok, _SCList, _GC, _ChildSpecs} = yaws_api:embedded_start_conf(
- Docroot, SconfList, GconfList, Id),
- try
- {ok,
- {file_info, _, directory, read_write, _, _, _, _, _, _, _, _, _, _}} =
- file:read_file_info(yaws:id_dir(Id)),
- ok
- after
- ok = file:del_dir(yaws:id_dir(Id))
- end.
View
2 test/support/include.mk.in
@@ -8,7 +8,7 @@ YAWS=$(YTOP)/bin/yaws
SUBST=../../scripts/Subst
-COMPILER_PA = -pa $(YTOP)/ebin
+COMPILER_PA = -pa $(YTOP)/ebin -pa $(YTOP)/test/ibrowse/ebin
%.beam: %.erl
"$(ERLC)" -Ddebug $(COMPILER_PA) $<
View
91 test/t2/app_test.erl
@@ -1,6 +1,6 @@
-module(app_test).
-include("../include/tftest.hrl").
--include("../ibrowse/include/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-compile(export_all).
@@ -13,27 +13,28 @@ start([F]) ->
start() ->
io:format("\n ==== MAIN TESTS ==== \n\n", []),
?line {ok, _} = ibrowse:start_link(),
- server_options_test(),
+ test_server_options(),
test1(),
test2(),
test3(),
- appmod_test(),
- streamcontent_test(),
+ test_appmod(),
+ test_streamcontent(),
sendfile_get(),
- json_test(),
- post_test(),
- flush_test(),
- expires_test(),
- reentrant_test(),
- cgi_redirect_test(),
- php_handler_test(),
- arg_rewrite_test(),
- shaper_test(),
- sslaccept_timeout_test(),
- throw_test(),
- too_many_headers_test(),
- index_files_test(),
- websocket_test(),
+ test_json(),
+ test_post(),
+ test_flush(),
+ test_expires(),
+ test_reentrant(),
+ test_cgi_redirect(),
+ test_php_handler(),
+ test_arg_rewrite(),
+ test_shaper(),
+ test_sslaccept_timeout(),
+ test_throw(),
+ test_too_many_headers(),
+ test_index_files(),
+ test_websocket(),
+ test_embedded_id_dir(),
ibrowse:stop().
@@ -137,7 +138,7 @@ test3() ->
[], head),
ok.
-server_options_test() ->
+test_server_options() ->
io:format("server_options_test\n",[]),
{ok, S} = gen_tcp:connect("localhost", 8000, [{packet, raw}, list,
{active, false}]),
@@ -227,7 +228,7 @@ collect(L, Count, Tag) ->
-define(APPMOD_HEADER, "Appmod-Called").
-appmod_test() ->
+test_appmod() ->
io:format("appmod_test\n",[]),
Uri1 = "http://localhost:8002/",
?line {ok, "200", Headers1, _} = ibrowse:send_req(Uri1, [], get),
@@ -243,7 +244,7 @@ appmod_test() ->
?line "true" = proplists:get_value(?APPMOD_HEADER, Headers4),
ok.
-streamcontent_test() ->
+test_streamcontent() ->
io:format("streamcontent_test\n",[]),
Uri1 = "http://localhost:8000/streamtest/1",
?line {ok, "200", Headers1, Body1} = ibrowse:send_req(Uri1, [], get),
@@ -282,7 +283,7 @@ streamcontent_test() ->
-define(JSON_URI, "http://localhost:8005/jsontest").
-json_test() ->
+test_json() ->
io:format("json_test\n",[]),
io:format(" param array1\n", []),
?line ok = do_json({struct, [{"jsonrpc", "2.0"},
@@ -527,7 +528,7 @@ recv_hdrs(Sock, Len) ->
%% partial_post_size = 2048000
-post_test() ->
+test_post() ->
io:format("post_test\n",[]),
small_post(),
large_post(),
@@ -579,7 +580,7 @@ large_chunked_post() ->
?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, Opts2),
ok.
-flush_test() ->
+test_flush() ->
io:format("flush_test\n",[]),
flush_small_post(),
flush_large_post(),
@@ -666,7 +667,7 @@ flush_chunked_get() ->
ok.
-expires_test() ->
+test_expires() ->
io:format("expires_test\n", []),
Uri = "http://localhost:8006/hello.txt",
?line {ok, "200", Hdrs, _} = ibrowse:send_req(Uri, [], get),
@@ -688,7 +689,7 @@ expires_test() ->
ok.
-reentrant_test() ->
+test_reentrant() ->
io:format("reentrant_test\n", []),
reentrant_test_status(),
reentrant_test_delayed_headers(),
@@ -709,22 +710,22 @@ reentrant_test_delayed_headers() ->
?line "true" = proplists:get_value("X-Delayed-Header", Hdrs),
ok.
-cgi_redirect_test() ->
+test_cgi_redirect() ->
io:format("cgi_redirect_test\n", []),
Uri = "http://localhost:8008/cgi-bin/redirect_test.cgi",
?line {ok, "302", Hdrs, _} = ibrowse:send_req(Uri, [], get),
?line true = lists:any(fun({"Location", _}) -> true; (_) -> false end, Hdrs),
ok.
-php_handler_test() ->
+test_php_handler() ->
io:format("php_handler_test\n", []),
Uri = "http://localhost:8006/test.php",
{ok, Binary} = file:read_file("./www/test.php"),
Content = binary_to_list(Binary),
?line {ok, "200", _, Content} = ibrowse:send_req(Uri, [], get),
ok.
-arg_rewrite_test() ->
+test_arg_rewrite() ->
io:format("arg_rewrite_test\n", []),
arg_rewrite_test_rewrite(),
arg_rewrite_test_redirect(),
@@ -759,7 +760,7 @@ arg_rewrite_test_response() ->
-shaper_test() ->
+test_shaper() ->
io:format("shaper_test\n", []),
Uri = "http://localhost:8007/",
?line {ok, "200", _, _} = ibrowse:send_req(Uri, [], get),
@@ -770,7 +771,7 @@ shaper_test() ->
-sslaccept_timeout_test() ->
+test_sslaccept_timeout() ->
io:format("sslaccept_tout_test\n", []),
{ok, Sock} = gen_tcp:connect("localhost", 8443, [binary, {active, true}]),
?line ok = receive
@@ -783,21 +784,21 @@ sslaccept_timeout_test() ->
gen_tcp:close(Sock),
ok.
-throw_test() ->
+test_throw() ->
io:format("throw test\n", []),
Uri = "http://localhost:8009/",
?line {ok, "500", _, _} = ibrowse:send_req(Uri, [], get),
ok.
-too_many_headers_test() ->
+test_too_many_headers() ->
io:format("too many request headers test\n", []),
Uri = "http://localhost:8009/",
Hdrs = [{link, "<compact.css>; rel=\"stylesheet\"; title=\"compact\""} || _ <- lists:seq(0, 1001)],
?line {ok, "431", _, _} = ibrowse:send_req(Uri, Hdrs, get),
ok.
-index_files_test() ->
+test_index_files() ->
io:format("index_files test\n", []),
%% "/" should be redirected to "/testdir", then to "/testdir/" and finally
%% get "/testdir/index.html"
@@ -815,7 +816,7 @@ index_files_test() ->
%% Do handshake, then send "hello" in a text frame
%% and check that "hello" is echoed back.
-websocket_test() ->
+test_websocket() ->
OpenHeads = "GET /websockets_example_endpoint.yaws HTTP/1.1\r\n"
"Host: localhost\r\n"
"Upgrade: websocket\r\n"
@@ -846,6 +847,26 @@ websocket_test() ->
ExpectFrame = <<129, 5, "hello">>,
{ok, ExpectFrame} = gen_tcp:recv(Sock, 0, 2000).
+test_embedded_id_dir() ->
+ Id = "id_dir_test",
+ GconfList = [{id, Id},
+ {logdir, "./logs"},
+ {ebin_dir, ["./ebin"]}],
+ Docroot = yaws:tmpdir(),
+ SconfList = [{port, 9999},
+ {servername, Id},
+ {listen, {127,0,0,1}},
+ {docroot, Docroot}],
+ {ok, _SCList, _GC, _ChildSpecs} = yaws_api:embedded_start_conf(
+ Docroot, SconfList, GconfList, Id),
+ try
+ {ok,
+ {file_info, _, directory, read_write, _, _, _, _, _, _, _, _, _, _}} =
+ file:read_file_info(yaws:id_dir(Id)),
+ ok
+ after
+ ok = file:del_dir(yaws:id_dir(Id))
+ end.
%% used for appmod tests
%%
View
2 test/t3/app_test.erl
@@ -1,6 +1,6 @@
-module(app_test).
-include("../include/tftest.hrl").
--include("../ibrowse/include/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-compile(export_all).
View
44 test/t4/app_test.erl
@@ -1,6 +1,6 @@
-module(app_test).
-include("../include/tftest.hrl").
--include("../ibrowse/include/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-compile(export_all).
@@ -23,16 +23,16 @@ start() ->
try
deflate_revproxy_test1(),
deflate_revproxy_test2(),
- post_revproxy_test(),
- streamcontent_revproxy_test(),
- keepalive_revproxy_test(),
- rewrite_revproxy_test(),
- large_content_revproxy_test(),
- no_content_length_revproxy_test(),
- failed_req_interception_revproxy_test(),
- failed_resp_interception_revproxy_test(),
- good_interception_revproxy_test(),
- fwdproxy_test(),
+ test_post_revproxy(),
+ test_streamcontent_revproxy(),
+ test_keepalive_revproxy(),
+ test_rewrite_revproxy(),
+ test_large_content_revproxy(),
+ test_no_content_length_revproxy(),
+ test_failed_req_interception_revproxy(),
+ test_failed_resp_interception_revproxy(),
+ test_good_interception_revproxy(),
+ test_fwdproxy(),
ok
catch
Error:Reason ->
@@ -81,9 +81,7 @@ deflate_revproxy_test2() ->
?line Res = binary_to_list(zlib:gunzip(Body2)),
ok.
-
-
-post_revproxy_test() ->
+test_post_revproxy() ->
io:format("post_revproxy_test\n",[]),
small_post(),
large_post(),
@@ -133,7 +131,7 @@ large_chunked_post() ->
-streamcontent_revproxy_test() ->
+test_streamcontent_revproxy() ->
io:format("streamcontent_revproxy_test\n", []),
Uri = "http://localhost:8000/revproxy1/streamtest",
Res = "This is the data in the first chunk\n"
@@ -151,7 +149,7 @@ streamcontent_revproxy_test() ->
ok.
-keepalive_revproxy_test() ->
+test_keepalive_revproxy() ->
io:format("keepalive_revproxy_test\n", []),
Path1 = "/revproxy1/hello.txt",
Path2 = "/",
@@ -186,7 +184,7 @@ keepalive_revproxy_test() ->
ok.
-rewrite_revproxy_test() ->
+test_rewrite_revproxy() ->
io:format("rewrite_revproxy_test\n", []),
Uri1 = "http://localhost:8000/rewrite/revproxy1/hello.txt",
Uri2 = "http://localhost:8000/rewrite/revproxy2/hello.txt",
@@ -199,7 +197,7 @@ rewrite_revproxy_test() ->
?line Res = Body2,
ok.
-large_content_revproxy_test() ->
+test_large_content_revproxy() ->
io:format("large_content_revproxy_test\n", []),
Uri = "http://localhost:8004/revproxy/8388608.bin",
@@ -211,7 +209,7 @@ large_content_revproxy_test() ->
?line Bin = Body,
ok.
-no_content_length_revproxy_test() ->
+test_no_content_length_revproxy() ->
io:format("no_content_length_revproxy_test\n", []),
Uri = "http://localhost:8001/revproxy1/nolengthtest",
Res = lists:duplicate(512, $A),
@@ -223,19 +221,19 @@ no_content_length_revproxy_test() ->
?line Res = Body,
ok.
-failed_req_interception_revproxy_test() ->
+test_failed_req_interception_revproxy() ->
io:format("failed_req_interception_revproxy_test\n", []),
Uri = "http://localhost:8005/revproxy1/failedreqinterception",
?line {ok, "500", _, _} = ibrowse:send_req(Uri, [], get),
ok.
-failed_resp_interception_revproxy_test() ->
+test_failed_resp_interception_revproxy() ->
io:format("failed_resp_interception_revproxy_test\n", []),
Uri = "http://localhost:8005/revproxy2/failedrespinterception",
?line {ok, "500", _, _} = ibrowse:send_req(Uri, [], get),
ok.
-good_interception_revproxy_test() ->
+test_good_interception_revproxy() ->
io:format("good_interception_revproxy_test\n", []),
Uri = "http://localhost:8005/revproxy3/hello.txt",
Res = "Hello, World!\n",
@@ -245,7 +243,7 @@ good_interception_revproxy_test() ->
?line "true" = proplists:get_value("X-Test-Interception", Hdrs),
ok.
-fwdproxy_test() ->
+test_fwdproxy() ->
io:format("fwdproxy_test\n", []),
Uri1 = "http://localhost:8001/rewrite/hello.txt",
Uri2 = "http://localhost:8002/rewrite/hello.txt",
View
2 test/t5/app_test.erl
@@ -1,6 +1,6 @@
-module(app_test).
-include("../include/tftest.hrl").
--include("../ibrowse/include/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-compile(export_all).
View
18 test/t7/app_test.erl
@@ -1,6 +1,6 @@
-module(app_test).
-include("../include/tftest.hrl").
--include("../ibrowse/include/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-compile(export_all).
@@ -13,14 +13,14 @@ start([F]) ->
start() ->
io:format("\n ==== MIME-TYPES TESTS ==== \n\n", []),
?line {ok, _} = ibrowse:start_link(),
- generated_module_test(),
- default_type_test(),
- yaws_type_test(),
- erlang_type_test(),
+ test_generated_module(),
+ test_default_type(),
+ test_yaws_type(),
+ test_erlang_type(),
ibrowse:stop().
-generated_module_test() ->
+test_generated_module() ->
io:format("generated_module_test\n", []),
{ok, Host} = inet:gethostname(),
Node = list_to_atom("test@" ++ Host),
@@ -87,7 +87,7 @@ generated_module_test() ->
ok.
-default_type_test() ->
+test_default_type() ->
io:format("default_type_test\n", []),
Uri1 = "http://localhost:8000/news",
Uri2 = "http://localhost:8001/news",
@@ -97,7 +97,7 @@ default_type_test() ->
?line "text/plain; charset=UTF-8" = proplists:get_value("Content-Type", Hdrs2),
ok.
-yaws_type_test() ->
+test_yaws_type() ->
io:format("yaws_type_test\n", []),
Uri1 = "http://localhost:8000/index.yaws",
Uri2 = "http://localhost:8001/index.yaws",
@@ -107,7 +107,7 @@ yaws_type_test() ->
?line "text/xhtml; charset=ISO-8859-1" = proplists:get_value("Content-Type", Hdrs2),
ok.
-erlang_type_test() ->
+test_erlang_type() ->
io:format("erlang_type_test\n", []),
Uri1 = "http://localhost:8000/code/myappmod.erl",
Uri2 = "http://localhost:8001/code/myappmod.erl",

0 comments on commit 66f50e6

Please sign in to comment.