-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore module-level calls in
assert_call
(#409)
* Add failing tests * Adjust existing tests * Ignore module-level calls in assert_call * Add tests for dna-encoding
- Loading branch information
1 parent
f1c76d0
commit bf1d881
Showing
7 changed files
with
254 additions
and
25 deletions.
There are no files selected for viewing
Submodule elixir
updated
19 files
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
78 changes: 78 additions & 0 deletions
78
test/elixir_analyzer/exercise_test/assert_call/module_level_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,78 @@ | ||
defmodule ElixirAnalyzer.ExerciseTest.AssertCall.ModuleLevelCallTest do | ||
use ElixirAnalyzer.ExerciseTestCase, | ||
exercise_test_module: ElixirAnalyzer.Support.AnalyzerVerification.AssertCall.ModuleLevelCall | ||
|
||
test_exercise_analysis "calls in function bodies count", comments: [] do | ||
[ | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
[0, 1] | ||
|> Enum.map(&(&1 + 1)) | ||
|> List.to_tuple() | ||
|> elem(0) | ||
end | ||
end, | ||
defmodule AssertCallVerification do | ||
defp main_function() do | ||
[0, 1] | ||
|> Enum.map(&(&1 + 1)) | ||
|> List.to_tuple() | ||
|> elem(0) | ||
end | ||
end | ||
] | ||
end | ||
|
||
test_exercise_analysis "calls in macro bodies count if no calling_fn specified", | ||
comments: ["didn't find any call to List.to_tuple/1 from main_function/0"] do | ||
[ | ||
defmodule AssertCallVerification do | ||
defmacro main_function() do | ||
[0, 1] | ||
|> Enum.map(&(&1 + 1)) | ||
|> List.to_tuple() | ||
|> elem(0) | ||
end | ||
end, | ||
defmodule AssertCallVerification do | ||
defmacrop main_function() do | ||
[0, 1] | ||
|> Enum.map(&(&1 + 1)) | ||
|> List.to_tuple() | ||
|> elem(0) | ||
end | ||
end | ||
] | ||
end | ||
|
||
test_exercise_analysis "module level calls do not count", | ||
comments: [ | ||
"didn't find any call to Enum.map/2 from anywhere", | ||
"didn't find any call to List.to_tuple/1 from main_function/0" | ||
] do | ||
[ | ||
defmodule AssertCallVerification do | ||
def main_function() do | ||
1 | ||
end | ||
end, | ||
defmodule AssertCallVerification do | ||
{@one, @two} = List.to_tuple([1, 2]) | ||
|
||
def main_function() do | ||
@one | ||
end | ||
end, | ||
defmodule AssertCallVerification do | ||
{@one, @two} = | ||
[0, 1] | ||
|> Enum.map(&(&1 + 1)) | ||
|> List.to_tuple() | ||
|
||
def main_function() do | ||
@one | ||
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
21 changes: 21 additions & 0 deletions
21
test/support/analyzer_verification/assert_call/module_level_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,21 @@ | ||
defmodule ElixirAnalyzer.Support.AnalyzerVerification.AssertCall.ModuleLevelCall do | ||
@moduledoc """ | ||
This is an exercise analyzer extension module to test assert_call calling a function from | ||
outside any function/macro bodies. | ||
""" | ||
|
||
use ElixirAnalyzer.ExerciseTest | ||
|
||
assert_call "find a call to Enum.map" do | ||
type :informative | ||
called_fn module: Enum, name: :map | ||
comment "didn't find any call to Enum.map/2 from anywhere" | ||
end | ||
|
||
assert_call "find a call to List.to_tuple from main_function" do | ||
type :informative | ||
called_fn module: List, name: :to_tuple | ||
calling_fn module: AssertCallVerification, name: :main_function | ||
comment "didn't find any call to List.to_tuple/1 from main_function/0" | ||
end | ||
end |