Skip to content

Commit 4a378f0

Browse files
committed
Fix warnings
1 parent d68726a commit 4a378f0

File tree

3 files changed

+85
-74
lines changed

3 files changed

+85
-74
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,12 @@ defmodule Kernel.RaiseTest do
349349
test "function clause error" do
350350
result =
351351
try do
352-
zero(1)
352+
Access.get(:ok, :error)
353353
rescue
354354
x in [FunctionClauseError] -> Exception.message(x)
355355
end
356356

357-
assert result == "no function clause matching in Kernel.RaiseTest.zero/1"
357+
assert result == "no function clause matching in Access.get/3"
358358
end
359359

360360
test "badarg error" do
@@ -450,7 +450,7 @@ defmodule Kernel.RaiseTest do
450450

451451
result =
452452
try do
453-
^x = zero(0)
453+
^x = Process.get(:unused, 0)
454454
rescue
455455
x in [MatchError] -> Exception.message(x)
456456
end
@@ -483,7 +483,7 @@ defmodule Kernel.RaiseTest do
483483
test "bad map error" do
484484
result =
485485
try do
486-
%{zero(0) | foo: :bar}
486+
%{Process.get(:unused, 0) | foo: :bar}
487487
rescue
488488
x in [BadMapError] -> Exception.message(x)
489489
end
@@ -494,7 +494,7 @@ defmodule Kernel.RaiseTest do
494494
test "bad boolean error" do
495495
result =
496496
try do
497-
1 and true
497+
Process.get(:unused, 1) and true
498498
rescue
499499
x in [BadBooleanError] -> Exception.message(x)
500500
end
@@ -507,7 +507,7 @@ defmodule Kernel.RaiseTest do
507507

508508
result =
509509
try do
510-
case zero(0) do
510+
case Process.get(:unused, 0) do
511511
^x -> nil
512512
end
513513
rescue
@@ -521,7 +521,7 @@ defmodule Kernel.RaiseTest do
521521
result =
522522
try do
523523
cond do
524-
!zero(0) -> :ok
524+
!Process.get(:unused, 0) -> :ok
525525
end
526526
rescue
527527
x in [CondClauseError] -> Exception.message(x)
@@ -581,6 +581,4 @@ defmodule Kernel.RaiseTest do
581581
"function DoNotExist.for_sure/0 is undefined (module DoNotExist is not available). " <>
582582
"Make sure the module name is correct and has been specified in full (or that an alias has been defined)"
583583
end
584-
585-
defp zero(0), do: 0
586584
end

lib/elixir/test/elixir/kernel_test.exs

Lines changed: 75 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ defmodule KernelTest do
44
use ExUnit.Case, async: true
55

66
# Skip these doctests are they emit warnings
7-
doctest Kernel, except: [===: 2, !==: 2, is_nil: 1]
7+
doctest Kernel,
8+
except:
9+
[===: 2, !==: 2, and: 2, or: 2] ++
10+
[is_exception: 1, is_exception: 2, is_nil: 1, is_struct: 1, is_non_struct_map: 1]
811

912
def id(arg), do: arg
1013
def id(arg1, arg2), do: {arg1, arg2}
@@ -298,8 +301,8 @@ defmodule KernelTest do
298301
assert (false and true) == false
299302
assert (false and 0) == false
300303
assert (false and raise("oops")) == false
301-
assert ((x = true) and not x) == false
302-
assert_raise BadBooleanError, fn -> 0 and 1 end
304+
assert ((x = Process.get(:unused, true)) and not x) == false
305+
assert_raise BadBooleanError, fn -> Process.get(:unused, 0) and 1 end
303306
end
304307

305308
test "or/2" do
@@ -310,25 +313,27 @@ defmodule KernelTest do
310313
assert (false or false) == false
311314
assert (false or true) == true
312315
assert (false or 0) == 0
313-
assert ((x = false) or not x) == true
314-
assert_raise BadBooleanError, fn -> 0 or 1 end
316+
assert ((x = Process.get(:unused, false)) or not x) == true
317+
assert_raise BadBooleanError, fn -> Process.get(:unused, 0) or 1 end
315318
end
316319

317-
defp struct?(arg) when is_struct(arg), do: true
318-
defp struct?(_arg), do: false
320+
defp delegate_is_struct(arg), do: is_struct(arg)
321+
322+
defp guarded_is_struct(arg) when is_struct(arg), do: true
323+
defp guarded_is_struct(_arg), do: false
319324

320325
defp struct_or_map?(arg) when is_struct(arg) or is_map(arg), do: true
321326
defp struct_or_map?(_arg), do: false
322327

323328
test "is_struct/1" do
324-
assert is_struct(%{}) == false
325-
assert is_struct([]) == false
326-
assert is_struct(%Macro.Env{}) == true
327-
assert is_struct(%{__struct__: "foo"}) == false
328-
assert struct?(%Macro.Env{}) == true
329-
assert struct?(%{__struct__: "foo"}) == false
330-
assert struct?([]) == false
331-
assert struct?(%{}) == false
329+
assert delegate_is_struct(%{}) == false
330+
assert delegate_is_struct([]) == false
331+
assert delegate_is_struct(%Macro.Env{}) == true
332+
assert delegate_is_struct(%{__struct__: "foo"}) == false
333+
assert guarded_is_struct(%Macro.Env{}) == true
334+
assert guarded_is_struct(%{__struct__: "foo"}) == false
335+
assert guarded_is_struct([]) == false
336+
assert guarded_is_struct(%{}) == false
332337
end
333338

334339
test "is_struct/1 and other match works" do
@@ -337,25 +342,27 @@ defmodule KernelTest do
337342
assert struct_or_map?(10) == false
338343
end
339344

340-
defp struct?(arg, name) when is_struct(arg, name), do: true
341-
defp struct?(_arg, _name), do: false
345+
defp delegate_is_struct(arg, name), do: is_struct(arg, name)
346+
347+
defp guarded_is_struct(arg, name) when is_struct(arg, name), do: true
348+
defp guarded_is_struct(_arg, _name), do: false
342349

343350
defp struct_or_map?(arg, name) when is_struct(arg, name) or is_map(arg), do: true
344351
defp struct_or_map?(_arg, _name), do: false
345352

346353
defp not_atom(), do: "not atom"
347354

348355
test "is_struct/2" do
349-
assert is_struct(%{}, Macro.Env) == false
350-
assert is_struct([], Macro.Env) == false
351-
assert is_struct(%Macro.Env{}, Macro.Env) == true
352-
assert is_struct(%Macro.Env{}, URI) == false
353-
assert struct?(%Macro.Env{}, Macro.Env) == true
354-
assert struct?(%Macro.Env{}, URI) == false
355-
assert struct?(%{__struct__: "foo"}, "foo") == false
356-
assert struct?(%{__struct__: "foo"}, Macro.Env) == false
357-
assert struct?([], Macro.Env) == false
358-
assert struct?(%{}, Macro.Env) == false
356+
assert delegate_is_struct(%{}, Macro.Env) == false
357+
assert delegate_is_struct([], Macro.Env) == false
358+
assert delegate_is_struct(%Macro.Env{}, Macro.Env) == true
359+
assert delegate_is_struct(%Macro.Env{}, URI) == false
360+
assert guarded_is_struct(%Macro.Env{}, Macro.Env) == true
361+
assert guarded_is_struct(%Macro.Env{}, URI) == false
362+
assert guarded_is_struct(%{__struct__: "foo"}, "foo") == false
363+
assert guarded_is_struct(%{__struct__: "foo"}, Macro.Env) == false
364+
assert guarded_is_struct([], Macro.Env) == false
365+
assert guarded_is_struct(%{}, Macro.Env) == false
359366

360367
assert_raise ArgumentError, "argument error", fn ->
361368
is_struct(%{}, not_atom())
@@ -368,21 +375,23 @@ defmodule KernelTest do
368375
assert struct_or_map?(%Macro.Env{}, Macro.Env) == true
369376
end
370377

371-
defp non_struct_map?(arg) when is_non_struct_map(arg), do: true
372-
defp non_struct_map?(_arg), do: false
378+
defp delegate_is_non_struct_map(arg), do: is_non_struct_map(arg)
379+
380+
defp guarded_is_non_struct_map(arg) when is_non_struct_map(arg), do: true
381+
defp guarded_is_non_struct_map(_arg), do: false
373382

374383
defp non_struct_map_or_struct?(arg) when is_non_struct_map(arg) or is_struct(arg), do: true
375384
defp non_struct_map_or_struct?(_arg), do: false
376385

377386
test "is_non_struct_map/1" do
378-
assert is_non_struct_map(%{}) == true
379-
assert is_non_struct_map([]) == false
380-
assert is_non_struct_map(%Macro.Env{}) == false
381-
assert is_non_struct_map(%{__struct__: "foo"}) == true
382-
assert non_struct_map?(%Macro.Env{}) == false
383-
assert non_struct_map?(%{__struct__: "foo"}) == true
384-
assert non_struct_map?([]) == false
385-
assert non_struct_map?(%{}) == true
387+
assert delegate_is_non_struct_map(%{}) == true
388+
assert delegate_is_non_struct_map([]) == false
389+
assert delegate_is_non_struct_map(%Macro.Env{}) == false
390+
assert delegate_is_non_struct_map(%{__struct__: "foo"}) == true
391+
assert guarded_is_non_struct_map(%Macro.Env{}) == false
392+
assert guarded_is_non_struct_map(%{__struct__: "foo"}) == true
393+
assert guarded_is_non_struct_map([]) == false
394+
assert guarded_is_non_struct_map(%{}) == true
386395
end
387396

388397
test "is_non_struct_map/1 and other match works" do
@@ -391,21 +400,23 @@ defmodule KernelTest do
391400
assert non_struct_map_or_struct?(10) == false
392401
end
393402

394-
defp exception?(arg) when is_exception(arg), do: true
395-
defp exception?(_arg), do: false
403+
defp delegate_is_exception(arg), do: is_exception(arg)
404+
405+
defp guarded_is_exception(arg) when is_exception(arg), do: true
406+
defp guarded_is_exception(_arg), do: false
396407

397408
defp exception_or_map?(arg) when is_exception(arg) or is_map(arg), do: true
398409
defp exception_or_map?(_arg), do: false
399410

400411
test "is_exception/1" do
401-
assert is_exception(%{}) == false
402-
assert is_exception([]) == false
403-
assert is_exception(%RuntimeError{}) == true
404-
assert is_exception(%{__exception__: "foo"}) == false
405-
assert exception?(%RuntimeError{}) == true
406-
assert exception?(%{__exception__: "foo"}) == false
407-
assert exception?([]) == false
408-
assert exception?(%{}) == false
412+
assert delegate_is_exception(%{}) == false
413+
assert delegate_is_exception([]) == false
414+
assert delegate_is_exception(%RuntimeError{}) == true
415+
assert delegate_is_exception(%{__exception__: "foo"}) == false
416+
assert guarded_is_exception(%RuntimeError{}) == true
417+
assert guarded_is_exception(%{__exception__: "foo"}) == false
418+
assert guarded_is_exception([]) == false
419+
assert guarded_is_exception(%{}) == false
409420
end
410421

411422
test "is_exception/1 and other match works" do
@@ -414,26 +425,28 @@ defmodule KernelTest do
414425
assert exception_or_map?(10) == false
415426
end
416427

417-
defp exception?(arg, name) when is_exception(arg, name), do: true
418-
defp exception?(_arg, _name), do: false
428+
defp delegate_is_exception(arg, name), do: is_exception(arg, name)
429+
430+
defp guarded_is_exception(arg, name) when is_exception(arg, name), do: true
431+
defp guarded_is_exception(_arg, _name), do: false
419432

420433
defp exception_or_map?(arg, name) when is_exception(arg, name) or is_map(arg), do: true
421434
defp exception_or_map?(_arg, _name), do: false
422435

423436
test "is_exception/2" do
424-
assert is_exception(%{}, RuntimeError) == false
425-
assert is_exception([], RuntimeError) == false
426-
assert is_exception(%RuntimeError{}, RuntimeError) == true
427-
assert is_exception(%RuntimeError{}, Macro.Env) == false
428-
assert exception?(%RuntimeError{}, RuntimeError) == true
429-
assert exception?(%RuntimeError{}, Macro.Env) == false
430-
assert exception?(%{__exception__: "foo"}, "foo") == false
431-
assert exception?(%{__exception__: "foo"}, RuntimeError) == false
432-
assert exception?([], RuntimeError) == false
433-
assert exception?(%{}, RuntimeError) == false
437+
assert delegate_is_exception(%{}, RuntimeError) == false
438+
assert delegate_is_exception([], RuntimeError) == false
439+
assert delegate_is_exception(%RuntimeError{}, RuntimeError) == true
440+
assert delegate_is_exception(%RuntimeError{}, Macro.Env) == false
441+
assert guarded_is_exception(%RuntimeError{}, RuntimeError) == true
442+
assert guarded_is_exception(%RuntimeError{}, Macro.Env) == false
443+
assert guarded_is_exception(%{__exception__: "foo"}, "foo") == false
444+
assert guarded_is_exception(%{__exception__: "foo"}, RuntimeError) == false
445+
assert guarded_is_exception([], RuntimeError) == false
446+
assert guarded_is_exception(%{}, RuntimeError) == false
434447

435448
assert_raise ArgumentError, "argument error", fn ->
436-
is_exception(%{}, not_atom())
449+
delegate_is_exception(%{}, not_atom())
437450
end
438451
end
439452

@@ -954,15 +967,15 @@ defmodule KernelTest do
954967
end
955968

956969
test "get_in/1" do
957-
users = %{"john" => %{age: 27}, :meg => %{age: 23}}
970+
users = Process.get(:unused, %{"john" => %{age: 27}, :meg => %{age: 23}})
958971
assert get_in(users["john"][:age]) == 27
959972
assert get_in(users["dave"][:age]) == nil
960973
assert get_in(users["john"].age) == 27
961974
assert get_in(users["dave"].age) == nil
962975
assert get_in(users.meg[:age]) == 23
963976
assert get_in(users.meg.age) == 23
964977

965-
is_nil = nil
978+
is_nil = Process.get(:unused, nil)
966979
assert get_in(is_nil.age) == nil
967980

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

lib/elixir/test/elixir/macro_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ defmodule MacroTest do
214214
end
215215

216216
defp expand_once_and_clean(quoted, env) do
217-
cleaner = &Keyword.drop(&1, [:counter])
217+
cleaner = &Keyword.drop(&1, [:counter, :type_check])
218218

219219
quoted
220220
|> Macro.expand_once(env)
@@ -276,7 +276,7 @@ defmodule MacroTest do
276276
end
277277

278278
defp expand_and_clean(quoted, env) do
279-
cleaner = &Keyword.drop(&1, [:counter])
279+
cleaner = &Keyword.drop(&1, [:counter, :type_check])
280280

281281
quoted
282282
|> Macro.expand(env)
@@ -490,7 +490,7 @@ defmodule MacroTest do
490490
end
491491

492492
test "with case" do
493-
list = [1, 2, 3]
493+
list = List.flatten([1, 2, 3])
494494

495495
{result, formatted} =
496496
dbg_format(

0 commit comments

Comments
 (0)