Skip to content

Commit d267911

Browse files
committed
Hide obvious failures from type system
1 parent 13dde55 commit d267911

File tree

7 files changed

+21
-30
lines changed

7 files changed

+21
-30
lines changed

lib/elixir/test/elixir/kernel/raise_test.exs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,10 @@ defmodule Kernel.RaiseTest do
458458
assert result == "no match of right hand side value: 0"
459459
end
460460

461-
defp empty_map(), do: %{}
462-
463461
test "bad key error" do
464462
result =
465463
try do
466-
%{empty_map() | foo: :bar}
464+
%{Process.get(:unused, %{}) | foo: :bar}
467465
rescue
468466
x in [KeyError] -> Exception.message(x)
469467
end
@@ -472,7 +470,7 @@ defmodule Kernel.RaiseTest do
472470

473471
result =
474472
try do
475-
empty_map().foo
473+
Process.get(:unused, %{}).foo
476474
rescue
477475
x in [KeyError] -> Exception.message(x)
478476
end

lib/elixir/test/elixir/kernel/special_forms_test.exs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ defmodule Kernel.SpecialFormsTest do
6868
end
6969
end
7070

71-
def false_fun(), do: false
72-
7371
test "cond_clause error keeps line number in stacktrace" do
7472
try do
7573
cond do
76-
false_fun() -> :ok
74+
Process.get(:unused, false) -> :ok
7775
end
7876
rescue
7977
_ ->

lib/elixir/test/elixir/kernel/with_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ defmodule Kernel.WithTest do
126126
end
127127

128128
assert_raise RuntimeError, fn ->
129-
with({:ok, res} <- ok(42), res = res + oops(), do: res)
129+
with({:ok, res} <- ok(42), oops(), do: res)
130130
end
131131
end
132132

lib/elixir/test/elixir/kernel_test.exs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ defmodule KernelTest do
1111

1212
def id(arg), do: arg
1313
def id(arg1, arg2), do: {arg1, arg2}
14-
def empty_list(), do: []
1514
def empty_map, do: %{}
1615

1716
defp purge(module) do
@@ -1359,7 +1358,7 @@ defmodule KernelTest do
13591358
assert is_map_key(Map.new(a: 1), :a) == true
13601359

13611360
assert_raise BadMapError, fn ->
1362-
is_map_key(empty_list(), :a)
1361+
is_map_key(Process.get(:unused, []), :a)
13631362
end
13641363

13651364
case Map.new(a: 1) do
@@ -1381,15 +1380,15 @@ defmodule KernelTest do
13811380
test "tl/1" do
13821381
assert tl([:one]) == []
13831382
assert tl([1, 2, 3]) == [2, 3]
1384-
assert_raise ArgumentError, fn -> tl(empty_list()) end
1383+
assert_raise ArgumentError, fn -> tl(Process.get(:unused, [])) end
13851384

13861385
assert tl([:a | :b]) == :b
13871386
assert tl([:a, :b | :c]) == [:b | :c]
13881387
end
13891388

13901389
test "hd/1" do
13911390
assert hd([1, 2, 3, 4]) == 1
1392-
assert_raise ArgumentError, fn -> hd(empty_list()) end
1391+
assert_raise ArgumentError, fn -> hd(Process.get(:unused, [])) end
13931392
assert hd([1 | 2]) == 1
13941393
end
13951394

lib/elixir/test/elixir/map_test.exs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ defmodule MapTest do
66
doctest Map
77

88
@sample %{a: 1, b: 2}
9-
10-
defp sample, do: @sample
9+
defp sample, do: Process.get(:unused, %{a: 1, b: 2})
1110

1211
test "maps in attributes" do
1312
assert @sample == %{a: 1, b: 2}
@@ -82,7 +81,7 @@ defmodule MapTest do
8281

8382
test "map_size/1" do
8483
assert map_size(%{}) == 0
85-
assert map_size(@sample) == 2
84+
assert map_size(sample()) == 2
8685
end
8786

8887
test "new/1" do
@@ -282,8 +281,6 @@ defmodule MapTest do
282281
defstruct name: "john", age: 27
283282
end
284283

285-
defp empty_map(), do: %{}
286-
287284
test "structs" do
288285
assert %ExternalUser{} == %{__struct__: ExternalUser, name: "john", age: 27}
289286

@@ -294,10 +291,6 @@ defmodule MapTest do
294291

295292
%ExternalUser{name: name} = %ExternalUser{}
296293
assert name == "john"
297-
298-
assert_raise BadStructError, "expected a struct named MapTest.ExternalUser, got: %{}", fn ->
299-
%ExternalUser{empty_map() | name: "meg"}
300-
end
301294
end
302295

303296
describe "structs with variable name" do
@@ -325,12 +318,11 @@ defmodule MapTest do
325318
end
326319
end
327320

328-
defp foo(), do: "foo"
329321
defp destruct1(%module{}), do: module
330322
defp destruct2(%_{}), do: :ok
331323

332324
test "does not match" do
333-
invalid_struct = %{__struct__: foo()}
325+
invalid_struct = Process.get(:unused, %{__struct__: "foo"})
334326

335327
assert_raise CaseClauseError, fn ->
336328
case invalid_struct do
@@ -345,7 +337,7 @@ defmodule MapTest do
345337
end
346338

347339
assert_raise CaseClauseError, fn ->
348-
foo = foo()
340+
foo = Process.get(:unused, "foo")
349341

350342
case invalid_struct do
351343
%^foo{} -> :ok
@@ -370,7 +362,7 @@ defmodule MapTest do
370362
end
371363

372364
assert_raise MatchError, fn ->
373-
foo = foo()
365+
foo = Process.get(:unused, "foo")
374366
%^foo{} = invalid_struct
375367
end
376368
end

lib/ex_unit/test/ex_unit/assertions_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ defmodule ExUnit.AssertionsTest do
314314
true = assert match?({2, 1}, Value.tuple())
315315

316316
try do
317-
assert match?({:ok, _}, error(true))
317+
assert match?({:ok, _}, Process.get(:unused, :ok))
318318
flunk("This should never be tested")
319319
rescue
320320
error in [ExUnit.AssertionError] ->
321321
"match (match?) failed" = error.message
322-
"assert match?({:ok, _}, error(true))" = Macro.to_string(error.expr)
323-
"{:error, true}" = Macro.to_string(error.right)
322+
"assert match?({:ok, _}, Process.get(:unused, :ok))" = Macro.to_string(error.expr)
323+
":ok" = Macro.to_string(error.right)
324324
end
325325
end
326326

lib/ex_unit/test/ex_unit/callbacks_test.exs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,14 @@ defmodule ExUnit.CallbacksNoTests do
446446
use ExUnit.Case, async: true
447447

448448
setup_all do
449-
raise "never run"
449+
if :rand.uniform() >= 0 do
450+
raise "never run"
451+
end
450452
end
451453

452454
setup do
453-
raise "never run"
455+
if :rand.uniform() >= 0 do
456+
raise "never run"
457+
end
454458
end
455459
end

0 commit comments

Comments
 (0)