diff --git a/CHANGELOG.md b/CHANGELOG.md index 3497cc86..ceec7870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.12.1 (2018-02-26) + +### Bugfixes (User Facing) +* Formatters that use `FileCreation.each` will no longer silently fail on file +creation and now also sanitizes `/` and other file name characters to be `_`. +Thanks @gfvcastro + ## 0.12.0 (2018-01-20) Adds the ability to save benchmarking results and load them again to compare diff --git a/lib/benchee/utility/file_creation.ex b/lib/benchee/utility/file_creation.ex index 3b743af3..006882f3 100644 --- a/lib/benchee/utility/file_creation.ex +++ b/lib/benchee/utility/file_creation.ex @@ -35,7 +35,7 @@ defmodule Benchee.Utility.FileCreation do ensure_directory_exists filename Enum.each names_to_content, fn({input_name, content}) -> input_filename = interleave(filename, input_name) - File.open input_filename, [:write, :utf8], fn(file) -> + File.open! input_filename, [:write, :utf8], fn(file) -> function.(file, content, input_filename) end end @@ -68,6 +68,9 @@ defmodule Benchee.Utility.FileCreation do iex> Benchee.Utility.FileCreation.interleave("abc.csv", "Big Input") "abc_big_input.csv" + iex> Benchee.Utility.FileCreation.interleave("abc.csv", "String.length/1") + "abc_string_length_1.csv" + iex> Benchee.Utility.FileCreation.interleave("bench/abc.csv", "Big Input") "bench/abc_big_input.csv" @@ -123,7 +126,7 @@ defmodule Benchee.Utility.FileCreation do case name_string do ^no_input -> "" _ -> - String.downcase(String.replace(name_string, " ", "_")) + String.downcase(String.replace(name_string, ~r/[^0-9A-Z]/i, "_")) end end end diff --git a/mix.exs b/mix.exs index 5394e333..ccf1b128 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Benchee.Mixfile do use Mix.Project - @version "0.12.0" + @version "0.12.1" def project do [ diff --git a/test/benchee/utility/file_creation_integration_test.exs b/test/benchee/utility/file_creation_integration_test.exs index 34cc98d4..dc34d7e5 100644 --- a/test/benchee/utility/file_creation_integration_test.exs +++ b/test/benchee/utility/file_creation_integration_test.exs @@ -24,7 +24,7 @@ defmodule Benchee.Utility.FileCreationIntegrationTest do end end - test "by default writes writes files" do + test "by default writes files" do try do capture_io fn -> each @input_to_contents, @filename end assert_correct_files() @@ -44,6 +44,16 @@ defmodule Benchee.Utility.FileCreationIntegrationTest do end end + test "with String.length/1 as a name it writes the correct file" do + to_contents = %{ + "String.length/1" => "abc" + } + capture_io fn -> each to_contents, @filename end + assert File.exists? "#{@directory}/test_string_length_1.txt" + after + File.rm_rf! @directory + end + defp assert_correct_files do assert File.exists? @file_name_1 assert File.exists? @file_name_2