Back
delete-file (clj)
(source)function
(delete-file f & [silently])
Delete file f. If silently is nil or false, raise an exception on failure, else return the value of silently.
Examples
technomancy/leiningen
(ns leiningen.test.new
(:require [leiningen.new :as new]
[clojure.test :refer :all]
[clojure.java.io :refer [file]]
[leiningen.test.helper :refer [delete-file-recursively abort-msg]]
[leiningen.new :as new]
[leiningen.core.main :as main]))
(deftest test-new-with-just-project-name
(new/new nil "test-new-proj")
(is (= #{"README.md" "project.clj" "resources" "src" "core.clj" "test"
"doc" "intro.md" "test_new_proj" "core_test.clj" ".gitignore"
".hgignore" "LICENSE" "CHANGELOG.md"}
(set (map (memfn getName) (rest (file-seq (file "test-new-proj")))))))
(delete-file-recursively (file "test-new-proj") :silently))
(deftest test-new-with-group-and-project-name
(new/new nil "orgname/a-project")
(is (= #{"src" "a_project_test.clj" "project.clj" "a_project.clj" "orgname"
"resources" "test" ".gitignore" "README.md" "doc" "intro.md"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName)
(rest (file-seq (file "a-project")))))))
(delete-file-recursively (file "a-project") :silently))
(deftest test-new-with-explicit-default-template
(new/new nil "default" "test-new-proj")
(is (= #{"README.md" "project.clj" "src" "core.clj" "test" "resources"
"doc" "intro.md" "test_new_proj" "core_test.clj" ".gitignore"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName) (rest (file-seq (file "test-new-proj")))))))
(delete-file-recursively (file "test-new-proj") :silently))
(deftest test-new-with-app-template
(new/new nil "app" "test-new-app")
(is (= #{"README.md" "project.clj" "src" "core.clj" "test" "resources"
"doc" "intro.md" "test_new_app" "core_test.clj" ".gitignore"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName) (rest (file-seq (file "test-new-app")))))))
(delete-file-recursively (file "test-new-app") :silently))
(deftest test-new-with-plugin-template
(new/new nil "plugin" "test-new-plugin")
(is (= #{"README.md" "project.clj" "src" "leiningen"
"test_new_plugin.clj" ".gitignore"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName) (rest (file-seq (file "test-new-plugin")))))))
(delete-file-recursively (file "test-new-plugin") :silently))
(deftest test-new-with-template-template
(new/new nil "template" "test-new-template")
(is (= #{"README.md" "project.clj" "src" "leiningen" "new" "resources"
"test_new_template.clj" "test_new_template" "foo.clj" ".gitignore"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName) (rest (file-seq (file "test-new-template")))))))
(delete-file-recursively (file "test-new-template") :silently))
(deftest test-new-with-to-dir-option
(new/new nil "test-new-proj" "--to-dir" "my-proj")
(is (= #{"README.md" "project.clj" "src" "core.clj" "test" "resources"
"doc" "intro.md" "test_new_proj" "core_test.clj" ".gitignore"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName) (rest (file-seq (file "my-proj")))))))
(delete-file-recursively (file "my-proj") :silently))
(deftest test-new-with-force-option
(.mkdir (file "test-new-proj"))
(new/new nil "test-new-proj" "--force")
(is (= #{"README.md" "project.clj" "src" "core.clj" "test" "resources"
"doc" "intro.md" "test_new_proj" "core_test.clj" ".gitignore"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName) (rest (file-seq (file "test-new-proj")))))))
(delete-file-recursively (file "test-new-proj") :silently))
(deftest test-new-with-to-dir-and-force-option
(.mkdir (file "my-proj"))
(new/new nil "test-new-proj" "--to-dir" "my-proj" "--force")
(is (= #{"README.md" "project.clj" "src" "core.clj" "test" "resources"
"doc" "intro.md" "test_new_proj" "core_test.clj" ".gitignore"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName) (rest (file-seq (file "my-proj")))))))
(delete-file-recursively (file "my-proj") :silently))
(new/new nil "test-new-proj")
(is (= #{"README.md" "project.clj" "src" "core.clj" "test" "resources"
"doc" "intro.md" "test_new_proj" "core_test.clj" ".gitignore"
"LICENSE" ".hgignore" "CHANGELOG.md"}
(set (map (memfn getName)
(rest (file-seq (file new-pwd "test-new-proj")))))))
(System/setProperty "leiningen.original.pwd" original-pwd)
(delete-file-recursively (file new-pwd) :silently)))
technomancy/leiningen
(ns leiningen.test.compile
(:refer-clojure :exclude [compile])
(:require [clojure.test :refer :all]
[clojure.java.io :as io]
[clojure.java.shell :refer [with-sh-dir]]
[leiningen.compile :refer :all]
[leiningen.test.helper :refer [sample-project
delete-file-recursively
sample-ordered-aot-project
sample-failing-project
sample-reader-cond-project
tricky-name-project
more-gen-classes-project
with-system-err-str
with-system-out-str]]
[leiningen.core.eval :as eval]
[leiningen.core.main :as main]))
(use-fixtures :each (fn [f]
(delete-file-recursively
(io/file "test_projects" "sample" "target") true)
(delete-file-recursively
(io/file "test_projects" "sample-failing" "target") true)
(binding [main/*info* false]
(f))))
technomancy/leiningen
(ns leiningen.test.install
(:require [leiningen.core.user :as user]
[leiningen.core.main :as main]
[clojure.test :refer :all]
[leiningen.install :refer :all]
[leiningen.test.helper :as helper]
[clojure.java.io :as io]))
(deftest ^:online test-install
(helper/unmemoize #'leiningen.core.classpath/get-dependencies-memoized
#'leiningen.core.classpath/get-dependencies*)
(helper/delete-file-recursively (helper/m2-dir "nomnomnom" "0.5.0-SNAPSHOT") true)
(with-out-str
(binding [main/*info* false]
(install helper/sample-project)))
(is (not (empty? (.listFiles (helper/m2-dir "nomnomnom" "0.5.0-SNAPSHOT"))))))
(deftest ^:online test-tricky-name-install
(helper/delete-file-recursively tricky-m2-dir true)
(with-out-str
(install helper/tricky-name-project))
(is (not (empty? (.listFiles tricky-m2-dir)))))
technomancy/leiningen
(ns leiningen.test.run
(:require [leiningen.core.project :as project]
[leiningen.javac]
[clojure.java.io :as io]
[leiningen.test.helper :as helper
:refer [bad-require-project tmp-dir tricky-name-project
java-main-project file-not-found-thrower-project
with-system-out-str with-system-err-str]]
[clojure.test :refer :all]
[leiningen.run :refer :all]))
(use-fixtures :each (fn [f]
(f)
(io/delete-file out-file :silently)))
technomancy/leiningen
(ns leiningen.test.uberjar
(:require [leiningen.uberjar :refer :all]
[clojure.test :refer :all]
[clojure.java.io :as io]
[clojure.java.shell :refer [sh]]
[clojure.xml :as xml]
[leiningen.test.helper :refer [unmemoize
sample-no-aot-project
uberjar-merging-project
data-readers-backwards-compatibility-project
provided-project
managed-deps-project
managed-deps-snapshot-project] :as h])
(:import (java.io File FileOutputStream)
(java.util.zip ZipFile)))
(deftest test-components-merger
(let [file1 (io/input-stream "test_projects/uberjar-components-merging/components1.xml")
file2 (io/input-stream "test_projects/uberjar-components-merging/components2.xml")
[read-xml combine write-xml] components-merger
combined-xml (combine (read-xml file1) (read-xml file2))
expected-xml (xml/parse (io/input-stream
"test_projects/uberjar-components-merging/expected-components.xml")
#'leiningen.uberjar/startparse)
result-file "test_projects/uberjar-components-merging/result-components.xml"
out-file (FileOutputStream. (File. result-file))]
(write-xml out-file combined-xml)
(is (= expected-xml (xml/parse (io/input-stream result-file)
#'leiningen.uberjar/startparse)))
(io/delete-file result-file true)))