GitXplorerGitXplorer
W

propcheck

public
58 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
6a40b092eccb53d64abbac27e31b31adfff8e050

Show example output

WWilfred committed 4 years ago
Unverified
d50dd297c560bef442ae53454088fa3c3fddbecf

Emacs 25 doesn't support cl-lib, so require Emacs 26

WWilfred committed 4 years ago
Unverified
9f780519850508fd71df1b3ae0ad8bc5295cd4b5

Use latest Python to suppress a Cask warning on GH actions

WWilfred committed 4 years ago
Unverified
1fd2d9d909068d105cac88d457fd76b18b51c542

Support Emacs 27 bignums

WWilfred committed 4 years ago
Unverified
addd3b603eb6a896bbdfbb8d9d4338a59f205382

Prefer cl-lib to cl

WWilfred committed 4 years ago
Unverified
fa58907e1cd0f26e93e8bc6848dd1c4f30a0b851

Make more docstrings clean with checkdoc

WWilfred committed 4 years ago

README

The README file for this repository.

propcheck Coverage Status

propcheck brings property based testing to elisp.

It's similar to the excellent Hypothesis library for Python.

Status: beta. It works, but expect rough edges.

Usage

Tests are defined with propcheck-deftest, which defines an ERT test just like ert-deftest.

Your test should generate input values with the propcheck generator functions, then call propcheck-should to make assertions about the result.

(require 'propcheck)

(defun buggy-zerop (num)
  ;; Return t for all values >= 0. This is wrong! We'll claim that 42
  ;; is zero.
  ;;
  ;; There are lots of numbers that produce a wrong result from this
  ;; function, but 1 is the smallest. Ideally propcheck would report 1
  ;; as failing example. It usually does.
  (>= num 0))

(propcheck-deftest buggy-zerop-should-match-zerop ()
  ;; The body of this test will be evaluated repeatedly (up to
  ;; `propcheck-max-examples` times). The value generated will be
  ;; different on each iteration.
  ;;
  ;; If the assertion ever fails, propcheck will call the body again
  ;; with progressively smaller values, then report the smallest
  ;; failing example it could find.
  (let* ((i (propcheck-generate-integer "i")))
    (propcheck-should
     (eq (zerop i)
         (buggy-zerop i)))))

Generators

propcheck provides the following generators:

  • propcheck-generate-bool
  • propcheck-generate-integer
  • propcheck-generate-float
  • propcheck-generate-ascii-char
  • propcheck-generate-proper-list
  • propcheck-generate-vector
  • propcheck-generate-string
  • propcheck-generate-one-of

Using Generators Interactively

Generally you'll want to use propcheck-deftest to handle seeds for you. You can still experiement with generator functions in M-x ielm if you bind propcheck-seed first. Here's an example:

(let ((propcheck-seed (propcheck-seed)))
  (propcheck-generate-string nil)) ; e.g. "M26gM{^*v "