lib/archeometer/analysis/utils.ex

defmodule Archeometer.Analysis.Utils do
  @moduledoc """
  Functions for validate the type, current project enviroment
  and to set the right path.
  """

  @doc """
  Validates if a module's path corresponds to a test..

  ## Parameters

  - The ``path`` of the module.

  ## Returns

  - A ``boolean`` value.
  """
  def is_test?(path) do
    if Mix.Project.umbrella?() or is_archeometer_test?() do
      Regex.match?(~r{apps/.+/test/}, path)
    else
      String.starts_with?(path, "test/")
    end
  end

  defp is_archeometer_test?() do
    Mix.env() == :test and Keyword.get(Mix.Project.config(), :app) == :archeometer
  end
end