Skip to content

Commit

Permalink
[Closes #2] Fixed sentence in README. Removed commented line. Moved a…
Browse files Browse the repository at this point in the history
…uxiliary test functions to a test module. Replaced not_found for {error, enoent}.
  • Loading branch information
jfacorro committed Jun 26, 2014
1 parent ff12d4e commit a9c0961
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ elvis:rock(Config).
%%= ok
```

`Config` which should have a valid format. Since this is a project under development what is a valid format is still a
`Config` should have a valid format, since this is a project under development the definition for *valid format* is still a
work in progress.

## Configuration
Expand Down
1 change: 0 additions & 1 deletion src/elvis_result.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ print([Result | Results]) ->
print(Results);

print(#file_result{path = Path, rules = Rules}) ->
%% ct:pal("~p", [Rules]),
Status = case file_status(Rules) of
ok -> "OK";
fail -> "FAIL"
Expand Down
16 changes: 2 additions & 14 deletions src/elvis_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-export([
src/2,
find_files/2,
find_file/2,
rules/1,
source_dirs/1,
validate_config/1,
Expand All @@ -18,12 +17,9 @@

%% @doc Returns the source for the file.
-spec src(elvis:config(), file:filename()) ->
{ok, binary()} | not_found.
{ok, binary()} | {error, enoent}.
src(_Config, FilePath) ->
case file:read_file(FilePath) of
{error, enoent} -> not_found;
Result -> Result
end.
file:read_file(FilePath).

%% @doc Returns all files under the specified Path
%% that match the pattern Name.
Expand All @@ -34,14 +30,6 @@ find_files(Dirs, Pattern) ->
end,
lists:flatmap(Fun, Dirs).

-spec find_file([string()], string()) ->
{ok, string()} | not_found.
find_file(Dirs, Pattern) ->
case find_files(Dirs, Pattern) of
[] -> not_found;
[Path | _] -> {ok, Path}
end.

%% @doc Reads the rules to apply specified in the
%% configuration and returns them.
-spec rules(elvis:config()) -> [rule()].
Expand Down
10 changes: 5 additions & 5 deletions test/elvis_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ check_configuration(_Config) ->
find_file_and_check_src(_Config) ->
Dirs = ["../../test/examples"],

not_found = elvis_utils:find_file(Dirs, "doesnt_exist.erl"),
{ok, Path} = elvis_utils:find_file(Dirs, "small.erl"),
[] = elvis_utils:find_files(Dirs, "doesnt_exist.erl"),
[Path] = elvis_utils:find_files(Dirs, "small.erl"),

{ok, <<"-module(small).\n">>} = elvis_utils:src([], Path),
not_found = elvis_utils:src([], "doesnt_exist.erl").
{error, enoent} = elvis_utils:src([], "doesnt_exist.erl").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Rules
Expand All @@ -103,7 +103,7 @@ verify_line_length_rule(_Config) ->
SrcDirs = elvis_utils:source_dirs(ElvisConfig),

File = "fail_line_length.erl",
{ok, Path} = elvis_utils:find_file(SrcDirs, File),
{ok, Path} = elvis_test_utils:find_file(SrcDirs, File),

Results = elvis_style:line_length(ElvisConfig, Path, [80]),
ok = case length(Results) of
Expand All @@ -117,7 +117,7 @@ verify_no_tabs_rule(_Config) ->
SrcDirs = elvis_utils:source_dirs(ElvisConfig),

File = "fail_no_tabs.erl",
{ok, Path} = elvis_utils:find_file(SrcDirs, File),
{ok, Path} = elvis_test_utils:find_file(SrcDirs, File),

Results = elvis_style:no_tabs(ElvisConfig, Path, []),
ok = case length(Results) of
Expand Down
15 changes: 15 additions & 0 deletions test/elvis_test_utils.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-module(elvis_test_utils).

-export([
find_file/2
]).

-spec find_file([string()], string()) ->
{ok, string()} | {error, enoent}.
find_file(Dirs, Pattern) ->
case elvis_utils:find_files(Dirs, Pattern) of
[] -> {error, enoent};
[Path | _] -> {ok, Path}
end.


0 comments on commit a9c0961

Please sign in to comment.