GitHub - Wilfred/propcheck: Quickcheck/hypothesis style testing for elisp
source link: https://github.com/Wilfred/propcheck
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
propcheck
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, so our minimal example should be 1. (>= num 0)) (propcheck-deftest buggy-zerop-should-match-zerop () (let* ((i (propcheck-generate-integer "i")) (result (buggy-zerop i))) (propcheck-should ;; If `zerop' returns t, we should also return t, otherwise we ;; should return false. (if (zerop i) result (not result)))))
Generators
propcheck provides the following generators:
propcheck-generate-bool
propcheck-generate-integer
propcheck-generate-ascii-char
propcheck-generate-proper-list
propcheck-generate-vector
propcheck-generate-string
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK