Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add a not-found? test predicate

  • Loading branch information...
commit 1504628034f1e3cb317f1e47f18cf6a771860e8c 1 parent bd5ed4d
@danlarkin danlarkin authored
Showing with 24 additions and 15 deletions.
  1. +24 −15 test/subrosa/test/expect.clj
View
39 test/subrosa/test/expect.clj
@@ -65,26 +65,35 @@
(defn found? [pattern lines]
(some (partial re-find pattern) lines))
-(defn expect
- ([socket pattern] (expect socket pattern (or *timeout* 0)))
- ([socket pattern timeout]
- (.setSoTimeout (:socket socket) timeout)
- (let [in (:in socket)]
- (loop [line (socket-read-line in)]
- (swap! (:received socket) conj (if (= :timeout line)
- ""
- line))
- (if (found? pattern @(:received socket))
- true
- (if (= :timeout line)
- (join "\n" @(:received socket))
- (recur (socket-read-line in))))))))
+(defn expect [socket pattern found-pred]
+ (.setSoTimeout (:socket socket) *timeout*)
+ (let [in (:in socket)]
+ (loop [line (socket-read-line in)]
+ (swap! (:received socket) conj (if (= :timeout line)
+ ""
+ line))
+ (if (found-pred (found? pattern @(:received socket)))
+ true
+ (if (= :timeout line)
+ (join "\n" @(:received socket))
+ (recur (socket-read-line in)))))))
(defmethod assert-expr 'received? [msg form]
(let [socket (nth form 1)
string (nth form 2)]
`(do
- (let [v# (expect ~socket ~string)]
+ (let [v# (expect ~socket ~string identity)]
+ (if (true? v#)
+ (report {:type :pass :message ~msg
+ :expected ~string :actual v#})
+ (report {:type :fail :message ~msg
+ :expected ~string :actual v#}))))))
+
+(defmethod assert-expr 'not-received? [msg form]
+ (let [socket (nth form 1)
+ string (nth form 2)]
+ `(do
+ (let [v# (expect ~socket ~string not)]
(if (true? v#)
(report {:type :pass :message ~msg
:expected ~string :actual v#})
Please sign in to comment.
Something went wrong with that request. Please try again.