Skip to content
This repository has been archived by the owner on May 27, 2019. It is now read-only.

Commit

Permalink
Add enscript runner (TODO create a binary like rebar does)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspiller committed Dec 25, 2011
1 parent c32a10e commit c10aef7
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bin/espec
@@ -0,0 +1,49 @@
#!/usr/bin/env escript
%%! -smp enable -sname espec_runner -pa deps/*/ebin -pa ebin

-define(SPEC_FILE_REGEXP, ".*_espec.erl$").

main([]) ->
usage();
main(Args) ->
SpecFiles = expand_files_from_args(Args),
run_spec_files(SpecFiles).

-spec usage() -> term().
usage() ->
io:format("Usage: espec [files or directories]\n"),
halt(1).

-spec expand_files_from_args(list()) -> list().
expand_files_from_args(FilesOrDirs) ->
lists:append(lists:map(fun(FileOrDir) ->
case filelib:is_dir(FileOrDir) of
true ->
filelib:fold_files(FileOrDir, ?SPEC_FILE_REGEXP, true, fun(File, Acc) ->
[File | Acc]
end, []);
false ->
[FileOrDir]
end
end, FilesOrDirs)).

-spec run_spec_files(list()) -> term().
run_spec_files(SpecFiles) ->
CompileOptions = [
binary,
{i, "ebin"},
{i, "include"},
report,
warnings_as_errors
],
Modules = lists:foldl(fun(SpecFile, Acc) ->
case compile:file(SpecFile, CompileOptions) of
{ok, Module, Binary} ->
{module, Module} = code:load_binary(Module, SpecFile, Binary),
[Module | Acc];
error ->
% errors and warnings are automatically printed to stdout
Acc
end
end, [], SpecFiles),
espec:run_no_shell(Modules).

0 comments on commit c10aef7

Please sign in to comment.