Skip to content

Commit

Permalink
Full test coverage for Mix.Tasks.Compile.Thrift
Browse files Browse the repository at this point in the history
Add test coverage for the last two remaining error cases. This brings
this module's unit test coverage up to 100%.

This also includes one functional change: we now redirect :stderr output
to :stdout so we can more consistently capture and display output from
the Thrift compiler executable.
  • Loading branch information
jparise committed Oct 2, 2016
1 parent a8ae4d9 commit bc08592
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/mix/tasks/compile.thrift.ex
Expand Up @@ -62,7 +62,7 @@ defmodule Mix.Tasks.Compile.Thrift do
end

defp get_thrift_version(exec) do
case System.cmd(exec, ~w[-version]) do
case System.cmd(exec, ~w[-version], stderr_to_stdout: true) do
{s, 0} -> hd(Regex.run(~r/\b(\d+\.\d+\.\d+)\b/, s, capture: :first) || [])
{_, e} -> Mix.raise "Failed to execute `#{exec} -version` (error #{e})"
end
Expand All @@ -89,7 +89,7 @@ defmodule Mix.Tasks.Compile.Thrift do

defp generate(exec, options, thrift_file) do
args = options ++ [thrift_file]
case System.cmd(exec, args) do
case System.cmd(exec, args, stderr_to_stdout: true) do
{_, 0} -> Mix.shell.info "Compiled #{thrift_file}"
{_, e} -> Mix.shell.error "Failed to compile #{thrift_file} (error #{e})"
end
Expand Down
22 changes: 21 additions & 1 deletion test/mix/tasks/compile.thrift_test.exs
Expand Up @@ -52,14 +52,24 @@ defmodule Mix.Tasks.Compile.ThriftTest do
end
end

test "specifying an empty :thrift_files list " do
test "specifying an empty :thrift_files list" do
in_fixture fn ->
with_project_config [thrift_files: []], fn ->
assert capture_io(fn -> run([]) end) == ""
end
end
end

test "specifying a non-existent Thrift file" do
in_fixture fn ->
with_project_config [thrift_files: ~w("missing.thrift")], fn ->
capture_io fn ->
assert capture_io(:stderr, fn -> run([]) end) =~ "Failed to compile"
end
end
end
end

test "attempting to use a non-existent Thrift executable" do
in_fixture fn ->
with_project_config [thrift_executable: "nonexistentthrift"], fn ->
Expand All @@ -70,6 +80,16 @@ defmodule Mix.Tasks.Compile.ThriftTest do
end
end

test "attempting to use a broken Thrift executable" do
in_fixture fn ->
with_project_config [thrift_executable: "mix", thrift_version: "0.0.0"], fn ->
assert_raise Mix.Error, ~r/Failed to execute/, fn ->
run([])
end
end
end
end

test "attempting to use an unsupported Thrift version" do
in_fixture fn ->
with_project_config [thrift_version: "< 0.0.0"], fn ->
Expand Down

0 comments on commit bc08592

Please sign in to comment.