Skip to content

Commit

Permalink
Also scrub inputs from the configuration before formatters
Browse files Browse the repository at this point in the history
This includes a slight workaround to preserve the names of inputs
as people may be relying on those. Doesn't feel great but...
somehow reasonable?
  • Loading branch information
PragTob committed Dec 14, 2023
1 parent c43880d commit b44e2e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
15 changes: 14 additions & 1 deletion lib/benchee/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,25 @@ defmodule Benchee.Formatter do
# Hence, we scrub them away here. If you maintain a formatter plugin and rely on these please
# get in touch so we can work on a solution.
defp scrub_suite(suite) do
update_in(suite.scenarios, fn scenarios ->
suite = update_in(suite.scenarios, fn scenarios ->
Enum.map(scenarios, &scrub_scenario/1)
end)

update_in(suite.configuration, &scrub_configuration/1)
end

defp scrub_scenario(scenario) do
%Scenario{scenario | function: nil, input: nil}
end

defp scrub_configuration(configuration) do
update_in(configuration.inputs, &scrub_inputs/1)
end

defp scrub_inputs(nil), do: nil
# Feels somewhat hacky, but while people should not be relying on the input itself, they
# may be relying on the input names/order
defp scrub_inputs(inputs) do
Enum.map(inputs, fn {name, _value} -> {name, :scrubbed_see_1_3_0_changelog} end)
end
end
16 changes: 8 additions & 8 deletions test/benchee/formatter_test.exs
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
defmodule Benchee.FormatterTest do
use ExUnit.Case, async: true
alias Benchee.{Formatter, Suite, Test.FakeFormatter}
alias Benchee.{Configuration, Formatter, Suite, Test.FakeFormatter}

@no_print_assigns %{test: %{progress_printer: Benchee.Test.FakeProgressPrinter}}

describe "output/1" do
test "calls `write/1` with the output of `format/1` on each module" do
Formatter.output(%Suite{
configuration: %{formatters: [{FakeFormatter, %{}}], assigns: @no_print_assigns}
configuration: %Configuration{formatters: [{FakeFormatter, %{}}], assigns: @no_print_assigns}

Check warning on line 10 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 24.3)

Line is too long (max is 98, was 101).

Check warning on line 10 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 25.3)

Line is too long (max is 98, was 101).

Check warning on line 10 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 26.1)

Line is too long (max is 98, was 101).

Check warning on line 10 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 24.3)

Line is too long (max is 98, was 101).

Check warning on line 10 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 25.3)

Line is too long (max is 98, was 101).

Check warning on line 10 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 26.1)

Line is too long (max is 98, was 101).
})

assert_receive {:write, "output of `format/1` with %{}", %{}}
end

test "works with just modules without option tuple, defaults to empty map" do
Formatter.output(%Suite{
configuration: %{formatters: [FakeFormatter], assigns: @no_print_assigns}
configuration: %Configuration{formatters: [FakeFormatter], assigns: @no_print_assigns}
})

assert_receive {:write, "output of `format/1` with %{}", %{}}
end

test "options are passed on correctly" do
Formatter.output(%Suite{
configuration: %{formatters: [{FakeFormatter, %{a: :b}}], assigns: @no_print_assigns}
configuration: %Configuration{formatters: [{FakeFormatter, %{a: :b}}], assigns: @no_print_assigns}

Check warning on line 26 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 24.3)

Line is too long (max is 98, was 106).

Check warning on line 26 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 25.3)

Line is too long (max is 98, was 106).

Check warning on line 26 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 26.1)

Line is too long (max is 98, was 106).

Check warning on line 26 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 24.3)

Line is too long (max is 98, was 106).

Check warning on line 26 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 25.3)

Line is too long (max is 98, was 106).

Check warning on line 26 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 26.1)

Line is too long (max is 98, was 106).
})

assert_receive {:write, "output of `format/1` with %{a: :b}", %{a: :b}}
end

test "keyword list options are deep converted to maps" do
Formatter.output(%Suite{
configuration: %{formatters: [{FakeFormatter, [a: [b: :c]]}], assigns: @no_print_assigns}
configuration: %Configuration{formatters: [{FakeFormatter, [a: [b: :c]]}], assigns: @no_print_assigns}

Check warning on line 34 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 24.3)

Line is too long (max is 98, was 110).

Check warning on line 34 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 25.3)

Line is too long (max is 98, was 110).

Check warning on line 34 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 26.1)

Line is too long (max is 98, was 110).

Check warning on line 34 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 24.3)

Line is too long (max is 98, was 110).

Check warning on line 34 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 25.3)

Line is too long (max is 98, was 110).

Check warning on line 34 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 26.1)

Line is too long (max is 98, was 110).
})

assert_receive {:write, "output of `format/1` with %{a: %{b: :c}}", %{a: %{b: :c}}}
end

test "mixing functions and formatters works" do
suite = %Suite{
configuration: %{
configuration: %Configuration{
formatters: [
{FakeFormatter, %{}},
fn suite -> send(self(), {:fun, suite, "me"}) end
Expand All @@ -56,15 +56,15 @@ defmodule Benchee.FormatterTest do

test "returns the suite passed in as the first argument unchanged" do
suite = %Suite{
configuration: %{formatters: [{FakeFormatter, %{}}], assigns: @no_print_assigns}
configuration: %Configuration{formatters: [{FakeFormatter, %{}}], assigns: @no_print_assigns}

Check warning on line 59 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 24.3)

Line is too long (max is 98, was 101).

Check warning on line 59 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 25.3)

Line is too long (max is 98, was 101).

Check warning on line 59 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 26.1)

Line is too long (max is 98, was 101).

Check warning on line 59 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 24.3)

Line is too long (max is 98, was 101).

Check warning on line 59 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 25.3)

Line is too long (max is 98, was 101).

Check warning on line 59 in test/benchee/formatter_test.exs

View workflow job for this annotation

GitHub Actions / Test on Ubuntu (Elixir 1.15.7, OTP 26.1)

Line is too long (max is 98, was 101).
}

assert Formatter.output(suite) == suite
end

test "lets you know it starts formatting now" do
Formatter.output(%Suite{
configuration: %{formatters: [], assigns: @no_print_assigns}
configuration: %Configuration{formatters: [], assigns: @no_print_assigns}
})

assert_received :formatting
Expand Down

0 comments on commit b44e2e3

Please sign in to comment.