Permalink
Browse files

Added browser 'auto' setting to open html reports

  • Loading branch information...
1 parent ed2d989 commit 559e522375521c7dbdb240978acf11a5e3e32743 @komone committed Feb 18, 2009
Showing with 26 additions and 5 deletions.
  1. +3 −2 ebin/utest.app
  2. +23 −3 src/utest.erl
View
5 ebin/utest.app
@@ -12,10 +12,11 @@
% {mod, {utest_app, []}}, when converting to OTP
{env, [
{verbosity, normal}, % terse | normal | verbose
- {report, html}, % none | console | raw | text | xml | html
+ {report, html}, % none | console | raw | text | xml | html
{target, [localhost]}, % later add 'remote' for continuous integration
{test_dir, "utest"}, % the name for the default test directory
- {file_ext, ".test"} % test file extension, must start with .
+ {file_ext, ".test"}, % test file extension, must start with .
+ {browser, auto} % auto | off (automatically open browser if html)
]},
{applications, [kernel, stdlib]}
]}.
View
26 src/utest.erl
@@ -59,17 +59,35 @@ run(App) when is_atom(App) ->
{ok, Results, {Total, Pass, Fail, Skip}} = run_tests(Test#suite.path,
Records, Test#suite.tests, [], {0, 0, 0, 0}),
utest_suite:teardown(Test),
- utest_report:format(Test#suite{results=Results},
+ F = utest_report:format(Test#suite{results=Results},
get_config(report),
get_config(test_dir)),
+
+ case get_config(browser) == auto andalso get_config(report) == html of
+ true ->
+ case F of
+ {ok, File} -> start_browser(os:type(), File);
+ _ -> ok
+ end;
+ _ -> ok
+ end,
case get_config(verbosity) of
terse ->
{App, [{tests, Total}, {pass, Pass}, {fail, Fail}, {skip, Skip}]};
_ ->
print(normal, "RESULT [~p] Total ~p, Pass ~p, Fail ~p, Skipped ~p~n",
- [App, Total, Pass, Fail, Skip])
+ [App, Total, Pass, Fail, Skip]),
+ F
end.
-
+
+%% BROWSER[LINUX] os:cmd("exec firefox /../test.html").
+%% BROWSER[WIN] os:cmd("start /../test.html").
+%% BROWSER[WIN] os:cmd("rundll32 url.dll,FileProtocolHandler /../test.html").
+start_browser({unix, _}, File) -> start_browser(unix, File);
+start_browser(unix, File) -> os:cmd("exec firefox " ++ File);
+start_browser({win32, _}, File) -> start_browser(win32, File);
+start_browser(win32, File) -> os:cmd("start " ++ File);
+start_browser(_, _) -> {error, no_browser}.
%%
%% Internal API
@@ -182,6 +200,8 @@ set_config(Key, Value) ->
Valid = is_list(Value);
file_ext when is_list(Value) ->
Valid = lists:nth(1, Value) == $.;
+ browser ->
+ Valid = lists:member(Value, [no, off, auto]);
_->
Valid = false
end,

0 comments on commit 559e522

Please sign in to comment.