[英]Elixir: doctesting a sigil
I wrote an awesome sigil: 我写了一个很棒的标签:
defmodule Sigiltest do
@doc """
An awesome sigil!
### Usage
iex> ~a{I love elixir}
"I love elixir, awesome!"
"""
def sigil_a(content, _flags) do
"#{content}, awesome!"
end
end
Here is the tests module: 这是测试模块:
defmodule SigiltestTest do
use ExUnit.Case
doctest Sigiltest
end
When I run mix test
I get the following output: 当我运行
mix test
我得到以下输出:
Compiled lib/sigiltest.ex
** (CompileError) (for doctest at) lib/sigiltest.ex:7: undefined function sigil_a/2
(stdlib) lists.erl:1337: :lists.foreach/2
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
Is there a way to run doctests on a sigil? 有没有办法在sigil上运行doctest? If so, how?
如果是这样,怎么办?
That's because sigil_a
is not present in the context the doctests are being run. 这是因为
sigil_a
不存在于文档测试正在运行的环境。 You can either import Sigiltest
explicitly: 您可以显式导入
Sigiltest
:
@doc """
An awesome sigil!
### Usage
iex> import Sigiltest
iex> ~a{I love elixir}
"I love elixir, awesome!"
"""
or add import: true
to the doctest
invocation: 或在
doctest
调用中添加import: true
:
doctest Sigiltest, import: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.