Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…

…/yaws@1321 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit a919ac1246c83aedea60e3a0a6f0a3f3b323fca0 1 parent 9517bd9
Claes Wikstrom authored
2  test/include/tftest.hrl
View
@@ -0,0 +1,2 @@
+-define(line, put('$line',{?MODULE,?LINE}),).
+
2  test/src/Makefile
View
@@ -1,4 +1,4 @@
include ../support/include.mk
-all: test.beam
+all: test.beam tftest.beam
clean: tclean
148 test/src/tftest.erl
View
@@ -0,0 +1,148 @@
+-module(tftest).
+
+%%% external exports
+-export([start/0, start/1]).
+
+%% Use these functions if you want to start/stop coverage yourself
+-export([cover_start/1, cover_stop/1]).
+
+-include("../include/tftest.hrl").
+
+start() ->
+ start(true).
+start([_]) ->
+ start(false);
+
+start(DoHalt) ->
+ spawn(fun() -> start1(DoHalt) end).
+
+start1(DoHalt) ->
+ process_flag(trap_exit, true),
+ Pid = spawn_link(fun() -> start2() end),
+ receive
+ {'EXIT', Pid, tests_ok} ->
+ io:format("\n** All tests completed successfully.\n"),
+ dohalt(DoHalt, 0);
+ {'EXIT', Pid, {tests_failed, M, Line, Error}} ->
+ {ok, Wd} = file:get_cwd(),
+ io:format("**************\n"
+ "** test failed at ~p.erl:~p\n"
+ " in ~p\n"
+ "** reason: \n"
+ " ~p\n"
+ "**************\n",
+ [M, Line, Wd, Error]),
+ %% allow time to flush output
+ timer:sleep(1000),
+ dohalt(DoHalt, 1);
+ {'EXIT', Pid, R} ->
+ io:format("**************\n"
+ "** test failed ~p\n",
+ [R]),
+ %% allow time to flush output
+ timer:sleep(1000),
+ dohalt(DoHalt, 1)
+ end.
+
+start2() ->
+ CM =
+ case catch app_test:cover_modules() of
+ {'EXIT', _} ->
+ [];
+ Mods ->
+ cover_start(Mods)
+ end,
+ application:load(sasl),
+ application:set_env(sasl, errlog_type, error),
+ application:start(sasl),
+ case catch app_test:start() of
+ ok ->
+ cover_stop(CM),
+ exit(tests_ok);
+ Error ->
+ {M,Line} = case get('$line') of
+ undefined -> {undefined, undefined};
+ ML -> ML
+ end,
+ exit({tests_failed, M, Line, Error})
+ end.
+
+%% @spec (Mods::[atom()]) -> CoveredModules::[atom()]
+cover_start(Mods) ->
+ cover:start(),
+ %% First cover-compile listed modules
+ CM = lists:foldl(
+ fun (M, Ms) ->
+ case module_source_or_beam(M) of
+ {source, File} ->
+ {ok, _} = cover:compile(File),
+ [M|Ms];
+ {beam, File} ->
+ {ok, _} = cover:compile_beam(File),
+ [M|Ms];
+ _ ->
+ Ms
+ end
+ end, [], Mods),
+ %% Now merge any previous state
+ case file:open(cover_state_file(), [read]) of
+ {ok, F} ->
+ file:close(F),
+ cover:import(cover_state_file());
+ _ ->
+ ok
+ end,
+ CM.
+
+module_source_or_beam(M) ->
+ CInfo = M:module_info(compile),
+ {value, {options, COptions}} = lists:keysearch(options, 1, CInfo),
+ Source = case lists:keysearch(source, 1, CInfo) of
+ {value, {source, SFile}} ->
+ case file:open(SFile, [read]) of
+ {ok, SFd} ->
+ file:close(SFd),
+ SFile;
+ _ ->
+ unknown
+ end;
+ _ ->
+ unknown
+ end,
+ Beam = case lists:keysearch(outdir, 1, COptions) of
+ {value, {outdir, Dir = "/" ++ _}} ->
+ BFile = filename:join(Dir, atom_to_list(M) ++ ".beam"),
+ case file:open(BFile, [read]) of
+ {ok, BFd} ->
+ file:close(BFd),
+ BFile;
+ _ ->
+ unknown
+ end;
+ _ ->
+ unknown
+ end,
+ case lists:member(debug_info, COptions) of
+ true when Beam =/= unknown ->
+ {beam, Beam};
+ _ when Source =/= unknown ->
+ {source, Source};
+ _ ->
+ false
+ end.
+
+cover_state_file() -> "/tmp/COVER.coverdata".
+
+%% @spec (CoveredModules::[atom()]) -> void()
+cover_stop([]) ->
+ ok;
+cover_stop(Mods) ->
+ lists:foreach(fun (M) -> cover:analyse_to_file(M) end, Mods),
+ cover:export(cover_state_file()), % Keep state
+ cover:stop(),
+ ok.
+
+dohalt(true, Int) ->
+ erlang:halt(Int);
+dohalt(false, _) ->
+ ok.
44 test/support/include.mk
View
@@ -1,9 +1,51 @@
ERL="/usr/local/bin/erl"
+ERLC="/usr/local/bin/erlc"
YTOP="/Users/klacke/yaws/erlyaws/trunk/yaws"
YAWS=$(YTOP)/bin/yaws
%.beam: %.erl
- "$(ERLC)" -Ddebug $<
+ "$(ERLC)" -Ddebug $<
+
+none:
+ echo "Do make clean|all|test"
+ exit 1
+
+tclean:
+ @rm -rf logs *.beam *.log yaws.conf erl_crash.dump 2> /dev/null || true
+
+
+setup:
+ @rm -rf logs 2> /dev/null
+ @mkdir logs
+ $(MAKE) start
+
+start:
+ $(YTOP)/bin/yaws -sname test --daemon --id testid --conf ./yaws.conf
+ ../support/wait_started.sh
+
+## Interactive node
+i:
+ $(YTOP)/bin/yaws -sname test -i --id testid --conf ./yaws.conf
+
+PA = -pa $(YTOP)/test/ibrowse/ebin \
+ -pa $(YTOP)/test/src \
+ -pa $(YTOP)/ebin
+
+## connect to existing yaws node
+connect:
+ $(ERL) -sname client $(PA) \
+ -s test connect `hostname`
+
+
+status:
+ $(YTOP)/bin/yaws --id testid --status
+stop:
+ $(YTOP)/bin/yaws --id testid --stop
+
+stdconf:
+ cat ../conf/stdconf.conf | \
+ ../../scripts/Subst %YTOP% $(YTOP) \
+ > yaws.conf
10 test/support/include.mk.in
View
@@ -30,12 +30,14 @@ start:
i:
$(YTOP)/bin/yaws -sname test -i --id testid --conf ./yaws.conf
+PA = -pa $(YTOP)/test/ibrowse/ebin \
+ -pa $(YTOP)/test/src \
+ -pa $(YTOP)/ebin
+
## connect to existing yaws node
connect:
- $(ERL) -sname client \
- -pa $(YTOP)/test/ibrowse/ebin \
- -pa $(YTOP)/test/src \
- -pa $(YTOP)/ebin -s test connect `hostname`
+ $(ERL) -sname client $(PA) \
+ -s test connect `hostname`
status:
19 test/t2/Makefile
View
@@ -0,0 +1,19 @@
+include ../support/include.mk
+
+all: conf setup app_test.beam
+ echo "all ok"
+
+test:
+ $(ERL) -noinput $(PA) -s tftest
+ $(MAKE) stop
+debug:
+ $(ERL) $(PA) -s tftest start nohalt
+
+conf: stdconf
+
+clean: tclean
+ -rm -rf localhost:8000
+
+
+
+
26 test/t2/app_test.erl
View
@@ -0,0 +1,26 @@
+-module(app_test).
+-include("../include/tftest.hrl").
+-include("../ibrowse/src/ibrowse.hrl").
+-compile(export_all).
+
+start() ->
+ ?line ok,
+ test1(),
+ test2(),
+ test3().
+
+
+test1() ->
+ ?line ok.
+
+test2() ->
+ ?line ok.
+
+test3() ->
+ ?line ok.
+
+
+
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.