Created
November 28, 2017 14:52
-
-
Save vnegrisolo/bfe477f43adf20753b274a314e007884 to your computer and use it in GitHub Desktop.
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 MixTests do | |
@commands [ | |
"git diff --name-only", | |
"git diff --cached --name-only", | |
"git diff --name-only ..develop", | |
"git ls-files --others --exclude-standard", | |
] | |
def files_to_run do | |
@commands | |
|> Enum.flat_map(&watch/1) | |
|> Enum.map(&transform/1) | |
|> Enum.reject(&is_nil/1) | |
|> Enum.sort | |
|> Enum.uniq | |
|> Enum.join(" ") | |
|> IO.puts | |
end | |
defp watch(command) do | |
[head|tail] = String.split(command) | |
{result, 0} = System.cmd(head, tail) | |
String.split(result) | |
end | |
defp transform("apps/" <> file), do: file |> String.replace(~r/^\w+\//, "") |> transform | |
defp transform("lib/" <> file), do: file |> String.replace(~r/(.*)\.ex$/, "test/\\g{1}_test.exs") |> transform | |
defp transform("test/"<> _rest = file), do: file | |
defp transform(_file), do: nil | |
end | |
MixTests.files_to_run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment