Skip to content

Commit

Permalink
Merge pull request #20 from williamthome/feat/improve-format-error
Browse files Browse the repository at this point in the history
Provide a better format error info
  • Loading branch information
williamthome authored May 23, 2024
2 parents 5a4289b + 89448a8 commit eabbcac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/doctest_eunit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ moduledoc_tests(Mod, AttrLn, CodeBlocks) ->
) of
{ok, Tests} ->
Tests;
{error, Reason} ->
error({doctest, {moduledoc, Reason}}, [
Mod, AttrLn, CodeBlocks
])
{error, {format, Info}} ->
error({doctest, {moduledoc_format, Info#{
module => Mod
}}}, [Mod, AttrLn, CodeBlocks])
end.

doc_tests({M, F, A}, AttrLn, CodeBlocks) ->
Expand Down Expand Up @@ -101,10 +101,12 @@ doc_tests({M, F, A}, AttrLn, CodeBlocks) ->
) of
{ok, Tests} ->
Tests;
{error, Reason} ->
error({doctest, {doc, Reason}}, [
{M, F, A}, AttrLn, CodeBlocks
])
{error, {format, Info}} ->
error({doctest, {doc_format, Info#{
module => M,
function => F,
arity => A
}}}, [{M, F, A}, AttrLn, CodeBlocks])
end.

test_title(Mod, Ln) ->
Expand Down
2 changes: 2 additions & 0 deletions src/doctest_eunit_report.erl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ print_output(#{output := Out}) ->
])
end.

format_error({error, {doctest, Error}, Stack}, _Test) ->
erlang:raise(error, {doctest, Error}, Stack);
format_error({error, {assertEqual, Info}, Stack}, Test) ->
case proplists:lookup(doctest, Info) of
{doctest, DocTest} ->
Expand Down
6 changes: 0 additions & 6 deletions src/doctest_md.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ chunks(Parts) ->
end
end, Parts).

% TODO: Maybe check for the correct line sequence by starting from 1, e.g.:
% 1> ok.
% 2> ok.
% And this should be wrong:
% 9> error.
% 8> error.
asserts([{left, {N, L}}, {more, {Ws, M}} | T], HI, {Ln, NLn}, Acc) ->
case check_more_format(Ws, N) of
ok ->
Expand Down

0 comments on commit eabbcac

Please sign in to comment.