yak(mutation-testing-with-muex-blogex-pure-app-code-1341): mutation testing with muex (blogex + pure app code)
This commit is contained in:
+65
-2
@@ -48,7 +48,8 @@ defmodule Blogex.MixProject do
|
||||
{:plug, "~> 1.15"},
|
||||
{:ex_doc, "~> 0.34", only: :dev, runtime: false},
|
||||
{:rustler, "~> 0.38.0", optional: true},
|
||||
{:ex_crap, "~> 0.1.1", only: [:dev, :test], runtime: false}
|
||||
{:ex_crap, "~> 0.1.1", only: [:dev, :test], runtime: false},
|
||||
{:muex, "~> 0.12", only: [:dev, :test], runtime: false}
|
||||
]
|
||||
end
|
||||
|
||||
@@ -91,12 +92,74 @@ defmodule Blogex.MixProject do
|
||||
# Same `precommit` alias name and shape as app/mix.exs, so both apps share
|
||||
# one loop: compile (warnings fatal), format, test. Heavy sensors belong in
|
||||
# the Lens pass (`make verify`), not here.
|
||||
#
|
||||
# `mutate` / `mutate.fast` are a sensor, not a gate: they are deliberately
|
||||
# absent from Makefile's VERIFY_SENSORS and always pass `--fail-at 0`, so a
|
||||
# survivor is reported rather than fatal. The scope lives in the plain-text
|
||||
# files beside this one; the aliases read them at run time, so the text file
|
||||
# stays the single source of truth.
|
||||
defp aliases do
|
||||
[
|
||||
precommit: ["compile --warning-as-errors", "format", "test"]
|
||||
precommit: ["compile --warning-as-errors", "format", "test"],
|
||||
mutate: &mutate/1,
|
||||
"mutate.fast": &mutate_fast/1
|
||||
]
|
||||
end
|
||||
|
||||
# No macro/`use` mutators: the scoped modules are plain functions, and the
|
||||
# macro-heavy modules (blog.ex, router.ex, components.ex, layout.ex) are out
|
||||
# of scope entirely. Spellings are muex 0.12's CLI names.
|
||||
@mutation_mutators "arithmetic,boolean,comparison,conditional,function_call,literal,return_value"
|
||||
|
||||
defp mutate(args), do: run_mutation("mutation_scope.txt", args)
|
||||
|
||||
defp mutate_fast(args), do: run_mutation("mutation_scope_fast.txt", args)
|
||||
|
||||
defp run_mutation(scope_file, args) do
|
||||
Mix.Task.run("muex", mutation_args(scope_file, args))
|
||||
end
|
||||
|
||||
@doc false
|
||||
def mutation_args(scope_file, extra_args \\ []) do
|
||||
files = read_mutation_scope(scope_file)
|
||||
|
||||
# `--fail-at 0` comes first so an ad-hoc override cannot turn the sensor
|
||||
# into a gate. Extra args come before our defaults, and OptionParser keeps
|
||||
# the first value, so `mix mutate --files lib/blogex/seo.ex` targets one
|
||||
# file while `mix mutate` covers the whole scope file.
|
||||
["--fail-at", "0"] ++
|
||||
extra_args ++
|
||||
["--files", Enum.join(files, ","), "--mutators", @mutation_mutators]
|
||||
end
|
||||
|
||||
@doc false
|
||||
def read_mutation_scope(scope_file) do
|
||||
path = Path.expand(scope_file, Path.dirname(Mix.Project.project_file()))
|
||||
|
||||
files =
|
||||
case File.read(path) do
|
||||
{:ok, contents} ->
|
||||
contents
|
||||
|> String.split("\n", trim: true)
|
||||
|> Enum.map(&String.trim/1)
|
||||
|> Enum.reject(&(&1 == ""))
|
||||
|
||||
{:error, reason} ->
|
||||
Mix.raise(
|
||||
"mutation scope #{scope_file} is unreadable (#{:file.format_error(reason)}); " <>
|
||||
"refusing to run the mutation sensor over an unknown scope"
|
||||
)
|
||||
end
|
||||
|
||||
if files == [] do
|
||||
Mix.raise(
|
||||
"mutation scope #{scope_file} is empty; refusing to run the mutation sensor over nothing"
|
||||
)
|
||||
end
|
||||
|
||||
files
|
||||
end
|
||||
|
||||
defp package do
|
||||
[
|
||||
licenses: ["MIT"],
|
||||
|
||||
Reference in New Issue
Block a user