Skip to content

Commit 6923760

Browse files
committed
Fix other tests
1 parent ac42e94 commit 6923760

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

lib/elixir/lib/macro.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,8 @@ defmodule Macro do
814814
815815
iex> value = {:a, :b, :c}
816816
iex> quote do: unquote(value)
817-
{:a, :b, :c}
817+
** (ArgumentError) tried to unquote invalid AST: {:a, :b, :c}
818+
Did you forget to escape term using Macro.escape/1?
818819
819820
`escape/2` is used to escape *values* (either directly passed or variable
820821
bound), while `quote/2` produces syntax trees for

lib/elixir/test/elixir/code_normalizer/quoted_ast_test.exs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,16 @@ defmodule Code.Normalizer.QuotedASTTest do
405405
end
406406

407407
test "range" do
408-
assert quoted_to_string(quote(do: unquote(-1..+2))) == "-1..2"
408+
assert quoted_to_string(quote(do: -1..+2)) == "-1..+2"
409409
assert quoted_to_string(quote(do: Foo.integer()..3)) == "Foo.integer()..3"
410-
assert quoted_to_string(quote(do: unquote(-1..+2//-3))) == "-1..2//-3"
410+
assert quoted_to_string(quote(do: -1..+2//-3)) == "-1..+2//-3"
411411

412412
assert quoted_to_string(quote(do: Foo.integer()..3//Bar.bat())) ==
413413
"Foo.integer()..3//Bar.bat()"
414+
415+
# invalid AST
416+
assert quoted_to_string(-1..+2) == "-1..2"
417+
assert quoted_to_string(-1..+2//-3) == "-1..2//-3"
414418
end
415419

416420
test "when" do

lib/elixir/test/elixir/kernel/expansion_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,11 +2871,11 @@ defmodule Kernel.ExpansionTest do
28712871

28722872
test "handles invalid expressions" do
28732873
assert_compile_error(~r"invalid quoted expression: {1, 2, 3}", fn ->
2874-
expand_env(quote(do: unquote({1, 2, 3})), __ENV__)
2874+
expand_env({1, 2, 3}, __ENV__)
28752875
end)
28762876

28772877
assert_compile_error(~r"invalid quoted expression: #Function\<", fn ->
2878-
expand(quote(do: unquote({:sample, fn -> nil end})))
2878+
expand({:sample, fn -> nil end})
28792879
end)
28802880

28812881
assert_compile_error(~r"invalid pattern in match", fn ->

lib/elixir/test/elixir/macro_test.exs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ defmodule MacroTest do
839839
end
840840

841841
test "converts invalid AST with inspect" do
842-
assert Macro.to_string(quote do: unquote(1..3)) == "1..3"
842+
assert Macro.to_string(1..3) == "1..3"
843843
end
844844
end
845845

@@ -1172,12 +1172,16 @@ defmodule MacroTest do
11721172
end
11731173

11741174
test "range" do
1175-
assert macro_to_string(quote(do: unquote(-1..+2))) == "-1..2"
1175+
assert macro_to_string(quote(do: -1..+2)) == "-1..+2"
11761176
assert macro_to_string(quote(do: Foo.integer()..3)) == "Foo.integer()..3"
1177-
assert macro_to_string(quote(do: unquote(-1..+2//-3))) == "-1..2//-3"
1177+
assert macro_to_string(quote(do: -1..+2//-3)) == "-1..+2//-3"
11781178

11791179
assert macro_to_string(quote(do: Foo.integer()..3//Bar.bat())) ==
11801180
"Foo.integer()..3//Bar.bat()"
1181+
1182+
# invalid AST
1183+
assert macro_to_string(-1..+2) == "-1..2"
1184+
assert macro_to_string(-1..+2//-3) == "-1..2//-3"
11811185
end
11821186

11831187
test "when" do

lib/mix/test/mix/tasks/xref_test.exs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ defmodule Mix.Tasks.XrefTest do
6363
}
6464

6565
output = [
66-
%{callee: {A, :b, 1}, caller_module: B, file: "lib/b.ex", line: 3}
66+
%{callee: {A, :b, 1}, caller_module: B, file: "lib/b.ex", line: 3},
67+
%{
68+
callee: {:elixir_quote, :shallow_validate_ast, 1},
69+
caller_module: A,
70+
file: "lib/a.ex",
71+
line: 4
72+
}
6773
]
6874

6975
assert_all_calls(files, output)

0 commit comments

Comments
 (0)