-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpostcondition_is_test.clj
48 lines (43 loc) · 2.62 KB
/
postcondition_is_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(ns stateful-check.postcondition-is-test
(:require [clojure.test :refer [is deftest]]
[clojure.test.check.generators :as gen]
[stateful-check.core :refer :all]
[stateful-check.generator :refer [default-shrink-strategies ]]
[stateful-check.shrink-strategies :as shrink]
[stateful-check.queue-test :as q]))
(deftest ^:interactive postcondition-prints-in-parallel-case
;; This test is marked as "interactive" because we want to see the
;; output of it. The test should fail, but check to see whether you
;; can see the postcondition assertion output (expected and actual,
;; along with the message).
(is (specification-correct? (-> q/parallel-failing-queue-specification
(assoc-in [:commands :push :postcondition]
(fn [_ _ _ result] (is (nil? result))))
(assoc-in [:commands :peek :postcondition]
(fn [state _ _ val] (is (= (first (:elements state)) val))))
(assoc-in [:commands :pop :postcondition]
(fn [state _ _ val] (is (= (first (:elements state)) val))))
(assoc-in [:commands :count :postcondition]
(fn [state _ _ val] (is (= (count (:elements state)) val)))))
{:gen {:threads 2}
:run {:max-tries 10}})))
(deftest ^:interactive failed-assertion-is-printed
(is (specification-correct?
{:commands {:cmd {:command (constantly true)
:postcondition (fn [_ _ _ _]
(is (= 1 0)))}}})))
(deftest ^:interactive exception-in-assertion-is-printed
(is (specification-correct?
{:commands {:cmd {:command (constantly true)
:postcondition (fn [_ _ _ _]
(is (throw (ex-info "An exception!" {:oh "no"}))))}}})))
(deftest assertion-is-used-instead-of-return-value-is-printed
(is (specification-correct?
{:commands {:cmd {:command (constantly true)
:postcondition (fn [_ _ _ _]
(is (= 1 1))
;; falsey return value, but
;; ignored becuase of the
;; above assertion (which
;; passes)
false)}}})))