Skip to content

Commit 3fef075

Browse files
committed
Remove wrapping in assert
1 parent ba63cc9 commit 3fef075

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

lib/elixir/lib/module/types/pattern.ex

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ defmodule Module.Types.Pattern do
158158
end
159159

160160
:error ->
161-
meta = get_meta(expr) || stack.meta
162-
error = {:badpattern, expr, tag, context}
163-
throw({types, error(__MODULE__, error, meta, stack, context)})
161+
throw({types, to_badpattern_error(expr, tag, stack, context)})
164162
end
165163
end)
166164

@@ -210,13 +208,23 @@ defmodule Module.Types.Pattern do
210208
end)
211209
end
212210

211+
defp to_badpattern_error(expr, tag, stack, context) do
212+
meta =
213+
if meta = get_meta(expr) do
214+
meta ++ Keyword.take(stack.meta, [:generated, :line])
215+
else
216+
stack.meta
217+
end
218+
219+
error(__MODULE__, {:badpattern, expr, tag, context}, meta, stack, context)
220+
end
221+
213222
defp of_pattern_intersect(tree, expected, expr, tag, stack, context) do
214223
actual = of_pattern_tree(tree, context)
215224
type = intersection(actual, expected)
216225

217226
if empty?(type) do
218-
meta = get_meta(expr) || stack.meta
219-
{:error, error(__MODULE__, {:badpattern, expr, tag, context}, meta, stack, context)}
227+
{:error, to_badpattern_error(expr, tag, stack, context)}
220228
else
221229
{:ok, type, context}
222230
end

lib/elixir/test/elixir/kernel_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ defmodule KernelTest do
301301
assert (false and true) == false
302302
assert (false and 0) == false
303303
assert (false and raise("oops")) == false
304-
assert ((x = Process.get(:unused, true)) and not x) == false
305-
assert_raise BadBooleanError, fn -> Process.get(:unused, 0) and 1 end
304+
assert ((x = true) and not x) == false
305+
assert_raise BadBooleanError, fn -> 0 and 1 end
306306
end
307307

308308
test "or/2" do
@@ -313,8 +313,8 @@ defmodule KernelTest do
313313
assert (false or false) == false
314314
assert (false or true) == true
315315
assert (false or 0) == 0
316-
assert ((x = Process.get(:unused, false)) or not x) == true
317-
assert_raise BadBooleanError, fn -> Process.get(:unused, 0) or 1 end
316+
assert ((x = false) or not x) == true
317+
assert_raise BadBooleanError, fn -> 0 or 1 end
318318
end
319319

320320
defp delegate_is_struct(arg), do: is_struct(arg)
@@ -967,15 +967,15 @@ defmodule KernelTest do
967967
end
968968

969969
test "get_in/1" do
970-
users = Process.get(:unused, %{"john" => %{age: 27}, :meg => %{age: 23}})
970+
users = %{"john" => %{age: 27}, :meg => %{age: 23}}
971971
assert get_in(users["john"][:age]) == 27
972972
assert get_in(users["dave"][:age]) == nil
973973
assert get_in(users["john"].age) == 27
974974
assert get_in(users["dave"].age) == nil
975975
assert get_in(users.meg[:age]) == 23
976976
assert get_in(users.meg.age) == 23
977977

978-
is_nil = Process.get(:unused, nil)
978+
is_nil = nil
979979
assert get_in(is_nil.age) == nil
980980

981981
assert_raise KeyError, ~r"key :unknown not found", fn -> get_in(users.unknown) end

lib/ex_unit/test/ex_unit/assertions_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ defmodule ExUnit.AssertionsTest do
5050
defmacrop assert_ok_with_pin_from_quoted_var(arg) do
5151
quote do
5252
kind = :ok
53-
assert {^kind, value} = Process.get(:unused, unquote(arg))
53+
assert {^kind, value} = unquote(arg)
5454
end
5555
end
5656

@@ -666,22 +666,22 @@ defmodule ExUnit.AssertionsTest do
666666

667667
test "assert match when falsy but not match" do
668668
try do
669-
assert {:ok, _x} = Process.get(:unused, nil)
669+
assert {:ok, _x} = nil
670670
rescue
671671
error in [ExUnit.AssertionError] ->
672672
"match (=) failed" = error.message
673-
"assert {:ok, _x} = Process.get(:unused, nil)" = Macro.to_string(error.expr)
673+
"assert {:ok, _x} = nil" = Macro.to_string(error.expr)
674674
"nil" = Macro.to_string(error.right)
675675
end
676676
end
677677

678678
test "assert match when falsy" do
679679
try do
680-
assert _x = Process.get(:unused, nil)
680+
assert _x = nil
681681
rescue
682682
error in [ExUnit.AssertionError] ->
683683
"Expected truthy, got nil" = error.message
684-
"assert _x = Process.get(:unused, nil)" = Macro.to_string(error.expr)
684+
"assert _x = nil" = Macro.to_string(error.expr)
685685
end
686686
end
687687

@@ -1005,14 +1005,14 @@ defmodule ExUnit.AssertionsTest do
10051005
end
10061006

10071007
test "AssertionError.message/1 is nicely formatted" do
1008-
assert :a = Process.get(:unused, :b)
1008+
assert :a = :b
10091009
rescue
10101010
error in [ExUnit.AssertionError] ->
10111011
"""
10121012
10131013
10141014
match (=) failed
1015-
code: assert :a = Process.get(:unused, :b)
1015+
code: assert :a = :b
10161016
left: :a
10171017
right: :b
10181018
""" = Exception.message(error)

lib/ex_unit/test/ex_unit/formatter_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ defmodule ExUnit.FormatterTest do
347347
{:error,
348348
catch_assertion do
349349
expected_module = ExUnit.TestModule
350-
assert %^expected_module{} = Process.get(:unused, nil)
350+
assert %^expected_module{} = nil
351351
end, []}
352352
]
353353

@@ -357,7 +357,7 @@ defmodule ExUnit.FormatterTest do
357357
match (=) failed
358358
The following variables were pinned:
359359
expected_module = ExUnit.TestModule
360-
code: assert %^expected_module{} = Process.get(:unused, nil)
360+
code: assert %^expected_module{} = nil
361361
left: %^expected_module{}
362362
right: nil
363363
"""

0 commit comments

Comments
 (0)