Permalink
Browse files

add spec for original command line behaviour

  • Loading branch information...
benmmurphy authored and lucaspiller committed Dec 26, 2011
1 parent f844880 commit c70a734c006c82760e5e6c68e6c200d4f232f160
Showing with 54 additions and 35 deletions.
  1. +1 −35 bin/espec
  2. +11 −0 spec/expand_args_spec.erl
  3. +42 −0 src/espec_bin.erl
View
@@ -1,49 +1,15 @@
#!/usr/bin/env escript
%%! -smp enable -sname espec_runner -pa deps/*/ebin -pa ebin
--define(SPEC_FILE_REGEXP, ".*_spec.erl$").
main([]) ->
usage();
main(Args) ->
- SpecFiles = expand_files_from_args(Args),
- run_spec_files(SpecFiles).
+ espec_bin:run_spec_files_from_args(Args).
-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(Modules).
View
@@ -0,0 +1,11 @@
+-module(expand_args_spec).
+-include("espec.hrl").
+
+spec() ->
+ describe("processing command line arguments", fun() ->
+ it("should recursively expand a directory", fun() ->
+ Examples = espec_bin:expand_files_from_args(["examples_dir"]),
+ SortedExpectation = lists:sort(["examples_dir/level1a_spec.erl", "examples_dir/level1b_spec.erl", "examples_dir/level2/level2a_spec.erl", "examples_dir/level2/level2b_spec.erl"]),
+ SortedExpectation = lists:sort(Examples)
+ end)
+ end).
View
@@ -0,0 +1,42 @@
+-module(espec_bin).
+-export([run_spec_files_from_args/1, expand_files_from_args/1]).
+-define(SPEC_FILE_REGEXP, ".*_spec.erl$").
+
+-spec run_spec_files_from_args(list()) -> term().
+run_spec_files_from_args(Args) ->
+ SpecFiles = expand_files_from_args(Args),
+ run_spec_files(SpecFiles).
+
+-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(Modules).

0 comments on commit c70a734

Please sign in to comment.