Commits

Miki Tebeka committed 9397c70

defwriter-test

Comments (0)

Files changed (1)

test/csvlib_test.clj

 (defn tempfile []
   (.getCanonicalPath (File/createTempFile "-csvlib-" nil)))
 
-(deftest test-write-simple
-  (let [tmp (tempfile)]
-    (write-csv [[1 2 3] [4 5 6]] tmp)
-    (is (= (slurp tmp) "1,2,3\n4,5,6\n"))))
+(defmacro defwriter-test [test-name & body]
+  `(deftest ~test-name
+     (let [~'tmp (tempfile)]
+       ~@body)))
 
-(deftest test-write-headers
-  (let [tmp (tempfile)]
-    (write-csv [[1 2 3] [4 5 6]] tmp :headers ["x" "y" "z"])
-    (is (= (slurp tmp) "x,y,z\n1,2,3\n4,5,6\n"))))
+(defwriter-test test-write-simple
+  (write-csv [[1 2 3] [4 5 6]] tmp)
+  (is (= (slurp tmp) "1,2,3\n4,5,6\n")))
 
-(deftest test-write-format
-  (let [tmp (tempfile)
-        format {0 #(format "format-%s" %)}]
+(defwriter-test test-write-headers
+  (write-csv [[1 2 3] [4 5 6]] tmp :headers ["x" "y" "z"])
+  (is (= (slurp tmp) "x,y,z\n1,2,3\n4,5,6\n")))
+
+(defwriter-test test-write-format
+  (let [format {0 #(format "format-%s" %)}]
     (write-csv [[1 2 3] [4 5 6]] tmp :format format)
     (is (= (slurp tmp) "format-1,2,3\nformat-4,5,6\n"))))
-