Skip to content

Commit

Permalink
Merge pull request #269 from dgvncsz0f/master
Browse files Browse the repository at this point in the history
chore: PathReader.base_path config
  • Loading branch information
parroty authored Oct 3, 2021
2 parents 3fe1c20 + 8532957 commit a738f8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Add the following parameters.
- It's an optional setting for skipping `MIX_ENV=test` part when executing `mix coveralls` tasks.
- `test_coverage: [test_task: "espec"]` if you use Espec instead of default ExUnit.
- `:excoveralls` in the deps function.
- `Applicaton.put_env(:excoveralls, :base_path, "/bash/path")` an optional config if you want to set the application root path explicitly. By default this is the directory that the mix.exs file is in.

```elixir
def project do
Expand Down
5 changes: 4 additions & 1 deletion lib/excoveralls/path_reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ defmodule ExCoveralls.PathReader do
Returns the Mix.Project base path.
"""
def base_path do
Enum.find(Mix.Project.config_files, &(&1 =~ ~r/mix.exs/)) |> Path.dirname
case Application.fetch_env(:excoveralls, :base_path) do
{:ok, base_path} -> base_path
:error -> Mix.Project.config_files() |> Enum.find(&(&1 =~ ~r/mix.exs/)) |> Path.dirname()
end
end

@doc """
Expand Down
14 changes: 11 additions & 3 deletions test/mix/path_reader_test.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
defmodule ExCoveralls.PathReaderTest do
use ExUnit.Case
use ExUnit.Case, async: false
alias ExCoveralls.PathReader

test "gets project base path" do
assert(PathReader.base_path == File.cwd!)
assert(PathReader.base_path() == File.cwd!())
end

test "expand path" do
assert(PathReader.expand_path("test") == File.cwd! <> "/test")
assert(PathReader.expand_path("test") == File.cwd!() <> "/test")
end

test "use the application config when it is available" do
Application.put_env(:excoveralls, :base_path, "/base/path")
assert("/base/path" != File.cwd!())
assert(PathReader.base_path() == "/base/path")
after
Application.delete_env(:excoveralls, :base_path)
end
end

0 comments on commit a738f8c

Please sign in to comment.