Permalink
Browse files

test done

  • Loading branch information...
0 parents commit e829463a8709aab405a49e36f2155de461491d13 @hozumi committed Sep 27, 2010
Showing with 81 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +17 −0 README
  3. +5 −0 project.clj
  4. +7 −0 src/hozumi/rm_rf.clj
  5. +47 −0 test/hozumi/test_rm_rf.clj
@@ -0,0 +1,5 @@
+pom.xml
+*jar
+*~
+lib
+classes
17 README
@@ -0,0 +1,17 @@
+# clj-rm-rf
+
+FIXME: write description
+
+## Usage
+
+FIXME: write
+
+## Installation
+
+FIXME: write
+
+## License
+
+Copyright (C) 2010 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
@@ -0,0 +1,5 @@
+(defproject clj-rm-rf "1.0.0-SNAPSHOT"
+ :description "Recursively remove directory/file function for Clojure"
+ :dependencies [[org.clojure/clojure "1.2.0"]]
+ :dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]
+ [lein-clojars "0.6.0"]])
@@ -0,0 +1,7 @@
+(ns hozumi.rm-rf
+ (:require [clojure.java.io :as io :only [delete-file]]))
+
+(defn rm-rf [f & [silently]]
+ (if (.isDirectory f)
+ (dorun (map #(rm-rf % silently) (.listFiles f))))
+ (io/delete-file f silently))
@@ -0,0 +1,47 @@
+(ns hozumi.test-rm-rf
+ (:use [hozumi.rm-rf] :reload)
+ (:use [clojure.test])
+ (:require [clojure.java.io :as io :only [file]]))
+
+(defn mk-temp-file
+ [f]
+ (doto f
+ (.createNewFile)
+ (.deleteOnExit)))
+
+(defn mk-temp-dir
+ [f]
+ (doto f
+ (.mkdir)
+ (.deleteOnExit)))
+
+(defn mk-tmpfs
+ "Takes a tree of vectors and make directories and files under parent."
+ [parent node]
+ (if (vector? node)
+ (let [d (io/file parent (first node))]
+ (mk-temp-dir d)
+ (doall (map #(mk-tmpfs d %) (rest node)))
+ d)
+ (mk-temp-file (io/file parent node))))
+
+(def deep-fs
+ ["hozumi.test_rm_rf"
+ ["src"
+ ["org" "c.clj"]
+ "b.clj"]
+ ["lib" "A.jar"
+ ["dev" "B.jar"]
+ ["lab" ["lob"]]]
+ "a.clj"])
+
+(deftest test-rm-rf
+ (testing "make and delete dirs"
+ (let [dir (mk-tmpfs (io/file (System/getProperty
+ "java.io.tmpdir"))
+ deep-fs)]
+ (is (.exists dir))
+ (is (< 0 (count (.listFiles dir))))
+ (rm-rf dir :silently)
+ (is (= 0 (count (.listFiles dir))))
+ (is (not (.exists dir))))))

0 comments on commit e829463

Please sign in to comment.