-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
284 additions
and
39 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
144 changes: 144 additions & 0 deletions
144
test/elixir_analyzer/exercise_test/assert_call/indirect_call_test.exs
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,144 @@ | ||
defmodule ElixirAnalyzer.ExerciseTest.AssertCall.IndirectCallTest do | ||
use ElixirAnalyzer.ExerciseTestCase, | ||
exercise_test_module: ElixirAnalyzer.Support.AnalyzerVerification.AssertCall.IndirectCall | ||
|
||
test_exercise_analysis "Calling functions from main_function/0", | ||
comments_exclude: [ | ||
"didn't find any call to Elixir.Mix.Utils.read_path/1 from main_function/0", | ||
"didn't find any call to :math.pi from main_function/0", | ||
"didn't find any call to final_function/1 from main_function/0" | ||
] do | ||
[ | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
file = Elixir.Mix.Utils.read_path("") | ||
do_something(file) | ||
final_function(:math.pi()) | ||
end | ||
end, | ||
# via helper | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
helper("") | ||
|> do_something() | ||
end | ||
|
||
def helper(path) do | ||
Elixir.Mix.Utils.read_path(path) | ||
final_function(:math.pi()) | ||
end | ||
end, | ||
# via two helpers | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
helper("") | ||
|> do_something() | ||
end | ||
|
||
def helper(path) do | ||
helper_2(path) | ||
end | ||
|
||
def helper_2(path) do | ||
Elixir.Mix.Utils.read_path(path) | ||
|
||
:math.pi() | ||
|> final_function | ||
end | ||
end, | ||
# via three helpers | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
helper("") | ||
|> do_something() | ||
end | ||
|
||
def helper(path) do | ||
helper_2(path) | ||
end | ||
|
||
def helper_2(path) do | ||
helper_3(path) | ||
end | ||
|
||
def helper_3(path) do | ||
Elixir.Mix.Utils.read_path(path) | ||
final_function(:math.pi()) | ||
end | ||
end, | ||
# Full path for the helper function | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
AssertCallVerification.helper("") | ||
|> do_something() | ||
end | ||
|
||
def helper(path) do | ||
Elixir.Mix.Utils.read_path(path) | ||
final_function(:math.pi()) | ||
end | ||
end, | ||
# __MODULE__ for the helper function | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
__MODULE__.helper("") | ||
|> do_something() | ||
end | ||
|
||
def helper(path) do | ||
Elixir.Mix.Utils.read_path(path) | ||
final_function(:math.pi()) | ||
end | ||
end | ||
] | ||
end | ||
|
||
test_exercise_analysis "Not calling functions from main_function/0", | ||
comments_include: [ | ||
"didn't find any call to Elixir.Mix.Utils.read_path/1 from main_function/0", | ||
"didn't find any call to :math.pi from main_function/0", | ||
"didn't find any call to final_function/1 from main_function/0" | ||
] do | ||
[ | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
end | ||
end, | ||
# recursion is safe | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
:ok | ||
|> main_function() | ||
|> main_function() | ||
|> do_something() | ||
end | ||
end, | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
end | ||
|
||
def unrelated_function() do | ||
Elixir.Mix.Utils.read_path(path) | ||
final_function(:math.pi()) | ||
end | ||
end, | ||
defmodule AssertCallVerification do | ||
# Internal modules don't fool assert_call | ||
defmodule UnrelateInternaldModule do | ||
def main_function() do | ||
helper("") | ||
|> do_something() | ||
end | ||
|
||
def helper(path) do | ||
Elixir.Mix.Utils.read_path(path) | ||
final_function(:math.pi()) | ||
end | ||
end | ||
|
||
def main_function() do | ||
end | ||
end | ||
] | ||
end | ||
end |
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
29 changes: 29 additions & 0 deletions
29
test/support/analyzer_verification/assert_call/indirect_call.ex
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,29 @@ | ||
defmodule ElixirAnalyzer.Support.AnalyzerVerification.AssertCall.IndirectCall do | ||
@moduledoc """ | ||
This is an exercise analyzer extension module to test assert_call calling a function from | ||
a calling function via helper functions | ||
""" | ||
|
||
use ElixirAnalyzer.ExerciseTest | ||
|
||
assert_call "find a call to Elixir.Mix.Utils.read_path/1 from main_function/0" do | ||
type :informational | ||
called_fn module: Elixir.Mix.Utils, name: :read_path | ||
calling_fn module: AssertCallVerification, name: :main_function | ||
comment "didn't find any call to Elixir.Mix.Utils.read_path/1 from main_function/0" | ||
end | ||
|
||
assert_call "find a call to :math.pi from main_function/0" do | ||
type :informational | ||
called_fn module: :math, name: :pi | ||
calling_fn module: AssertCallVerification, name: :main_function | ||
comment "didn't find any call to :math.pi from main_function/0" | ||
end | ||
|
||
assert_call "find a call to final_function/1 from main_function/0" do | ||
type :informational | ||
called_fn name: :final_function | ||
calling_fn module: AssertCallVerification, name: :main_function | ||
comment "didn't find any call to final_function/1 from main_function/0" | ||
end | ||
end |