Skip to content

Commit

Permalink
Make test suite for assert_no_guard more robust (#7801)
Browse files Browse the repository at this point in the history
If I got it right, one of the reasons for that change was to get the message:

> invalid expression in guard, **!** is not allowed in guards. To learn more about guards, visit: https://hexdocs.pm/elixir/guards.html  

instead of:

> invalid expression in guard, **case** is not allowed in guards. To learn more about guards, visit: https://hexdocs.pm/elixir/guards.html

This change should make the test suite more robust for future changes or refactors :)

In addition, I've split a couple of strings that were exceeding the maximum line length (98). By the way, should the formatter warn when it cannot keep the code under the desired line length? maybe with a `--strict` flag?
  • Loading branch information
fertapric authored and michalmuskala committed Jun 27, 2018
1 parent e07ccb1 commit e3b2b09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/elixir/lib/kernel.ex
Expand Up @@ -4877,7 +4877,8 @@ defmodule Kernel do

if is_list(funs) do
message =
"passing a list to Kernel.defdelegate/2 is deprecated, please define each delegate separately"
"passing a list to Kernel.defdelegate/2 is deprecated, " <>
"please define each delegate separately"

:elixir_errors.warn(line, file, message)
end
Expand Down Expand Up @@ -5219,7 +5220,8 @@ defmodule Kernel do
case context do
:guard ->
raise ArgumentError,
"invalid expression in guard, #{exp} is not allowed in guards. To learn more about guards, visit: https://hexdocs.pm/elixir/guards.html"
"invalid expression in guard, #{exp} is not allowed in guards. " <>
"To learn more about guards, visit: https://hexdocs.pm/elixir/guards.html"

_ ->
:ok
Expand Down
6 changes: 3 additions & 3 deletions lib/elixir/test/elixir/kernel/guard_test.exs
Expand Up @@ -290,19 +290,19 @@ defmodule Kernel.GuardTest do

# Consistent errors

assert_raise ArgumentError, ~r"invalid expression in guard", fn ->
assert_raise ArgumentError, ~r"invalid expression in guard, ! is not allowed", fn ->
defmodule SoftNegationLogicUsage do
defguard foo(logic) when !logic
end
end

assert_raise ArgumentError, ~r"invalid expression in guard", fn ->
assert_raise ArgumentError, ~r"invalid expression in guard, && is not allowed", fn ->
defmodule SoftAndLogicUsage do
defguard foo(soft, logic) when soft && logic
end
end

assert_raise ArgumentError, ~r"invalid expression in guard", fn ->
assert_raise ArgumentError, ~r"invalid expression in guard, || is not allowed", fn ->
defmodule SoftOrLogicUsage do
defguard foo(soft, logic) when soft || logic
end
Expand Down

0 comments on commit e3b2b09

Please sign in to comment.