emiln / clojirc

A simple event-based IRC library.
Eclipse Public License 1.0
1 stars 0 forks source link

Simple macro to DRY up the command tests #22

Closed emiln closed 10 years ago

emiln commented 10 years ago

All command tests in the clojirc.commands-test namespace repeats a bunch of code. I am not usually a big fan of macros for tests, but I think it is warranted here.

(let [channel (async/chan)
      network {:to-network channel}]
  (expect
    "ADMIN tolsun.oulu.fi"
    (do (cmd/admin! network "tolsun.oulu.fi")
      (async/<!! channel))))

could become something like

(command-expect
  "ADMIN tolsun.oulu.fi"
  (cmd/admin! "tolsun.oulu.fi"))
emiln commented 10 years ago

Something like this:

(defmacro expect-command
  [string command]
  `(let [channel# (clojure.core.async/chan)
         network# {:to-network channel#}]
     (expect
       ~string
       (do (~(first command) network# ~@(rest command))
         (clojure.core.async/<!! channel#)))))
emiln commented 10 years ago

This was closed by the was that was fd1bc03d22ddcc9f8560f09d7837655ad1497952.