Is there a conflict for ensure_consistency alias in book Adopting Elixir?

In the AUTOMATING YOUR CONSISTENCY CHECKS, there is an alias:

    def​ aliases ​do​
      [
        "ensure_consistency"​: [​"​​test"​, ​"​​dialyzer"​, ​"​​credo --strict"​, ​"​​inch"​, ​"​coveralls"​]
      ]
    end

When I tried in my own project, it complains:
** (Mix) "mix test" is running on environment "dev". If you are running tests along another task, please set MIX_ENV explicitly.

I suppose it should execute in MIX_ENV=test mix ensure_consistency, but in previous chapters, the deps are:

    ​defp​ deps ​do​
​ 	  [
​ 	    {​:credo​, ​"​​~> 0.8.8"​, ​only:​ [​:dev​], ​runtime:​ false},
​ 	    {​:dialyxir​, ​"​​~> 0.5"​, ​only:​ [​:dev​], ​runtime:​ false},
​ 	    {​:excoveralls​, ​"​​~> 0.7.4"​, ​only:​ [​:test​], ​runtime:​ false},
​ 	    {​:ex_doc​, ​"​​~> 0.18"​, ​only:​ [​:dev​], ​runtime:​ false},
​ 	    {​:inch_ex​, ​"​​~> 0.5"​, ​only:​ [​:dev​, ​:test​], ​runtime:​ false}
​ 	  ]
​ 	​end​

So the credo and dialyxir are available only in dev mode while excoveralls only in test mode, it seems existing a conflict.

Is there something wrong? Thanks

2 Likes

I changed the deps as following, and run MIX_ENV=test mix ensure_consistency, it works.

    defp​ deps ​do​
​ 	  [
​ 	    {​:credo​, ​"​​~> 0.8.8"​, ​only:​ [​:dev​, :test], ​runtime:​ false},
​ 	    {​:dialyxir​, ​"​​~> 0.5"​, ​only:​ [​:dev​, :test], ​runtime:​ false},
​ 	    {​:excoveralls​, ​"​​~> 0.7.4"​, ​only:​ [​:test​], ​runtime:​ false},
​ 	    {​:ex_doc​, ​"​​~> 0.18"​, ​only:​ [​:dev​], ​runtime:​ false},
​ 	    {​:inch_ex​, ​"​​~> 0.5"​, ​only:​ [​:dev​, ​:test​], ​runtime:​ false}
​ 	  ]
​ 	​end​

But “coveralls” cannot output anything. If I run mix converalls, it have the output.

1 Like

I believe there is a :preferred_cli_env configuration you should set too.

1 Like

Ah, yes, I have set :preferred_cli_env

defmodule Brightu.Mixfile do
  use Mix.Project

  def project do
    [
      app: :brightu,
      version: "0.0.1",
      elixir: "~> 1.4",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:phoenix, :gettext] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps(),
      dialyzer: [plt_add_deps: :transitive],
      test_coverage: [tool: ExCoveralls],
      preferred_cli_env: [
        coveralls: :test,
        "coveralls.html": :test,
        inch: :test,
        ensure_consistency: :test
      ]
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {Brightu.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.3.2"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_ecto, "~> 3.2"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 1.0"},
      {:credo, "~> 0.9.1", only: [:dev, :test], runtime: false},
      {:dialyxir, "~> 1.0.0-rc.2", only: [:dev, :test], runtime: false},
      {:excoveralls, "~> 0.8", only: [:test], runtime: false}
      {:inch_ex, "~> 0.5", only: [:dev, :test], runtime: false},
    ]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to create, migrate and run the seeds file at once:
  #
  #     $ mix ecto.setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    [
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate", "test"],
      ensure_consistency: ["test", "dialyzer", "credo --strict", "inch", "coveralls"]
    ]
  end
end

When I run mix ensure_consistency, the coveralls seems not work. For example, I changed it to a typo word like imcoveralls, I expected it to report The task "imcoveralls" could not be found, but even no such error.

And inch has the same problem.

The output of mix ensure_consistency:

~/work/brightu master*
❯ env MIX_ENV=test mix ensure_consistency
Compiling 17 files (.ex)
Generated brightu app
...

Finished in 0.04 seconds
3 tests, 0 failures

Randomized with seed 965034
Finding suitable PLTs
Checking PLT...
[:asn1, :bunt, :certifi, :compiler, :connection, :cowboy, :cowlib, :credo, :crypto, :db_connection, :decimal, :dialyxir, :ecto, :eex, :elixir, :excoveralls, :gettext, :hackney, :idna, :inch_ex, :jason, :kernel, :logger, :metrics, :mime, :mimerl, :parse_trans, :phoenix, :phoenix_ecto, :phoenix_html, :phoenix_pubsub, :plug, :poison, :poolboy, :postgrex, :public_key, :ranch, :runtime_tools, :ssl, :ssl_verify_fun, :stdlib, :unicode_util_compat]
Looking up modules in dialyxir_erlang-21.0_elixir-1.6.6_deps-test.plt
Finding applications for dialyxir_erlang-21.0_elixir-1.6.6_deps-test.plt
Finding modules for dialyxir_erlang-21.0_elixir-1.6.6_deps-test.plt
Checking 1489 modules in dialyxir_erlang-21.0_elixir-1.6.6_deps-test.plt
Starting Dialyzer
[
  check_plt: false,
  init_plt: '/Users/james/work/brightu/_build/test/dialyxir_erlang-21.0_elixir-1.6.6_deps-test.plt',
  files_rec: ['/Users/james/work/brightu/_build/test/lib/brightu/ebin'],
  warnings: [:unknown],
  format: nil,
  raw: nil
]
Total errors: 2, Skipped: 0
done in 0m1.63s
:0:unknown_function
Function ExUnit.Callbacks.__merge__/3 does not exist.
________________________________________________________________________________
:0:unknown_function
Function ExUnit.CaseTemplate.__proxy__/2 does not exist.
________________________________________________________________________________
done (warnings were emitted)
Checking 22 source files ...

  Software Design
┃
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       lib/brightu/application.ex:28:5 #(Brightu.Application.config_change)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       test/support/data_case.ex:47:5 #(Brightu.DataCase.errors_on)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       lib/brightu_web/views/error_view.ex:14:5 #(BrightuWeb.ErrorView.template_not_found)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       test/support/data_case.ex:32:7 #(Brightu.DataCase)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       test/support/data_case.ex:29:11 #(Brightu.DataCase)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       test/support/conn_case.ex:36:17 #(BrightuWeb.ConnCase)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       test/support/conn_case.ex:33:7 #(BrightuWeb.ConnCase)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       test/support/conn_case.ex:30:11 #(BrightuWeb.ConnCase)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       test/support/channel_case.ex:32:7 #(BrightuWeb.ChannelCase)
┃ [D] ↘ Nested modules could be aliased at the top of the invoking module.
┃       test/support/channel_case.ex:29:11 #(BrightuWeb.ChannelCase)

  Code Readability
┃
┃ [R] → Modules should have a @moduledoc tag.
┃       lib/brightu/application.ex:1:11 #(Brightu.Application)
┃ [R] ↘ Line is too long (max is 80, was 82).
┃       lib/brightu_web/channels/user_socket.ex:33:81 #(BrightuWeb.UserSocket.connect)
┃ [R] ↘ Line is too long (max is 80, was 83).
┃       lib/brightu_web/channels/user_socket.ex:26:81 #(BrightuWeb.UserSocket.connect)
┃ [R] ↘ Line is too long (max is 80, was 85).
┃       lib/brightu/application.ex:15:81 #(Brightu.Application.start)

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.1 seconds (0.01s to load, 0.1s running checks)
38 mods/funs, found 4 code readability issues, 10 software design suggestions.


~/work/brightu master* 9s