diff --git a/.tool-versions b/.tool-versions index 6866748..b95ebe4 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -elixir 1.10.3-otp-21 -erlang 21.0 +elixir 1.14.0-otp-25 +erlang 25.0.3 \ No newline at end of file diff --git a/config/config.exs b/config/config.exs index a85bee8..1cbf38c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :chaps, terminal_options: [ diff --git a/lib/bless.ex b/lib/bless.ex index 5e94741..0944eb0 100644 --- a/lib/bless.ex +++ b/lib/bless.ex @@ -15,6 +15,20 @@ defmodule Bless do |> Enum.filter(&available?/1) end + @option_definitions [seed: :string] + @option_mappings [seed: [:test, :"chaps.html", :"coveralls.html"]] + def combine_args({task, subargs} = _bless_component, archargs) do + {parsed_args, _other_args, _invalid_args} = + OptionParser.parse(archargs, strict: @option_definitions) + + parsed_args + |> Enum.filter(fn {switch, _val} -> + task in Keyword.get(@option_mappings, switch) + end) + |> OptionParser.to_argv() + |> Kernel.++(subargs) + end + # chaps-ignore-start defp available?({:chaps, _args}), do: Code.ensure_loaded?(Mix.Tasks.Chaps) diff --git a/lib/mix/tasks/bless.ex b/lib/mix/tasks/bless.ex index d36ce7a..0bfa83e 100644 --- a/lib/mix/tasks/bless.ex +++ b/lib/mix/tasks/bless.ex @@ -30,14 +30,27 @@ defmodule Mix.Tasks.Bless do """ @shortdoc "Runs a testing suite" - def run(_) do + def run(archargs) do + IO.ANSI.format([ + :cyan, + :bright, + "Running bless w/ args #{inspect(archargs)}" + ]) + |> IO.puts() + Mix.Project.config() |> Keyword.get(:bless_suite, Bless.default()) - |> Enum.each(fn {task, args} -> + |> Enum.each(fn {task, _subargs} = bless_component -> + args = + bless_component + |> Bless.combine_args(archargs) + IO.ANSI.format([:cyan, "Running #{task} with args #{inspect(args)}"]) |> IO.puts() - Mix.Task.run(task |> to_string(), args) + task + |> to_string() + |> Mix.Task.run(args) end) end end diff --git a/mix.exs b/mix.exs index 291d238..758607b 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule Bless.MixProject do @version_file Path.join(__DIR__, ".version") @external_resource @version_file - @version (case Regex.run(~r/^v([\d\.]+)/, File.read!(@version_file), + @version (case Regex.run(~r/^v([\d\.\w-]+)/, File.read!(@version_file), capture: :all_but_first ) do [version] -> version @@ -52,8 +52,8 @@ defmodule Bless.MixProject do # docs {:ex_doc, ">= 0.0.0", only: :dev, runtime: false, optional: true}, # test - {:chaps, ">= 0.15.0", only: :test, optional: true}, - {:credo, ">= 0.0.0", only: :test, runtime: false, optional: true} + {:chaps, ">= 1.0.0", only: :test, optional: true}, + {:credo, ">= 1.7.0", only: :test, runtime: false, optional: true} ] end diff --git a/mix.lock b/mix.lock index 1e6673a..91da08f 100644 --- a/mix.lock +++ b/mix.lock @@ -1,12 +1,13 @@ %{ - "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, - "chaps": {:hex, :chaps, "0.15.2", "c7819ecb7fc3cec3efce00bf56bd53154e2e7863b2893051b5780dfe229d1055", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 0.3 and >= 0.3.7", [hex: :nimble_options, repo: "hexpm", optional: false]}], "hexpm", "f1111b4d5795bdca5e0374bbdbc3e806a9141b85737cbdc5ba063d6c9874de56"}, - "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"}, + "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, + "chaps": {:hex, :chaps, "1.0.1", "38ab5bff3c3d5949c43a549660b324c0423abc650e3f88917499d1fa5450bcf3", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}], "hexpm", "da5f38874e36d62d0b5b39fb13420bbf881ca883c7a08c497e34a102e53b182b"}, + "credo": {:hex, :credo, "1.7.11", "d3e805f7ddf6c9c854fd36f089649d7cf6ba74c42bc3795d587814e3c9847102", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "56826b4306843253a66e47ae45e98e7d284ee1f95d53d1612bb483f88a8cf219"}, "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, "ex_doc": {:hex, :ex_doc, "0.22.2", "03a2a58bdd2ba0d83d004507c4ee113b9c521956938298eba16e55cc4aba4a6c", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "cf60e1b3e2efe317095b6bb79651f83a2c1b3edcb4d319c421d7fcda8b3aff26"}, - "jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"}, + "file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"}, + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"}, "makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"}, - "nimble_options": {:hex, :nimble_options, "0.3.7", "1e52dd7673d36138b1a5dede183b5d86dff175dc46d104a8e98e396b85b04670", [:mix], [], "hexpm", "2086907e6665c6b6579be54ef5001928df5231f355f71ed258f80a55e9f63633"}, + "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, "nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"}, } diff --git a/test/bless_test.exs b/test/bless_test.exs index 96afb7b..c46ac44 100644 --- a/test/bless_test.exs +++ b/test/bless_test.exs @@ -7,4 +7,46 @@ defmodule BlessTest do check |> Atom.to_string() |> String.contains?("coveralls") end) end + + describe "Bless.combine_args" do + test "parent \"--seed\" argument is passed through to relevant tasks" do + assert ["--seed", _val] = + Bless.combine_args({:test, []}, [ + "--seed", + "#{Enum.random(0..5000)}" + ]) + + assert ["--seed", _val] = + Bless.combine_args({:"coveralls.html", []}, [ + "--seed", + "#{Enum.random(0..5000)}" + ]) + + assert ["--seed", _val] = + Bless.combine_args({:"chaps.html", []}, [ + "--seed", + "#{Enum.random(0..5000)}" + ]) + end + + test "parent \"--seed\" argument is not passed through to unrelated tasks" do + assert [] = + Bless.combine_args({:credo, []}, [ + "--seed", + "#{Enum.random(0..5000)}" + ]) + + assert [] = + Bless.combine_args({:"deps.unlock", []}, [ + "--seed", + "#{Enum.random(0..5000)}" + ]) + + assert [] = + Bless.combine_args({:compile, []}, [ + "--seed", + "#{Enum.random(0..5000)}" + ]) + end + end end