-
-
Save rrichardsonv/1a722d2d8c345dbc41b56333b5e0e72e to your computer and use it in GitHub Desktop.
Parallel test runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Mix.Tasks.NTest do | |
use Mix.Task | |
@wildcard "apps/*/test/**/*_test.exs" | |
def run([i, n | args]) do | |
{i, _} = Integer.parse(i) | |
{n, _} = Integer.parse(n) | |
test_paths = | |
@wildcard | |
|> Path.wildcard() | |
|> Enum.map(&Path.split/1) | |
|> Enum.map(&Enum.drop(&1, 2)) | |
|> Enum.map(&Path.join/1) | |
|> Enum.filter(fn path -> | |
path |> hash |> rem(n) == i - 1 | |
end) | |
{stdout, exit_code} = System.cmd("mix", ["test"] ++ args ++ test_paths) | |
IO.puts(stdout) | |
exit({:shutdown, exit_code}) | |
end | |
defp hash(s) do | |
:md5 | |
|> :crypto.hash(s) | |
|> Base.encode16() | |
|> Integer.parse(16) | |
|> elem(0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment