运行以下代码时,我收到警告:
warning: variable "char" does not exist and is being expanded to "char()", please use parentheses to remove the ambiguity or change the variable name
test/my_module_test.exs:7
接着是失败的测试:
== Compilation error in file test/my_module_test.exs ==
** (CompileError) test/my_module_test.exs:7: undefined function char/0
(stdlib) lists.erl:1338: :lists.foreach/2
(stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
(elixir) lib/code.ex:767: Code.require_file/2
(elixir) lib/kernel/parallel_compiler.ex:209: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
defmodule MyModule do
use ExUnit.Case, async: true
doctest MyModule
Enum.each ~w(a b c), fn char ->
test "test involving #{char}" do
assert char == char
end
end
end
似乎在Enum.each
块中char
为该行定义了值,test "... #{char}" do
但在断言中变得未定义。
为什么会这样?