PowerAssert
PowerAssert for Elixir.
Example test is here:
test "Enum.at should return the element at the given index" do
array = [1, 2, 3]; index = 2; two = 2
assert array |> Enum.at(index) == two
endAnd the result is like the following:
1) test Enum.at should return the element at the given index (PowerAssertTest)
array |> Enum.at(index) == two
| | | |
| | | 2
| | 2
| 3
[1, 2, 3]
Enjoy !
Dependencies
- ExUnit
Installation
# add dependencies in mix.exs
defp deps do
[
{:power_assert, "~> 0.0.1"}
]
end
# and fetch
$ mix deps.get
How to use
# replace `use ExUnit.Case` into `use PowerAssert` in your test code
## before
defmodule YourAwesomeTest do
use ExUnit.Case # <-- **HERE**
end
## after
defmodule YourAwesomeTest do
use PowerAssert # <-- **REPLACED**
endwhen ExUnit.CaseTemplate
# replace `use ExUnit.CaseTemplate` into `use PowerAssert.CaseTemplate` in your test code
## before
defmodule YourAwesomeTest do
use ExUnit.CaseTemplate # <-- **HERE**
end
## after
defmodule YourAwesomeTest do
use PowerAssert.CaseTemplate # <-- **REPLACED**
enduseful command to replace use ExUnit.CaseTemplate and use ExUnit.Case
$ git grep -l 'use ExUnit\.CaseTemplate' | xargs sed -i.bak -e 's/use ExUnit\.CaseTemplate/use PowerAssert.CaseTemplate/g'
$ git grep -l 'use ExUnit\.Case' | xargs sed -i.bak -e 's/use ExUnit\.Case/use PowerAssert/g'API
assert(expression, message \\ nil)
TODO
-
ExUnit.CaseTemplatewithusing function - support
assert [one] = [two]- currently rely on
ExUnit.Assertions.assert/1
- currently rely on
- and more we've not yet noticed
Limitation
- NOT SUPPORTED
- match expression ex:
assert List.first(x = [false]) - fn expression ex:
assert fn(x) -> x == 1 end.(2) - :: expression ex:
<< x :: bitstring >>- this means string interpolations also unsupported ex:
"#{x} hoge"
- this means string interpolations also unsupported ex:
- sigil expression ex:
~w(hoge fuga) - quote arguments ex:
assert quote(@opts, do: :hoge) - case expression
- get_and_update_in/2, put_in/2, update_in/2, for/1
- <<>> expression includes attributes
<<@x, "y">>; <<x :: binary, "y">> __MODULE__.Foo- many macros maybe caught error...
- match expression ex:
License
Distributed under the Apache 2 License.
Check LICENSE files for more information.