Skip to content
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

Update formatter to handle older Elixir versions #27

Merged

Conversation

smpoulsen
Copy link
Contributor

18e7b99 updated the formatter to handle ExUnit's tests_counter change
from an integer to a map in
elixir-lang/elixir@c4d6be6#diff-0ed5c47cc55f463c3af34af96d1fef62L18
in a way that wasn't backwards compatible with older Elixir versions.

This updates the formatter to handle older Elixir versions by checking
whether tests_counter is a map and updating it accordingly.

18e7b99 updated the formatter to handle ExUnit's `tests_counter` change
from an integer to a map in
elixir-lang/elixir@c4d6be6#diff-0ed5c47cc55f463c3af34af96d1fef62L18
in a way that wasn't backwards compatible with older Elixir versions.

This updates the formatter to handle older Elixir versions by checking
whether `tests_counter` is a map and updating it accordingly.
@coveralls
Copy link

coveralls commented Jul 4, 2016

Coverage Status

Coverage increased (+0.9%) to 73.864% when pulling 3ccec28 on tpoulsen:handle-old-elixir-versions-in-formatter into 5370647 on parroty:master.

@@ -13,8 +13,13 @@ defmodule ExCheck.Formatter do

@doc false
def handle_event(event = {:suite_finished, _run_us, _load_us}, config) do
updated_test_count = config.tests_counter.test + ExCheck.IOServer.total_tests
new_cfg = %{config | tests_counter: %{test: updated_test_count}}
updated_test_count =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this would be more idiomatic:

# in handle_event
updated_tests_counter = update_tests_counter(config.tests_counter, ExCheck.IOServer.total_tests)

# then, below:
defp update_tests_counter(count, increment) when is_integer(count) do
  count + increment
end
defp update_tests_counter(counter, increment) when is_map(counter) do
  %{counter | test: counter.test + increment}
end

Ideally you'd find out if tests_counter is a struct and pattern match on that struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that approach; it's cleaner and more extensible.

@coveralls
Copy link

coveralls commented Jul 4, 2016

Coverage Status

Coverage increased (+0.6%) to 73.563% when pulling 03eabc4 on tpoulsen:handle-old-elixir-versions-in-formatter into 5370647 on parroty:master.

@parroty parroty merged commit 8daef93 into parroty:master Jul 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants