fix some path errors in windows tests
lein test still has 2 failures and 1 error after this. normalize-path should now handle absolute *nix paths correctly under windows addresses #1176
This commit is contained in:
parent
0ddd6ca629
commit
a8e20e96ce
8 changed files with 52 additions and 16 deletions
|
@ -252,9 +252,14 @@
|
|||
(get project dependencies-key)
|
||||
(apply get-dependencies dependencies-key project options)))
|
||||
|
||||
;http://stackoverflow.com/questions/5154754/why-is-file-isabsolute-platform-dependent-when-the-file-class-is-platform-inde
|
||||
(defn- normalize-path [root path]
|
||||
(let [f (io/file path)]
|
||||
(.getAbsolutePath (if (.isAbsolute f) f (io/file root path)))))
|
||||
(.getAbsolutePath (cond
|
||||
;(.isAbsolute f) f
|
||||
(or (.isAbsolute f) (.startsWith (.getPath f) "\\")) f
|
||||
:else
|
||||
(io/file root path)))))
|
||||
|
||||
(defn ext-dependency?
|
||||
"Should the given dependency be loaded in the extensions classloader?"
|
||||
|
|
|
@ -92,3 +92,30 @@
|
|||
(io/file (if (= :windows (get-os))
|
||||
"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))))
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
(:require [clojure.java.io :as io]
|
||||
[clojure.set :as set]
|
||||
[leiningen.core.user :as user]
|
||||
[leiningen.core.project :as project]))
|
||||
[leiningen.core.project :as project]
|
||||
[leiningen.core.utils :as utils]))
|
||||
|
||||
(use-fixtures :once
|
||||
(fn [f]
|
||||
|
@ -20,7 +21,7 @@
|
|||
[ring/ring-core "1.0.0"
|
||||
:exclusions [commons-codec]]]
|
||||
:checkout-deps-shares [:source-paths :resource-paths
|
||||
:compile-path #(str (:root %) "/foo")]
|
||||
:compile-path #(utils/pathify (str (:root %) "/foo"))]
|
||||
:repositories project/default-repositories
|
||||
:root "/tmp/lein-sample-project"
|
||||
:target-path "/tmp/lein-sample-project/target"
|
||||
|
@ -51,9 +52,10 @@
|
|||
(dependency-hierarchy :dependencies project))))
|
||||
|
||||
(def directories
|
||||
(vec (map utils/pathify
|
||||
["/tmp/lein-sample-project/test"
|
||||
"/tmp/lein-sample-project/src"
|
||||
"/tmp/lein-sample-project/resources"])
|
||||
"/tmp/lein-sample-project/resources"])))
|
||||
|
||||
(def libs
|
||||
#{(str (m2-file "commons-io/commons-io/1.4/commons-io-1.4.jar"))
|
||||
|
@ -75,7 +77,7 @@
|
|||
(spit (io/file d1 "project.clj")
|
||||
(pr-str '(defproject hello "1.0")))
|
||||
(is (= (for [path ["src" "resources" "target/classes" "foo"]]
|
||||
(format "/tmp/lein-sample-project/checkouts/d1/%s" path))
|
||||
(utils/pathify (format "/tmp/lein-sample-project/checkouts/d1/%s" path)))
|
||||
(#'leiningen.core.classpath/checkout-deps-paths project)))
|
||||
(finally
|
||||
;; can't recur from finally
|
||||
|
|
|
@ -54,11 +54,11 @@
|
|||
(is (= v (k actual))))
|
||||
(doseq [[k path] paths
|
||||
:when (string? path)]
|
||||
(is (= (str (:root actual) "/" path)
|
||||
(is (= (utils/pathify (str (:root actual) "/" path))
|
||||
(k actual))))
|
||||
(doseq [[k path] paths
|
||||
:when (coll? path)]
|
||||
(is (= (for [p path] (str (:root actual) "/" p))
|
||||
(is (= (for [p path] (utils/pathify (str (:root actual) "/" p)))
|
||||
(k actual))))))
|
||||
|
||||
;; TODO: test omit-default
|
||||
|
@ -267,14 +267,14 @@
|
|||
(project-with-profiles-meta
|
||||
p
|
||||
(merge @test-profiles (:profiles p))))]
|
||||
(is (= ["/etc/myapp" "test/hi" "blue-resources" "resources"]
|
||||
(is (= (vec (map utils/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 (= ["/etc/myapp" "test/hi" "blue-resources"]
|
||||
(is (= (vec (map utils/fix-path-delimiters ["/etc/myapp" "test/hi" "blue-resources"]))
|
||||
(-> (make
|
||||
(test-project
|
||||
{:resource-paths ^:displace ["resources"]
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
(defn plugin
|
||||
"A leiningen plugin project template."
|
||||
[name]
|
||||
[^String name]
|
||||
(let [render (renderer "plugin")
|
||||
unprefixed (if (.startsWith name "lein-")
|
||||
(subs name 5)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
leiningen.new.templates)
|
||||
(:require [leiningen.test.helper :refer [abort-msg]]
|
||||
[leiningen.core.user :as user]
|
||||
[leiningen.core.utils :as utils]
|
||||
[clojure.java.io :as io])
|
||||
(:import [java.io File]))
|
||||
|
||||
|
@ -52,7 +53,7 @@
|
|||
(is (= (multi-segment "multi.segment" "last") "multi.segment")))
|
||||
|
||||
(deftest paths
|
||||
(is (= (name-to-path "foo-bar.baz") "foo_bar/baz")))
|
||||
(is (= (name-to-path "foo-bar.baz") (utils/fix-path-delimiters "foo_bar/baz"))))
|
||||
|
||||
(deftest renderers
|
||||
(is (.contains (abort-msg (renderer "my-template") "boom" {})
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
[leiningen.test.helper :only [sample-project]])
|
||||
(: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]
|
||||
|
@ -96,7 +97,7 @@
|
|||
"target directory is included")
|
||||
(is (= nil (first-in xml [:project :build :extensions]))
|
||||
"no extensions")
|
||||
(is (= "target/classes" (first-in xml [:project :build :outputDirectory]))
|
||||
(is (= (utils/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])
|
||||
|
@ -275,7 +276,7 @@
|
|||
(first-in [:project :classifier])))))
|
||||
|
||||
(deftest test-pom-adds-java-source-paths
|
||||
(is (= ["java/src" "java/another"]
|
||||
(is (= (vec (map utils/fix-path-delimiters ["java/src" "java/another"]))
|
||||
(-> (make-pom (with-profile sample-project
|
||||
{:java-source-paths ["java/src" "java/another"]}))
|
||||
xml/parse-str
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(ns leiningen.test.repl
|
||||
(:require [clojure.test :refer :all]
|
||||
[leiningen.repl :refer :all]
|
||||
(leiningen.core [user :as user] [project :as project])))
|
||||
(leiningen.core [user :as user] [project :as project] [utils :as utils])))
|
||||
|
||||
(deftest test-merge-repl-profile
|
||||
(is (= (-> {:repl-options {:ack-port 4}}
|
||||
|
@ -61,13 +61,13 @@
|
|||
"http://localhost:20" "http://localhost:20"))
|
||||
|
||||
(deftest test-options-for-reply
|
||||
(is (= "/home/user/.lein-repl-history"
|
||||
(is (= (utils/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 (str (user/leiningen-home) "/repl-history")
|
||||
{:history-file (utils/pathify (str (user/leiningen-home) "/repl-history"))
|
||||
:input-stream System/in}
|
||||
exp)
|
||||
(let [[prj-k prj-v arg-k arg-v] in]
|
||||
|
|
Loading…
Reference in a new issue