Skip to content

Commit

Permalink
mix.format my touched files
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Jan 18, 2018
1 parent 9aa0448 commit 18cc27c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
17 changes: 9 additions & 8 deletions lib/benchee/formatters/tagged_save.ex
Expand Up @@ -14,7 +14,7 @@ defmodule Benchee.Formatters.TaggedSave do
alias Benchee.Benchmark.Scenario
alias Benchee.Utility.FileCreation

@spec format(Suite.t) :: {binary, String.t}
@spec format(Suite.t()) :: {binary, String.t()}
def format(suite = %Suite{configuration: config, scenarios: scenarios}) do
formatter_config = config.formatter_options.tagged_save
tag = determine_tag(scenarios, formatter_config)
Expand All @@ -29,8 +29,8 @@ defmodule Benchee.Formatters.TaggedSave do
|> Enum.map(fn scenario -> scenario.tag end)
|> Enum.uniq()
|> Enum.filter(fn tag ->
tag != nil && tag =~ ~r/#{Regex.escape(desired_tag)}/
end)
tag != nil && tag =~ ~r/#{Regex.escape(desired_tag)}/
end)
|> choose_tag(desired_tag)
end

Expand All @@ -49,20 +49,21 @@ defmodule Benchee.Formatters.TaggedSave do
tags
|> Enum.map(fn tag -> String.replace(tag, desired_tag <> "-", "") end)
|> Enum.map(&String.to_integer/1)
|> Enum.max
|> Enum.max()
end

defp tag_scenarios(scenarios, tag) do
Enum.map scenarios, fn(scenario) ->
Enum.map(scenarios, fn scenario ->
scenario
|> tagged_scenario(tag)
|> update_name
end
end)
end

defp tagged_scenario(scenario = %Scenario{tag: nil}, desired_tag) do
%Scenario{scenario | tag: desired_tag}
end

defp tagged_scenario(scenario, _desired_tag) do
scenario
end
Expand All @@ -71,12 +72,12 @@ defmodule Benchee.Formatters.TaggedSave do
%Scenario{scenario | name: Scenario.display_name(scenario)}
end

@spec write({binary, String.t}) :: :ok
@spec write({binary, String.t()}) :: :ok
def write({term_binary, filename}) do
FileCreation.ensure_directory_exists(filename)
return_value = File.write(filename, term_binary)

IO.puts "Suite saved in external term format at #{filename}"
IO.puts("Suite saved in external term format at #{filename}")

return_value
end
Expand Down
52 changes: 26 additions & 26 deletions test/benchee/formatters/tagged_save_test.exs
Expand Up @@ -31,12 +31,12 @@ defmodule Benchee.Formatters.TaggedSaveTest do
input_name: no_input(),
input: no_input(),
run_time_statistics: %Statistics{
average: 100.0,
ips: 10_000.0,
std_dev_ratio: 0.1,
median: 90.0,
percentiles: %{99 => 300.1}
}
average: 100.0,
ips: 10_000.0,
std_dev_ratio: 0.1,
median: 90.0,
percentiles: %{99 => 300.1}
}
}
],
configuration: %Benchee.Configuration{
Expand All @@ -53,9 +53,10 @@ defmodule Benchee.Formatters.TaggedSaveTest do
test "able to restore the original just fine" do
{binary, path} = format(@suite)

loaded_suite = binary
|> :erlang.binary_to_term
|> suite_without_scenario_tags
loaded_suite =
binary
|> :erlang.binary_to_term()
|> suite_without_scenario_tags

assert loaded_suite == @suite
assert path == @filename
Expand All @@ -66,10 +67,10 @@ defmodule Benchee.Formatters.TaggedSaveTest do

loaded_suite = :erlang.binary_to_term(binary)

Enum.each loaded_suite.scenarios, fn(scenario) ->
Enum.each(loaded_suite.scenarios, fn scenario ->
assert scenario.tag == @benchee_tag
assert scenario.name =~ ~r/#{@benchee_tag}/
end
end)
end

test "doesn't tag scenarios that already have a tag" do
Expand Down Expand Up @@ -108,12 +109,10 @@ defmodule Benchee.Formatters.TaggedSaveTest do
tags = sorted_tags(scenarios)
names = sorted_names(scenarios)

assert tags ==
[@benchee_tag <> "-2", @benchee_tag <> "-3", @benchee_tag <> "-4"]
assert tags == [@benchee_tag <> "-2", @benchee_tag <> "-3", @benchee_tag <> "-4"]

assert names ==
["foo (#{@benchee_tag}-2)",
"foo (#{@benchee_tag}-3)",
"foo (#{@benchee_tag}-4)"]
["foo (#{@benchee_tag}-2)", "foo (#{@benchee_tag}-3)", "foo (#{@benchee_tag}-4)"]
end

defp scenarios_from_formatted(suite) do
Expand All @@ -124,28 +123,29 @@ defmodule Benchee.Formatters.TaggedSaveTest do

defp sorted_tags(scenarios) do
scenarios
|> Enum.map(fn(scenario) -> scenario.tag end)
|> Enum.uniq
|> Enum.sort
|> Enum.map(fn scenario -> scenario.tag end)
|> Enum.uniq()
|> Enum.sort()
end

defp sorted_names(scenarios) do
scenarios
|> Enum.map(fn(scenario) -> scenario.name end)
|> Enum.uniq
|> Enum.sort
|> Enum.map(fn scenario -> scenario.name end)
|> Enum.uniq()
|> Enum.sort()
end
end

describe ".output/1" do
test "able to restore fully from file" do
capture_io fn -> output(@suite) end
capture_io(fn -> output(@suite) end)

etf_data = File.read!(@filename)

loaded_suite = etf_data
|> :erlang.binary_to_term
|> suite_without_scenario_tags
loaded_suite =
etf_data
|> :erlang.binary_to_term()
|> suite_without_scenario_tags

assert loaded_suite == @suite
after
Expand Down

0 comments on commit 18cc27c

Please sign in to comment.