Skip to content

Commit

Permalink
Simplified creation of user error reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed Mar 2, 2011
1 parent 44fcb37 commit 01f7352
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/midje/error_handling.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
(defn user-error-form? [form]
(:midje-user-error (meta form)))

(defn user-error-report-form [message position]
(defn user-error-report-form [form & notes]
(as-user-error `(report {:type :user-error
:message ~message
:position ~position})))
:notes '~notes
:position '~(form-position form)})))

; Maybe monad
(defmonad midje-maybe-m
Expand All @@ -35,6 +35,11 @@








(defn make-broken-fake [overrides & message-args]
(merge `{:type :broken-fake
:message ~(apply (partial cl-format nil) message-args)
Expand Down
16 changes: 10 additions & 6 deletions test/midje/t_error_handling.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

(ns midje.t-error-handling
(:use [midje sweet error-handling test-util]
[midje.util.file-position :only [form-position]]
[clojure.contrib monads]))

(fact "any form can be turned into a user-error form"
Expand Down Expand Up @@ -31,13 +32,16 @@
(fact "safely turns a function application into one that propagates errors."
(safely concat my-favorite-error-form '()) => my-favorite-error-form)

(fact "there is a helper function that produces error-reporting forms"
(let [result (user-error-report-form "message" "position")]
result => '(clojure.test/report {:type :user-error
:message "message"
:position "position" })
result => user-error-form?))

(fact "there is a helper function that produces error-reporting forms"
(user-error-report-form '(anything) "note 1" "note 2")
=> '(clojure.test/report {:type :user-error
:notes '["note 1" "note 2"]
:position '...form-position... })
(provided
(form-position '(anything)) => ...form-position...)

(user-error-report-form '(whatever)) => user-error-form?)



Expand Down

0 comments on commit 01f7352

Please sign in to comment.