Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename funs option to doc #31

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ The options are passed via a map:
% Default: true.
enabled => boolean(), false.

% Enable or turn off `-moduledoc` tests.
% Enable or turn off module doc tests.
% Default: true.
moduledoc => boolean(),

% Enable or turn off function tests or define a list of functions to be tested.
% Enable or turn off functions doc tests or define a list of functions to be tested.
% Default: true.
funs => boolean() | [{atom(), arity()}],
doc => boolean() | [{atom(), arity()}],

% Set the EUnit options. 'rebar3_config' tries to resolve the options defined in the rebar3.
% Default: rebar3_config.
Expand All @@ -128,7 +128,7 @@ In a module, the `-doctest` attribute is used to override the default settings v
```erlang
-doctest {moduledoc, true}.
```
- `{funs, boolean() | [{atom(), arity()}]}` or `[{atom(), arity()}]`: equivalent to funs option.
- `{doc, boolean() | [{atom(), arity()}]}` or `[{atom(), arity()}]`: equivalent to doc option.
```erlang
-doctest [print/0].
```
Expand All @@ -153,7 +153,7 @@ Options can be globally defined via a [config file](https://www.erlang.org/doc/m
[{doctest, [
{enabled, true},
{moduledoc, true},
{funs, true},
{doc, true},
{eunit_opts, rebar3_config},
{extractors, [doctest_extract_attr, doctest_extract_tag]}
]}].
Expand Down
6 changes: 3 additions & 3 deletions src/doctest.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
-type options() :: #{
enabled => boolean(),
moduledoc => boolean(),
funs => boolean() | [{atom(), arity()}],
doc => boolean() | [{atom(), arity()}],
eunit_opts => rebar3_config | [term()],
extractors => [module()]
}.
Expand Down Expand Up @@ -79,8 +79,8 @@ parse_opts(Opts) when is_map(Opts) ->
proplists:get_value(enabled, Env, true)),
moduledoc => maps:get(moduledoc, Opts,
proplists:get_value(moduledoc, Env, true)),
funs => maps:get(funs, Opts,
proplists:get_value(funs, Env, true)),
doc => maps:get(doc, Opts,
proplists:get_value(doc, Env, true)),
eunit_opts => maps:get(eunit_opts, Opts,
proplists:get_value(eunit_opts, Env, rebar3_config)),
extractors => maps:get(extractors, Opts,
Expand Down
8 changes: 4 additions & 4 deletions src/doctest_extract.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ should_test_moduledoc(#{moduledoc := false}) ->
should_test_moduledoc(Opts) when not is_map_key(moduledoc, Opts) ->
true.

should_test_doc(#{funs := true}, _Fun) ->
should_test_doc(#{doc := true}, _Fun) ->
true;
should_test_doc(#{funs := false}, _Fun) ->
should_test_doc(#{doc := false}, _Fun) ->
false;
should_test_doc(#{funs := Funs}, Fun) when is_list(Funs) ->
should_test_doc(#{doc := Funs}, Fun) when is_list(Funs) ->
lists:member(Fun, Funs);
should_test_doc(Opts, _Fun) when not is_map_key(funs, Opts) ->
should_test_doc(Opts, _Fun) when not is_map_key(doc, Opts) ->
true.

loc(Doc, Pos) ->
Expand Down
10 changes: 5 additions & 5 deletions src/doctest_transform.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ doctest_attrs(Forms) ->
parse_opts([Enabled | T], Opts) when is_boolean(Enabled) ->
parse_opts(T, Opts#{enabled => Enabled});
parse_opts([Funs | T], Opts) when is_list(Funs) ->
parse_opts(T, Opts#{funs => Funs});
parse_opts(T, Opts#{doc => Funs});
parse_opts([{enabled, Enabled} | T], Opts) when is_boolean(Enabled) ->
parse_opts(T, Opts#{enabled => Enabled});
parse_opts([{moduledoc, Enabled} | T], Opts) when is_boolean(Enabled) ->
parse_opts(T, Opts#{moduledoc => Enabled});
parse_opts([{funs, Enabled} | T], Opts) when is_boolean(Enabled) ->
parse_opts(T, Opts#{funs => Enabled});
parse_opts([{funs, Funs} | T], Opts) when is_list(Funs) ->
parse_opts(T, Opts#{funs => Funs});
parse_opts([{doc, Enabled} | T], Opts) when is_boolean(Enabled) ->
parse_opts(T, Opts#{doc => Enabled});
parse_opts([{doc, Funs} | T], Opts) when is_list(Funs) ->
parse_opts(T, Opts#{doc => Funs});
parse_opts([{eunit_opts, EunitOpts} | T], Opts) ->
parse_opts(T, Opts#{eunit_opts => EunitOpts});
parse_opts([{extractors, Extractors} | T], Opts) when is_list(Extractors) ->
Expand Down
Loading