Muzak is a mutation testing library for Elixir and Erlang applications.
Mutation testing is a way of systematically introducing bugs into your code and then running your tests to see if any of them fail. If you introduce a bug in your code
defmodule Mix.Tasks.Credo.Ci do | |
@shortdoc "Run Credo only on files that have changed since the last merge commit." | |
@moduledoc """ | |
Runs Credo in CI with somewhat special behavior. | |
If the branch being tested is `master`, it runs Credo on all files. Otherwise, it only runs | |
Credo on the files that have changed since the last merge commit, and it will fail CI if any | |
check doesn't pass for those specific files. | |
""" |
# Given that we have a `User` module, that looks something like this: | |
defmodule User do | |
defstruct [:name] | |
def changeset(user, params) do | |
# ... | |
end | |
end |
# Step 1 | |
def create_subscription(email, plan_id, payment_method_id) do | |
with %User{customer_id: nil, name: name} = user <- | |
Repo.get_by(User, email: email), | |
{:ok, %Stripe.Customer{id: customer_id}} <- | |
Stripe.Customer.create(%{ | |
name: name, | |
email: email, | |
payment_method: payment_method_id, |
# My GenServer | |
defmodule My.GenServer do | |
def start_link() do | |
GenServer.start_link(__MODULE__, :ok, name: __MODULE__) | |
end | |
def init(_) do | |
{:ok, []} | |
end |
def intermittent_failures( | |
%{id: suite_id}, | |
spec \\ %{10 => 100, 9 => 80, 8 => 60, 7 => 45, 6 => 32, 5 => 25, 4 => 16, 3 => 9} | |
) do | |
limit = spec |> Map.values() |> Enum.max() | |
last_100_runs = | |
from(r in Run, | |
where: r.suite_id == ^suite_id, | |
order_by: [desc: r.inserted_at], |
for num <- [1, 2, 3], num < 3, do: num * 2 |
#!/usr/bin/env escript | |
%% -*- erlang -*- | |
%%! -smp enable -sname wtf | |
main(_) -> | |
process_flag(trap_exit, true), | |
ToMap = lists:seq(1, 50), | |
MapFun = fun() -> | |
lists:map(fun(N) -> N end, ToMap) | |
end, | |
start_runner(MapFun), |
defmodule SendAfter do | |
def send_after(pid, message, nanoseconds) do | |
{_, os_name} = :os.type() | |
increment = | |
if os_name == :Windows do | |
# monotonic time for Windows in miliseconds, in Linux and MacOS it's nanoseconds | |
# so we'll need to convert to miliseconds for windows | |
nanoseconds / 1_000_000 | |
else | |
nanoseconds |
import Header from './header.jsx'; | |
function headerFun(input) { | |
<h1>{input.name}</h1> | |
} | |
function DesktopHeader(input) { | |
<Header {...{input, headerFun}} /> | |
} |