-
Notifications
You must be signed in to change notification settings - Fork 417
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
Add erlang-module support #2094
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1300,6 +1300,53 @@ | |
assert_receive {:runtime_evaluation_response, :code_1, terminal_text("6"), metadata()} | ||
end | ||
|
||
test "evaluate erlang-module code", %{evaluator: evaluator} do | ||
Evaluator.evaluate_code( | ||
evaluator, | ||
:erlang, | ||
"-module(tryme). -export([go/0]). go() ->{ok,went}.", | ||
:code_4, | ||
[] | ||
) | ||
|
||
assert_receive {:runtime_evaluation_response, :code_4, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fnchooft Again, I'm not very faimiliar with the test logic in Elixir, but I noticed that for most tests it actually returns a map, not a tuple. i changed this lines to assert_receive {:runtime_evaluation_response, :code_4,
terminal_text("\"erlang module successfully compiled\""), metadata()} |
||
{:text, "\"erlang module successfully compiled\""}, metadata()} | ||
end | ||
|
||
test "evaluate erlang-module error function already defined", %{evaluator: evaluator} do | ||
Evaluator.evaluate_code( | ||
evaluator, | ||
:erlang, | ||
"-module(tryme). -export([go/0]). go() ->{ok,went}. go() ->{ok,went}.", | ||
:code_4, | ||
[] | ||
) | ||
|
||
assert_receive {:runtime_evaluation_output, :code_4, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert_receive {:runtime_evaluation_output, :code_4,
terminal_text(":1:52: function go/0 already defined\n", true)} |
||
{:stdout, ":1:52: function go/0 already defined\n"}} | ||
end | ||
|
||
test "evaluate erlang-module error - expression after module", %{evaluator: evaluator} do | ||
Evaluator.evaluate_code( | ||
evaluator, | ||
:erlang, | ||
"-module(tryme). -export([go/0]). go() ->{ok,went}. go() ->{ok,went}. A = 1.", | ||
:code_4, | ||
[] | ||
) | ||
|
||
assert_receive { | ||
:runtime_evaluation_response, | ||
:code_4, | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert_receive {
:runtime_evaluation_response,
:code_4,
error(_),
%{code_markers: _List}
} |
||
:error, | ||
_ErrorText, | ||
:other | ||
}, | ||
%{code_markers: _List} | ||
} | ||
end | ||
|
||
test "mixed erlang/elixir bindings", %{evaluator: evaluator} do | ||
Evaluator.evaluate_code(evaluator, :elixir, "x = 1", :code_1, []) | ||
Evaluator.evaluate_code(evaluator, :erlang, "Y = X.", :code_2, [:code_1]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of detecting based on a string, we can do the first pass with
:erl_scan.string(String.to_charlist(str))
and then traverse all entries and see if any defines a module attribute.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your opinion: Analyze the forms to only allow one module? Throw an error to instruct the user?
Seems more inline with how Erlang defines modules.
If you defined multiple modules we would have to have a lot more checks, and we would have to seperate the statements per module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for now, I think the best is to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For visibility @josevalim @fnchooft Did a PR for this here!
fnchooft#1