-
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.
Merge pull request #9 from nicholasbair/generate-tests
WIP generate tests
- Loading branch information
Showing
4 changed files
with
48 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule ExOanda.TestGenerator do | ||
@moduledoc false | ||
|
||
use ExUnit.Case, async: true | ||
|
||
def generate_tests(configs) do | ||
Enum.each(configs, fn %{module_name: module_name, functions: functions} -> | ||
module = Module.concat([ExOandaTest, module_name, "Generated"]) | ||
|
||
test_functions = | ||
Enum.map(functions, fn function -> | ||
function_name = function.function_name | ||
target_module = Module.concat([ExOanda, module_name]) | ||
arity = length(function.arguments) + 1 # Connection struct + configured arguments (less optional params) | ||
|
||
quote do | ||
test "#{unquote(module_name)}.#{unquote(function_name)} is generated." do | ||
assert function_exported?(unquote(target_module), unquote(String.to_atom(function_name)), unquote(arity)) | ||
end | ||
|
||
test "#{unquote(module_name)}.#{unquote(function_name)}! is generated." do | ||
assert function_exported?(unquote(target_module), unquote(String.to_atom("#{function_name}!")), unquote(arity)) | ||
end | ||
end | ||
end) | ||
|
||
module_body = | ||
quote do | ||
use ExUnit.Case, async: true | ||
unquote_splicing(test_functions) | ||
end | ||
|
||
Module.create(module, module_body, __ENV__) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule ExOandaTest.GeneratedFunctions do | ||
use ExUnit.Case, async: true | ||
|
||
ExOanda.TestGenerator.generate_tests(ExOanda.Config.load_config()) | ||
end |