test.check

Output of failed defspec should result in copy and paste-able data.

Details

  • Type: Enhancement Enhancement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

During a failure of a defspec the generated example data that caused the failure is not output in a way that makes it easy to copy and paste for testing. For example if the failed data was {:a "foo" :b "bar"} it will be displayed in the REPL as {:a foo, :b bar}. This is happening because the result of testing is printed by clojure.test.check.clojure-test/assert-check with println:

(defn- assert-check
[{:keys [result] :as m}]
(println m)
(if (instance? Throwable result)
(throw result)
(ct/is result)))

If it was changed to use pr-str then the output would be copy and paste-able:

(defn- assert-check
[{:keys [result] :as m}]
(println (pr-str m))
(if (instance? Throwable result)
(throw result)
(ct/is result)))

The following example spec output is better when I manipulate a local copy of test.check.

(defspec test-output 1
(for-all [n (gen/return {:a "foo"})]
(= n {:b "foo"})))

Output without change:
{:test-var test-output, :result false, :failing-size 0, :num-tests 1, :fail [{:a foo}], :shrunk {:total-nodes-visited 0, :depth 0, :result false, :smallest [{:a foo}]}}

Output with change:
{:test-var "test-output", :result false, :failing-size 0, :num-tests 1, :fail [{:a "foo"}], :shrunk {:total-nodes-visited 0, :depth 0, :result false, :smallest [{:a "foo"}]}}

Activity

Hide
Reid Draper added a comment -

Agree. This should get fixed.

Show
Reid Draper added a comment - Agree. This should get fixed.
Hide
Reid Draper added a comment -

Resolved in e857a084725889d0be7bee2a4e53ad70cd9b5f12.

Show
Reid Draper added a comment - Resolved in e857a084725889d0be7bee2a4e53ad70cd9b5f12.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: