-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compile time errors reporting (#3)
Co-authored-by: Sergei Shuvatov <[email protected]>
- Loading branch information
Showing
7 changed files
with
206 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
-module(compile_time_errors_SUITE). | ||
|
||
-include_lib("stdlib/include/assert.hrl"). | ||
|
||
-behaviour(ct_suite). | ||
-export([ | ||
all/0 | ||
]). | ||
|
||
%% Tests | ||
-export([ | ||
norecord/1, | ||
format_error/1, | ||
success/1 | ||
]). | ||
|
||
%% ct_suite callbacks | ||
|
||
all() -> | ||
[ | ||
norecord, | ||
format_error, | ||
success | ||
]. | ||
|
||
%% Tests | ||
|
||
norecord(Config) -> | ||
DataDir = proplists:get_value(data_dir, Config), | ||
File = filename:join(DataDir, "norecord"), | ||
?assertEqual( | ||
{ | ||
error, | ||
[ | ||
{File ++ ".erl", [ | ||
{{15, 23}, rconv, {record_not_found, norecord}}, | ||
{{18, 5}, rconv, bad_record_name}, | ||
{{22, 29}, rconv, {record_not_found, another_absent_record}}, | ||
{{25, 25}, rconv, {record_not_found, norecord}} | ||
]} | ||
], | ||
[] | ||
}, | ||
compile:file(File, [return]) | ||
). | ||
|
||
format_error(_Config) -> | ||
?assertEqual( | ||
"record 'norecord' not found", | ||
lists:flatten(rconv:format_error({record_not_found, norecord})) | ||
), | ||
?assertEqual( | ||
"record name argument should be an atom", | ||
lists:flatten(rconv:format_error(bad_record_name)) | ||
). | ||
|
||
success(Config) -> | ||
DataDir = proplists:get_value(data_dir, Config), | ||
File = filename:join(DataDir, "success"), | ||
?assertEqual( | ||
{ok, success, []}, | ||
compile:file(File, [return]) | ||
). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
%%% This module must not compile and parse transform should emit errors at compile time | ||
|
||
-module(norecord). | ||
|
||
-compile([{parse_transform, rconv}]). | ||
|
||
-export([ | ||
to_map/1, | ||
to_map_bad_arg/1, | ||
to_clean_map/1, | ||
from_map/1 | ||
]). | ||
|
||
to_map(Rec) -> | ||
rconv:to_map(Rec, norecord). | ||
|
||
to_map_bad_arg(Rec) -> | ||
rconv:to_map(Rec, []). | ||
|
||
to_clean_map(Rec) -> | ||
Filter = fun(V) -> V /= undefined end, | ||
rconv:to_clean_map(Rec, another_absent_record, Filter). | ||
|
||
from_map(Map) -> | ||
rconv:from_map(Map, norecord). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-module(success). | ||
|
||
-compile([{parse_transform, rconv}]). | ||
|
||
-export([ | ||
to_map/1, | ||
to_clean_map/1, | ||
empty_to_clean_map/1, | ||
from_map/1 | ||
]). | ||
|
||
-record(success, { | ||
a :: term(), | ||
b = false, | ||
c | ||
}). | ||
|
||
-record(empty, {}). | ||
|
||
to_map(R) -> | ||
rconv:to_map(R, success). | ||
|
||
to_clean_map(R) -> | ||
Filter = fun(V) -> V /= undefined end, | ||
rconv:to_clean_map(R, success, Filter). | ||
|
||
empty_to_clean_map(#empty{} = _E) -> | ||
% just a strange corner case, not an example | ||
rconv:to_clean_map(_E, empty, fun(_) -> true end). | ||
|
||
from_map(M) -> | ||
rconv:from_map(M, success). |