moving 2 functions from utils to helper

merged all commits to date which required adding "dev-resources" so a
test wouldn't fail
`bin\lein test` tested under windows (currently 2 failures and 1 error)
This commit is contained in:
AtKaaZ 2013-05-15 02:39:23 +03:00
parent 6c34ce7e6f
commit 3521a21a9d
8 changed files with 45 additions and 48 deletions

View file

@ -256,7 +256,6 @@
(defn- normalize-path [root path]
(let [f (io/file path)]
(.getAbsolutePath (cond
;(.isAbsolute f) f
(or (.isAbsolute f) (.startsWith (.getPath f) "\\")) f
:else
(io/file root path)))))

View file

@ -93,29 +93,3 @@
"NUL"
"/dev/null")))
(defn fix-path-delimiters [input-str]
(clojure.string/replace input-str "/" java.io.File/separator))
;so paths would work under windows too which adds a drive letter and changes path separator
(defn pathify
"
pass only absolute paths, will throw if not
because if not absolute then .getAbsolutePath will resolve them relative to current directory
"
[in-str-or-file]
(cond (or
(nil? in-str-or-file)
(not (or
(.startsWith in-str-or-file "/")
(and
(>= (.length in-str-or-file) 3)
(= ":\\" (.substring in-str-or-file 1 3))
)
)
)
)
(throw (new RuntimeException (str "bad usage, passed: `" in-str-or-file "`")))
:else
(.getAbsolutePath (io/as-file in-str-or-file))))

View file

@ -4,8 +4,8 @@
(:require [clojure.java.io :as io]
[clojure.set :as set]
[leiningen.core.user :as user]
[leiningen.core.project :as project]
[leiningen.core.utils :as utils]))
[leiningen.test.helper :as lthelper]
[leiningen.core.project :as project]))
(use-fixtures :once
(fn [f]
@ -21,7 +21,7 @@
[ring/ring-core "1.0.0"
:exclusions [commons-codec]]]
:checkout-deps-shares [:source-paths :resource-paths
:compile-path #(utils/pathify (str (:root %) "/foo"))]
:compile-path #(lthelper/pathify (str (:root %) "/foo"))]
:repositories project/default-repositories
:root "/tmp/lein-sample-project"
:target-path "/tmp/lein-sample-project/target"
@ -52,7 +52,7 @@
(dependency-hierarchy :dependencies project))))
(def directories
(vec (map utils/pathify
(vec (map lthelper/pathify
["/tmp/lein-sample-project/test"
"/tmp/lein-sample-project/src"
"/tmp/lein-sample-project/resources"])))
@ -76,8 +76,8 @@
(.mkdirs d1)
(spit (io/file d1 "project.clj")
(pr-str '(defproject hello "1.0")))
(is (= (for [path ["src" "resources" "target/classes" "foo"]]
(utils/pathify (format "/tmp/lein-sample-project/checkouts/d1/%s" path)))
(is (= (for [path ["src" "dev-resources" "resources" "target/classes" "foo"]]
(lthelper/pathify (format "/tmp/lein-sample-project/checkouts/d1/%s" path)))
(#'leiningen.core.classpath/checkout-deps-paths project)))
(finally
;; can't recur from finally

View file

@ -5,6 +5,7 @@
(:require [leiningen.core.user :as user]
[leiningen.core.classpath :as classpath]
[leiningen.core.test.helper :refer [abort-msg]]
[leiningen.test.helper :as lthelper]
[leiningen.core.utils :as utils]
[clojure.java.io :as io]))
@ -54,11 +55,11 @@
(is (= v (k actual))))
(doseq [[k path] paths
:when (string? path)]
(is (= (utils/pathify (str (:root actual) "/" path))
(is (= (lthelper/pathify (str (:root actual) "/" path))
(k actual))))
(doseq [[k path] paths
:when (coll? path)]
(is (= (for [p path] (utils/pathify (str (:root actual) "/" p)))
(is (= (for [p path] (lthelper/pathify (str (:root actual) "/" p)))
(k actual))))))
;; TODO: test omit-default
@ -267,14 +268,14 @@
(project-with-profiles-meta
p
(merge @test-profiles (:profiles p))))]
(is (= (vec (map utils/fix-path-delimiters ["/etc/myapp" "test/hi" "blue-resources" "resources"]))
(is (= (vec (map lthelper/fix-path-delimiters ["/etc/myapp" "test/hi" "blue-resources" "resources"]))
(-> (make
(test-project
{:resource-paths ["resources"]
:profiles {:blue {:resource-paths ["blue-resources"]}}}))
(merge-profiles [:blue :tes :qa])
:resource-paths)))
(is (= (vec (map utils/fix-path-delimiters ["/etc/myapp" "test/hi" "blue-resources"]))
(is (= (vec (map lthelper/fix-path-delimiters ["/etc/myapp" "test/hi" "blue-resources"]))
(-> (make
(test-project
{:resource-paths ^:displace ["resources"]

View file

@ -53,3 +53,27 @@ Raise an exception if any deletion fails unless silently is true."
(doseq [child (.listFiles f)]
(delete-file-recursively child silently)))
(io/delete-file f silently)))
(defn fix-path-delimiters [input-str]
(clojure.string/replace input-str "/" java.io.File/separator))
;so paths would work under windows too which adds a drive letter and changes the path separator
(defn pathify
"
pass only absolute paths, will throw if not
because if not absolute then .getAbsolutePath will resolve them relative to current directory
"
[in-str-or-file]
(cond (or
(nil? in-str-or-file)
(not (or
(.startsWith in-str-or-file "/")
(and
(>= (.length in-str-or-file) 3)
(= ":\\" (.substring in-str-or-file 1 3))
))))
(throw (new RuntimeException (str "bad usage, passed: `" in-str-or-file "`")))
:else
(.getAbsolutePath (io/as-file in-str-or-file))))

View file

@ -1,9 +1,8 @@
(ns leiningen.test.new.templates
(:use clojure.test
leiningen.new.templates)
(:require [leiningen.test.helper :refer [abort-msg]]
(:require [leiningen.test.helper :refer [abort-msg] :as lthelper]
[leiningen.core.user :as user]
[leiningen.core.utils :as utils]
[clojure.java.io :as io])
(:import [java.io File]))
@ -53,7 +52,7 @@
(is (= (multi-segment "multi.segment" "last") "multi.segment")))
(deftest paths
(is (= (name-to-path "foo-bar.baz") (utils/fix-path-delimiters "foo_bar/baz"))))
(is (= (name-to-path "foo-bar.baz") (lthelper/fix-path-delimiters "foo_bar/baz"))))
(deftest renderers
(is (.contains (abort-msg (renderer "my-template") "boom" {})

View file

@ -3,10 +3,9 @@
[clojure.java.io :only [file delete-file]]
[leiningen.pom :only [make-pom pom]]
[leiningen.core.user :as user]
[leiningen.test.helper :only [sample-project]])
[leiningen.test.helper :only [sample-project] :as lthelper])
(:require [clojure.data.xml :as xml]
[leiningen.core.project :as project]
[leiningen.core.utils :as utils]
[leiningen.core.main :as main]))
(use-fixtures :once (fn [f]
@ -93,11 +92,11 @@
(map #(first-in % [:testResource :directory])
(deep-content xml [:project :build :testResources])))
"test resource directories use :dev :default and :test profiles")
(is (= "target/" (first-in xml [:project :build :directory]))
(is (= (lthelper/fix-path-delimiters "target/") (first-in xml [:project :build :directory]))
"target directory is included")
(is (= nil (first-in xml [:project :build :extensions]))
"no extensions")
(is (= (utils/fix-path-delimiters "target/classes") (first-in xml [:project :build :outputDirectory]))
(is (= (lthelper/fix-path-delimiters "target/classes") (first-in xml [:project :build :outputDirectory]))
"classes directory is included")
(is (= ["org.clojure" "rome" "ring" "org.clojure" "clojure-complete"]
(map #(first-in % [:dependency :groupId])
@ -276,7 +275,7 @@
(first-in [:project :classifier])))))
(deftest test-pom-adds-java-source-paths
(is (= (vec (map utils/fix-path-delimiters ["java/src" "java/another"]))
(is (= (vec (map lthelper/fix-path-delimiters ["java/src" "java/another"]))
(-> (make-pom (with-profile sample-project
{:java-source-paths ["java/src" "java/another"]}))
xml/parse-str

View file

@ -1,7 +1,8 @@
(ns leiningen.test.repl
(:require [clojure.test :refer :all]
[leiningen.repl :refer :all]
(leiningen.core [user :as user] [project :as project] [utils :as utils])))
[leiningen.test.helper :as lthelper]
(leiningen.core [user :as user] [project :as project])))
(deftest test-merge-repl-profile
(is (= (-> {:repl-options {:ack-port 4}}
@ -61,13 +62,13 @@
"http://localhost:20" "http://localhost:20"))
(deftest test-options-for-reply
(is (= (utils/fix-path-delimiters "/home/user/.lein-repl-history")
(is (= (lthelper/fix-path-delimiters "/home/user/.lein-repl-history")
(:history-file (options-for-reply {:root "/home/user"}))))
(let [prompt-fn (fn [ns] "hi ")]
(are
[in exp]
(= (merge
{:history-file (utils/pathify (str (user/leiningen-home) "/repl-history"))
{:history-file (lthelper/pathify (str (user/leiningen-home) "/repl-history"))
:input-stream System/in}
exp)
(let [[prj-k prj-v arg-k arg-v] in]