Skip to content

Commit

Permalink
Cover new deps logic with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karolsluszniak committed Sep 12, 2019
1 parent 5425329 commit 61f92f5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/ex_check/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ defmodule ExCheck.Check do

defp satisfied_dep_status?(:any, _), do: true
defp satisfied_dep_status?(:ok, {:ok, _, _}), do: true
defp satisfied_dep_status?(:error, {:failed, _, _}), do: true
defp satisfied_dep_status?(:error, {:error, _, _}), do: true
defp satisfied_dep_status?(code, {_, _, {actual, _, _}}) when is_integer(code), do: code == actual
defp satisfied_dep_status?(_, _), do: false

Expand Down
31 changes: 26 additions & 5 deletions test/ex_check/project_cases/deps_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,25 @@ defmodule ExCheck.ProjectCases.DepsTest do
IO.puts(File.read!("a_out") <> "-" <> File.read!("b_out"))
"""

@g_eval """
raise("some error")
"""

@config """
[
tools: [
{:c, command: ["elixir", "-e", #{inspect(@c_eval)}], deps: [:a, :b]},
{:a, command: ["elixir", "-e", #{inspect(@a_eval)}], order: 1},
{:b, command: ["elixir", "-e", #{inspect(@b_eval)}]},
{:d, command: "dont_matter", deps: [:e]},
{:e, command: "dont_matter_too", deps: [:d]}
{:e, command: "dont_matter_too", deps: [:d]},
{:f, command: "dont_matter_too", deps: [:nonexisting]},
{:g, command: ["elixir", "-e", #{inspect(@g_eval)}]},
{:g_any, command: "echo", deps: [:g]},
{:g_success, command: "echo", deps: [{:g, status: :ok}]},
{:g_success_hide, command: "echo", deps: [{:g, status: :ok, else: :disable}]},
{:g_failure, command: "echo", deps: [{:g, status: :error}]}
]
]
"""
Expand All @@ -31,31 +42,41 @@ defmodule ExCheck.ProjectCases.DepsTest do
config_path = Path.join(project_dir, ".check.exs")
File.write!(config_path, @config)

assert {output, 0} = System.cmd("mix", ~w[check], cd: project_dir)
assert {output, 1} = System.cmd("mix", ~w[check], cd: project_dir)

assert output =~ "a success"
assert output =~ "b success"
assert output =~ "c success"
assert output =~ "d skipped due to unsatisfied dependency e"
assert output =~ "e skipped due to unsatisfied dependency d"
assert output =~ "f skipped due to unsatisfied dependency nonexisting"
assert output =~ "a_out-b_out"

assert output =~ ~r/running b.*running a.*running c/s

assert output =~ "g error code 1"
assert output =~ "g_success skipped due to unsatisfied dependency g"
refute output =~ "g_success_hide skipped"
assert output =~ "g_failure success"
end

test "deps (no parallel)", %{project_dir: project_dir} do
config_path = Path.join(project_dir, ".check.exs")
File.write!(config_path, @config)

assert {output, 0} = System.cmd("mix", ~w[check --no-parallel], cd: project_dir)
assert {output, 1} = System.cmd("mix", ~w[check --no-parallel], cd: project_dir)

assert output =~ "a success"
assert output =~ "b success"
assert output =~ "c success"
assert output =~ "d skipped due to unsatisfied dependency e"
assert output =~ "e skipped due to unsatisfied dependency d"
assert output =~ "f skipped due to unsatisfied dependency nonexisting"
assert output =~ "a_out-b_out"

assert output =~ ~r/running b.*running a.*running c/s

assert output =~ "g error code 1"
assert output =~ "g_success skipped due to unsatisfied dependency g"
refute output =~ "g_success_hide skipped"
assert output =~ "g_failure success"
end
end

0 comments on commit 61f92f5

Please sign in to comment.