Added $PROJECT_ROOT/src to include path.
[erlang-estap.git] / bin / estap
1 #!/usr/bin/escript
2 %%
3 %%----------------------------------------------------------------------------
4
5 main([]) -> main(["--help"]);
6 main(["-h"]) -> main(["--help"]);
7 main(["--help"]) ->
8   io:fwrite("Usage: ~s filename~n", [escript:script_name()]);
9
10 main([File]) ->
11   case find_project_root(File) of
12     {ok, Path} ->
13       IncludeDirs = [filename:join(Path, src)],
14       code:add_patha(filename:join(Path, ebin));
15     nothing ->
16       IncludeDirs = []
17   end,
18   {ok, {_Module, Forms}} = estap_file:read_file(File, IncludeDirs),
19   {ok, {Plan, Tests}} = estap_file:load_code(Forms),
20   estap_test:run(Plan, Tests),
21   ok.
22
23 %%----------------------------------------------------------------------------
24
25 -include_lib("kernel/include/file.hrl").
26
27 find_project_root(Path) ->
28   case file:read_file_info(filename:join(Path, ebin)) of
29     {ok, #file_info{type = directory}} ->
30       {ok, Path};
31     _ ->
32       case Path of
33         "." -> nothing; % don't check parent
34         "/" -> nothing; % no parent
35         _ -> find_project_root(filename:dirname(Path))
36       end
37   end.
38
39 %%----------------------------------------------------------------------------
40 %% vim:ft=erlang