Automatic Test Updates (and Enforcement someday)
Inspired by judge.
- Include dredd in your project.
io.github.escherize/dredd {:git/sha "eb72b86b4861276485acbcab3f1374ec11e01592"}
(require '[dredd.core :refer [j]])- As you work, put in some
jforms.
A j form takes one or two values:
Just one value: it will always eval to :fail.
(j (* 10 11))
;;=> :failThe wrong expected value will eval to :fail.
(j (* 10 11) "wrong")
;;=> :failThe right expected value evals to :true (🎉).
(j (* 10 11) 110)
;;=> :passThere are 3 public entrypoints: check, fix and ask.
Calling fix on a namespace will rewrite all j forms to be correct.
(ns my-ns (:require [dredd.dredd :refer [j]]))
;; blank
(j (* 234 593 -3))
;; wrong
(j (first "hi") \i)
(comment (dredd/fix))Evaluating (dredd/fix) in this namespace will rewrite it to be:
(ns my-ns (:require [dredd.dredd :refer [j]]))
;; blank
(j (* 234 593 -3) -416286)
;; wrong
(j (first "hi") \h)
(comment (dredd/fix))ask is similar to fix, but will show a prompt where you get shown
information about the change you're about to make. Accept the change by entering
y or just hitting enter, decline with n.
Here's the output of me running ask from dredd.dredd-test, and sending y + Enter to stdin twice:
*==================================================
* Fixing judge at: dredd.dredd-test:23
* When evaluating: (* 10 10)
* Expected: No value was provided
* But it should be: 100
* ---------
* Do you want me to fix it? [Y/n]
Dredd is fixing j_23 to be 100
*==================================================
* Fixing judge at: dredd.dredd-test:25
* When evaluating: (* 2 3)
* Expected: "wrong"
* But it should be: 6
* ---------
* Do you want me to fix it? [Y/n]
Dredd is fixing j_25 to be 6
And it's fixed.
To see the result of judges in your namespace without editing anything.
(dredd/check)
;;=> {:pass [test-one] :fail [test-two test-three]}-
I wouldn't try it with think this with non-deterministic functions.
-
Your editor might not be happy having file contents ripped out from under it. Sorry!
- check stdout of an expression
- transform dredd to a simple deftest
- transform a simple deftest to dredd
- detect dredd forms if they aren't aliased as j or refer'd to directly
- how to run as tests
- say thanks to ianthehenry