From 04ae511d6d434b2764b43c5da24af43841d56abd Mon Sep 17 00:00:00 2001 From: Bruno Laturner Date: Wed, 11 Oct 2017 17:34:08 -0300 Subject: [PATCH] Run code formatter on Kernel.RaiseTest --- lib/elixir/test/elixir/kernel/raise_test.exs | 371 ++++++++++--------- 1 file changed, 203 insertions(+), 168 deletions(-) diff --git a/lib/elixir/test/elixir/kernel/raise_test.exs b/lib/elixir/test/elixir/kernel/raise_test.exs index 4cfe3e7c6d6..9e0ae1b5764 100644 --- a/lib/elixir/test/elixir/kernel/raise_test.exs +++ b/lib/elixir/test/elixir/kernel/raise_test.exs @@ -1,4 +1,4 @@ -Code.require_file "../test_helper.exs", __DIR__ +Code.require_file("../test_helper.exs", __DIR__) defmodule Kernel.RaiseTest do use ExUnit.Case, async: true @@ -59,7 +59,7 @@ defmodule Kernel.RaiseTest do test "reraise message" do try do reraise "message", @trace - flunk "should not reach" + flunk("should not reach") rescue RuntimeError -> assert @trace == :erlang.get_stacktrace() @@ -68,7 +68,7 @@ defmodule Kernel.RaiseTest do try do var = binary() reraise var, @trace - flunk "should not reach" + flunk("should not reach") rescue RuntimeError -> assert @trace == :erlang.get_stacktrace() @@ -78,7 +78,7 @@ defmodule Kernel.RaiseTest do test "reraise with no arguments" do try do reraise RuntimeError, @trace - flunk "should not reach" + flunk("should not reach") rescue RuntimeError -> assert @trace == :erlang.get_stacktrace() @@ -87,7 +87,7 @@ defmodule Kernel.RaiseTest do try do var = atom() reraise var, @trace - flunk "should not reach" + flunk("should not reach") rescue RuntimeError -> assert @trace == :erlang.get_stacktrace() @@ -97,7 +97,7 @@ defmodule Kernel.RaiseTest do test "reraise with arguments" do try do reraise RuntimeError, [message: "message"], @trace - flunk "should not reach" + flunk("should not reach") rescue RuntimeError -> assert @trace == :erlang.get_stacktrace() @@ -107,7 +107,7 @@ defmodule Kernel.RaiseTest do atom = atom() opts = opts() reraise atom, opts, @trace - flunk "should not reach" + flunk("should not reach") rescue RuntimeError -> assert @trace == :erlang.get_stacktrace() @@ -117,7 +117,7 @@ defmodule Kernel.RaiseTest do test "reraise existing exception" do try do reraise %RuntimeError{message: "message"}, @trace - flunk "should not reach" + flunk("should not reach") rescue RuntimeError -> assert @trace == :erlang.get_stacktrace() @@ -126,7 +126,7 @@ defmodule Kernel.RaiseTest do try do var = struct() reraise var, @trace - flunk "should not reach" + flunk("should not reach") rescue RuntimeError -> assert @trace == :erlang.get_stacktrace() @@ -135,108 +135,118 @@ defmodule Kernel.RaiseTest do describe "rescue" do test "runtime error" do - result = try do - raise "an exception" - rescue - RuntimeError -> true - catch - :error, _ -> false - end + result = + try do + raise "an exception" + rescue + RuntimeError -> true + catch + :error, _ -> false + end assert result - result = try do - raise "an exception" - rescue - AnotherError -> true - catch - :error, _ -> false - end + result = + try do + raise "an exception" + rescue + AnotherError -> true + catch + :error, _ -> false + end refute result end test "named runtime error" do - result = try do - raise "an exception" - rescue - x in [RuntimeError] -> Exception.message(x) - catch - :error, _ -> false - end + result = + try do + raise "an exception" + rescue + x in [RuntimeError] -> Exception.message(x) + catch + :error, _ -> false + end assert result == "an exception" end test "with higher precedence than catch" do - result = try do - raise "an exception" - rescue - _ -> true - catch - _, _ -> false - end + result = + try do + raise "an exception" + rescue + _ -> true + catch + _, _ -> false + end assert result end test "argument error from erlang" do - result = try do - :erlang.error(:badarg) - rescue - ArgumentError -> true - end + result = + try do + :erlang.error(:badarg) + rescue + ArgumentError -> true + end assert result end test "argument error from elixir" do - result = try do - raise ArgumentError, "" - rescue - ArgumentError -> true - end + result = + try do + raise ArgumentError, "" + rescue + ArgumentError -> true + end assert result end test "catch-all variable" do - result = try do - raise "an exception" - rescue - x -> Exception.message(x) - end + result = + try do + raise "an exception" + rescue + x -> Exception.message(x) + end assert result == "an exception" end test "catch-all underscore" do - result = try do - raise "an exception" - rescue - _ -> true - end + result = + try do + raise "an exception" + rescue + _ -> true + end assert result end test "catch-all unused variable" do - result = try do - raise "an exception" - rescue - _any -> true - end + result = + try do + raise "an exception" + rescue + _any -> true + end assert result end test "catch-all with \"x in _\" syntax" do - result = try do - raise "an exception" - rescue - exception in _ -> - Exception.message(exception) - end + result = + try do + raise "an exception" + rescue + exception in _ -> + Exception.message(exception) + end assert result == "an exception" end @@ -244,74 +254,82 @@ defmodule Kernel.RaiseTest do describe "normalize" do test "wrap custom Erlang error" do - result = try do - :erlang.error(:sample) - rescue - x in [ErlangError] -> Exception.message(x) - end + result = + try do + :erlang.error(:sample) + rescue + x in [ErlangError] -> Exception.message(x) + end assert result == "Erlang error: :sample" end test "undefined function error" do - result = try do - DoNotExist.for_sure() - rescue - x in [UndefinedFunctionError] -> Exception.message(x) - end + result = + try do + DoNotExist.for_sure() + rescue + x in [UndefinedFunctionError] -> Exception.message(x) + end - assert result == "function DoNotExist.for_sure/0 is undefined (module DoNotExist is not available)" + assert result == + "function DoNotExist.for_sure/0 is undefined (module DoNotExist is not available)" end test "function clause error" do - result = try do - zero(1) - rescue - x in [FunctionClauseError] -> Exception.message(x) - end + result = + try do + zero(1) + rescue + x in [FunctionClauseError] -> Exception.message(x) + end assert result == "no function clause matching in Kernel.RaiseTest.zero/1" end test "badarg error" do - result = try do - :erlang.error(:badarg) - rescue - x in [ArgumentError] -> Exception.message(x) - end + result = + try do + :erlang.error(:badarg) + rescue + x in [ArgumentError] -> Exception.message(x) + end assert result == "argument error" end test "tuple badarg error" do - result = try do - :erlang.error({:badarg, [1, 2, 3]}) - rescue - x in [ArgumentError] -> Exception.message(x) - end + result = + try do + :erlang.error({:badarg, [1, 2, 3]}) + rescue + x in [ArgumentError] -> Exception.message(x) + end assert result == "argument error: [1, 2, 3]" end test "badarith error" do - result = try do - :erlang.error(:badarith) - rescue - x in [ArithmeticError] -> Exception.message(x) - end + result = + try do + :erlang.error(:badarith) + rescue + x in [ArithmeticError] -> Exception.message(x) + end assert result == "bad argument in arithmetic expression" end test "badarity error" do - fun = fn(x) -> x end + fun = fn x -> x end string = "#{inspect(fun)} with arity 1 called with 2 arguments (1, 2)" - result = try do - fun.(1, 2) - rescue - x in [BadArityError] -> Exception.message(x) - end + result = + try do + fun.(1, 2) + rescue + x in [BadArityError] -> Exception.message(x) + end assert result == string end @@ -319,113 +337,128 @@ defmodule Kernel.RaiseTest do test "badfun error" do # Avoid "invalid function call" warning in >= OTP 19 x = fn -> :example end - result = try do - x.().(2) - rescue - x in [BadFunctionError] -> Exception.message(x) - end + + result = + try do + x.().(2) + rescue + x in [BadFunctionError] -> Exception.message(x) + end assert result == "expected a function, got: :example" end test "badmatch error" do x = :example - result = try do - ^x = zero(0) - rescue - x in [MatchError] -> Exception.message(x) - end + + result = + try do + ^x = zero(0) + rescue + x in [MatchError] -> Exception.message(x) + end assert result == "no match of right hand side value: 0" end test "bad key error" do - result = try do - %{%{} | foo: :bar} - rescue - x in [KeyError] -> Exception.message(x) - end + result = + try do + %{%{} | foo: :bar} + rescue + x in [KeyError] -> Exception.message(x) + end assert result == "key :foo not found" - result = try do - %{}.foo - rescue - x in [KeyError] -> Exception.message(x) - end + result = + try do + %{}.foo + rescue + x in [KeyError] -> Exception.message(x) + end assert result == "key :foo not found in: %{}" end test "bad map error" do - result = try do - %{zero(0) | foo: :bar} - rescue - x in [BadMapError] -> Exception.message(x) - end + result = + try do + %{zero(0) | foo: :bar} + rescue + x in [BadMapError] -> Exception.message(x) + end assert result == "expected a map, got: 0" end test "bad boolean error" do - result = try do - 1 and true - rescue - x in [BadBooleanError] -> Exception.message(x) - end + result = + try do + 1 and true + rescue + x in [BadBooleanError] -> Exception.message(x) + end assert result == "expected a boolean on left-side of \"and\", got: 1" end test "case clause error" do x = :example - result = try do - case zero(0) do - ^x -> nil + + result = + try do + case zero(0) do + ^x -> nil + end + rescue + x in [CaseClauseError] -> Exception.message(x) end - rescue - x in [CaseClauseError] -> Exception.message(x) - end assert result == "no case clause matching: 0" end test "cond clause error" do - result = try do - cond do - !zero(0) -> :ok + result = + try do + cond do + !zero(0) -> :ok + end + rescue + x in [CondClauseError] -> Exception.message(x) end - rescue - x in [CondClauseError] -> Exception.message(x) - end assert result == "no cond clause evaluated to a true value" end test "try clause error" do - f = fn() -> :example end - result = try do + f = fn -> :example end + + result = try do - f.() - else - :other -> - :ok + try do + f.() + else + :other -> + :ok + end + rescue + x in [TryClauseError] -> Exception.message(x) end - rescue - x in [TryClauseError] -> Exception.message(x) - end assert result == "no try clause matching: :example" end test "undefined function error as Erlang error" do - result = try do - DoNotExist.for_sure() - rescue - x in [ErlangError] -> Exception.message(x) - end + result = + try do + DoNotExist.for_sure() + rescue + x in [ErlangError] -> Exception.message(x) + end - assert result == "function DoNotExist.for_sure/0 is undefined (module DoNotExist is not available)" + assert result == + "function DoNotExist.for_sure/0 is undefined (module DoNotExist is not available)" end end @@ -434,13 +467,15 @@ defmodule Kernel.RaiseTest do end test "with macros" do - result = try do - DoNotExist.for_sure() - rescue - x in exceptions() -> Exception.message(x) - end + result = + try do + DoNotExist.for_sure() + rescue + x in exceptions() -> Exception.message(x) + end - assert result == "function DoNotExist.for_sure/0 is undefined (module DoNotExist is not available)" + assert result == + "function DoNotExist.for_sure/0 is undefined (module DoNotExist is not available)" end defp zero(0), do: 0