Bond - Design by Contract for Elixir

fun :slight_smile: <3

  @post is_hallo: result == :hallo
  def hello do
    :world
  end

in this case dialyzer is screaming at me already … but its MUCH easier to actually get the error in your face … than dialyzer warning about something that SHOULD fail … but never does. ref this thread where dialyzer warns about something that never fails Dialyzer warning from hell: no_return when calling erl_tar.create - #2 by jarlah

iex(1)> TestBond.hello()
** (Bond.PostconditionError) postcondition failed in TestBond.hello/0
|   label: :is_hallo
|   assertion: result == :hallo
|   binding: [result: :world]

    (test_bond 0.1.0) lib/test_bond.ex:6: TestBond.hello/0
    iex:1: (file)
iex(1)> 

its probably more valuable in the ecto example i described above

2 Likes