Skip to content

portasynthinca3/propex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PropEx

shitpost-y logo

I swear this is not a shitpost

An adaptation of PropEr for the Elixir world.

WARNING!: As of right now, this is a prototype. Feel free to open issues and send pull requests!

Installation

Add the library as a dependency for the test environment

defp deps do
  [
    {:propex, "~> 0.1", only: :test}
  ]
end

Usage

Suppose that you want to test the following module:

# lib/my_lib.ex
defmodule MyLib do
  @spec add(a :: integer(), b :: integer()) :: integer()
  def add(a, b), do: a + b
end

Automatic

You can automatically generate the argument list assuming that you had written a @spec for your function:

# test/my_lib_test.exs
defmodule MyLibTest do
  use ExUnit.Case
  use PropEx

  test "add/2" do
    forall arguments_of MyLib.add/2 do
      # a, b and result are assigned automatically
      result - a == b &&
      result - b == a
    end
  end
end

Manual

You can specify the variables and types yourself if you want to

# test/my_lib_test.exs
defmodule MyLibTest do
  use ExUnit.Case
  use PropEx

  test "add/2" do
    forall [a :: integer(), b :: integer()] do
      MyLib.add(a, b) == a + b
    end
  end
end