Clojure

Return summary & successful? for clojure.test

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.1
  • Component/s: None
  • Labels:
    None
  • Approval:
    Ok

Description

clojure.test/run-tests does not return a value, making it difficult to integrate with build frameworks such as Ant and Maven.

This patch was written by Jason Sankey, who is a registered contributor.

The patch modifies run-tests to return the test summary results (the same map sent to the report function).

The patch also adds a new function, "successful?", which returns true if the summary indicates that there were no failures or errors.

A test script or main program can call (successful? (run-tests ...)) and then indicate success or failure in System/exit.

Activity

Hide
Assembla Importer added a comment -

stuart.sierra said: [file:dDYqFAQsKr3RHfeJe5aVNr]: patch to run-tests and successful?

Show
Assembla Importer added a comment - stuart.sierra said: [file:dDYqFAQsKr3RHfeJe5aVNr]: patch to run-tests and successful?
Hide
Assembla Importer added a comment -

stuart.sierra said: Checked against commit 3e60eff602652e753a54ba88b25dbdd2615c3b2e and still applies ok.

Show
Assembla Importer added a comment - stuart.sierra said: Checked against commit 3e60eff602652e753a54ba88b25dbdd2615c3b2e and still applies ok.
Hide
Assembla Importer added a comment -

richhickey said: Not a valid patch format, needs git format-patch

Show
Assembla Importer added a comment - richhickey said: Not a valid patch format, needs git format-patch
Hide
Assembla Importer added a comment -

digash said: I've ran into the same issue as a work around. Just bind the function to the patched one.

(defn patched-run-tests
  "Runs all tests in the given namespaces; prints results.
  Defaults to current namespace if none given."
  ([] (run-tests *ns*))
  ([& namespaces]
     (let [summary (assoc (apply merge-with + (map test-ns namespaces))
                     :type :summary)]
       (report summary)
       summary)))

(defn successful?
  "Returns true if the given test summary indicates all tests
  were successful, false otherwise."
  [summary]
  (and (zero? (:fail summary))
       (zero? (:error summary))))

(binding [clojure.test/run-tests patched-run-tests]
  (when-not (successful? (run-all-tests #".*test.*"))
    (System/exit 1)))
Show
Assembla Importer added a comment - digash said: I've ran into the same issue as a work around. Just bind the function to the patched one.
(defn patched-run-tests
  "Runs all tests in the given namespaces; prints results.
  Defaults to current namespace if none given."
  ([] (run-tests *ns*))
  ([& namespaces]
     (let [summary (assoc (apply merge-with + (map test-ns namespaces))
                     :type :summary)]
       (report summary)
       summary)))

(defn successful?
  "Returns true if the given test summary indicates all tests
  were successful, false otherwise."
  [summary]
  (and (zero? (:fail summary))
       (zero? (:error summary))))

(binding [clojure.test/run-tests patched-run-tests]
  (when-not (successful? (run-all-tests #".*test.*"))
    (System/exit 1)))
Hide
Assembla Importer added a comment -

stuart.sierra said: [file:cdsoTU3Pmr3Q3BeJe5aVNr]: Correctly-formatted patch

Show
Assembla Importer added a comment - stuart.sierra said: [file:cdsoTU3Pmr3Q3BeJe5aVNr]: Correctly-formatted patch
Hide
Assembla Importer added a comment -

stuart.sierra said: (In [[r:607389029cfec50f32b73c00a6f66d0a1dbcda23]]) clojure.test/run-tests: return summary, add successful?; refs #193

Reformatted patch.

Signed-off-by: Rich Hickey <richhickey@gmail.com>

Branch: master

Show
Assembla Importer added a comment - stuart.sierra said: (In [[r:607389029cfec50f32b73c00a6f66d0a1dbcda23]]) clojure.test/run-tests: return summary, add successful?; refs #193 Reformatted patch. Signed-off-by: Rich Hickey <richhickey@gmail.com> Branch: master

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: