Created
September 23, 2018 21:14
-
-
Save AaronJamesKing/44ee9d6c11e9212e77b74c5c6f6db2ac to your computer and use it in GitHub Desktop.
Mixfile helpers
This file contains hidden or 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
| unless Code.ensure_compiled? MyApp.MixfileHelpers do | |
| defmodule MyApp.MixfileHelpers do | |
| @moduledoc """ | |
| Defines functions to be shared by individual Mixfiles inside the umbrella project. | |
| Since Mixfiles in an umbrella project often need to stay coordinated, this module has been introduced as a single source of truth. | |
| This module should only be used for configuration that must be shared across applications. If configuration is only incidentally similar across Mixfiles, it should not be defined here. | |
| In order to use these helper functions, run `Code.load_file("path/to/this/module.ex")` inside of a `mix.exs` file. This module's definition is wrapped inside a condition so that it won't be redefined when loaded multiple times. | |
| """ | |
| @doc """ | |
| The Mix environments defined for running tests | |
| """ | |
| @spec test_envs() :: [atom] | |
| def test_envs(), do: [:test, :integration] | |
| @doc """ | |
| Run the integration tests, passing in command line options. | |
| """ | |
| @spec run_integration_tests([String.t]) :: nil | no_return | |
| def run_integration_tests(args), do: test_with_env("integration", args) | |
| @doc """ | |
| Run the unit tests, passing in command line options. | |
| """ | |
| @spec run_unit_tests([String.t]) :: nil | no_return | |
| def run_unit_tests(args), do: test_with_env("test", args) | |
| @doc """ | |
| Run a specific level of tests (e.g. integration, acceptance). | |
| Based on a strategy used by Ecto: https://github.com/elixir-ecto/ecto/blob/v2.2.10/mix.exs#L75 | |
| """ | |
| @spec test_with_env(String.t, [String.t]) :: nil | no_return | |
| def test_with_env(env, args) do | |
| args = if IO.ANSI.enabled?, do: ["--color"|args], else: ["--no-color"|args] | |
| IO.puts "==> Running tests with `MIX_ENV=#{env}`" | |
| {_, res} = System.cmd "mix", ["test"|args], | |
| into: IO.binstream(:stdio, :line), | |
| env: [{"MIX_ENV", to_string(env)}] | |
| if res > 0 do | |
| System.at_exit(fn _ -> exit({:shutdown, 1}) end) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment