From be1f13a627bf8fa161062302fbfa5ee8358f147d Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Thu, 14 Dec 2023 16:28:36 +0100 Subject: [PATCH] Also scrub inputs from the configuration before formatters 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? --- lib/benchee/formatter.ex | 20 +++++++++++++++++--- test/benchee/formatter_test.exs | 28 ++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/benchee/formatter.ex b/lib/benchee/formatter.ex index 1dec038c..33c3fea2 100644 --- a/lib/benchee/formatter.ex +++ b/lib/benchee/formatter.ex @@ -172,12 +172,26 @@ 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 -> - Enum.map(scenarios, &scrub_scenario/1) - end) + 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 diff --git a/test/benchee/formatter_test.exs b/test/benchee/formatter_test.exs index 17216968..f874e723 100644 --- a/test/benchee/formatter_test.exs +++ b/test/benchee/formatter_test.exs @@ -1,13 +1,16 @@ 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 + } }) assert_receive {:write, "output of `format/1` with %{}", %{}} @@ -15,7 +18,7 @@ defmodule Benchee.FormatterTest do 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 %{}", %{}} @@ -23,7 +26,10 @@ defmodule Benchee.FormatterTest do 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 + } }) assert_receive {:write, "output of `format/1` with %{a: :b}", %{a: :b}} @@ -31,7 +37,10 @@ defmodule Benchee.FormatterTest do 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 + } }) assert_receive {:write, "output of `format/1` with %{a: %{b: :c}}", %{a: %{b: :c}}} @@ -39,7 +48,7 @@ defmodule Benchee.FormatterTest do test "mixing functions and formatters works" do suite = %Suite{ - configuration: %{ + configuration: %Configuration{ formatters: [ {FakeFormatter, %{}}, fn suite -> send(self(), {:fun, suite, "me"}) end @@ -56,7 +65,10 @@ 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 + } } assert Formatter.output(suite) == suite @@ -64,7 +76,7 @@ defmodule Benchee.FormatterTest do 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