Skip to content

Commit

Permalink
add millis-now and sleep testutil-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarshantanu committed Oct 15, 2012
1 parent 3b85e4a commit 8add618
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/clip_test/testutil.clj
Expand Up @@ -28,6 +28,18 @@
(.getMessage ^Throwable err))


(defn millis-now
[]
(System/currentTimeMillis))


(defn sleep
[millis] {:pre [(number? millis)]}
(try (Thread/sleep millis)
(catch InterruptedException e
(.interrupt ^Thread (Thread/currentThread)))))


(defn init!
[]
(alter-var-root #'internal/try-catch (constantly try-catch))
Expand Down
11 changes: 11 additions & 0 deletions src/clip_test/testutil_cljs.cljs
Expand Up @@ -39,6 +39,17 @@
(.-message err))


(defn millis-now
[]
(.getTime (js/Date.)))


(defn sleep
[millis]
(let [start (millis-now)]
(while (< (- (millis-now) start) millis))))


(defn init!
[]
(set! internal/try-catch try-catch)
Expand Down
15 changes: 13 additions & 2 deletions test/clip_test/core_test.clj
@@ -1,7 +1,7 @@
(ns clip-test.core-test
(:use [clip-test.testutil;*CLJSBUILD-REMOVE*;-cljs
:only [;*CLJSBUILD-REMOVE*;RuntimeException
re-quote throw-msg]])
re-quote throw-msg millis-now sleep]])
(:use;*CLJSBUILD-REMOVE*;-macros
[clip-test.core;*CLJSBUILD-REMOVE*;-cljs
:only [deftest testing is
Expand Down Expand Up @@ -54,8 +54,19 @@
(is (throw-msg "Raising error") "throw-msg")))


(deftest test-testutil
(testing "millis-now"
(is (pos? (millis-now)) "millis-now"))
(testing "sleep"
(let [start (millis-now)
_ (sleep 100)
stop (millis-now)]
(is (>= (- stop start) 100) "sleep"))))


(defn test-ns-hook
[]
(test-success)
(test-fail)
(test-error))
(test-error)
(test-testutil))

0 comments on commit 8add618

Please sign in to comment.