-
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.
- Loading branch information
Showing
10 changed files
with
92 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule ExFactor.Callers do | ||
@moduledoc """ | ||
Documentation for `ExFactor.Callers`. | ||
""" | ||
|
||
alias ExFactor.Parser | ||
|
||
def all_fns(input), do: Parser.all_functions(input) | ||
|
||
@doc """ | ||
use `mix xref` list all the callers of a given module. | ||
""" | ||
# @spec callers(module()) :: list(map()) | ||
def callers(mod) do | ||
System.cmd("mix", ["xref", "callers", "#{mod}"], env: [{"MIX_ENV", "test"}]) | ||
|> elem(0) | ||
|> String.trim() | ||
|> String.split("\n") | ||
|> mangle_list() | ||
end | ||
|
||
defp mangle_list(["Compiling" <> _ | tail]), do: mangle_list(tail) | ||
|
||
defp mangle_list(list) do | ||
Enum.map(list, fn string -> | ||
[path, type] = String.split(string, " ") | ||
%{filepath: path, dependency_type: type} | ||
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
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,14 @@ | ||
defmodule ExFactor.CallersTest do | ||
use ExUnit.Case | ||
alias ExFactor.Callers | ||
|
||
describe "callers/1" do | ||
test "it should report callers of a module" do | ||
[one, _two, _three, four] = Callers.callers(ExFactor.Parser) | ||
|
||
assert one.dependency_type == "(runtime)" | ||
assert one.filepath == "lib/ex_factor/callers.ex" | ||
assert four.filepath == "test/support/support.ex" | ||
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
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
defmodule ExFactorTest do | ||
use ExUnit.Case | ||
# use ExUnit.Case | ||
|
||
describe "callers/1" do | ||
test "it should report callers of a module" do | ||
[one, _three, two] = ExFactor.callers(ExFactor.Parser) | ||
# describe "callers/1" do | ||
# test "it should report callers of a module" do | ||
# [one, _three, two] = ExFactor.callers(ExFactor.Parser) | ||
|
||
assert one.dependency_type == "(runtime)" | ||
assert one.filepath == "lib/ex_factor.ex" | ||
assert two.filepath == "test/support/support.ex" | ||
end | ||
end | ||
# assert one.dependency_type == "(runtime)" | ||
# assert one.filepath == "lib/ex_factor.ex" | ||
# assert two.filepath == "test/support/support.ex" | ||
# 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