Unmemoize in order to fix tests.

This commit is contained in:
Phil Hagelberg 2017-06-04 09:38:00 -07:00
parent ad6c4bd290
commit 63305fcccd
6 changed files with 77 additions and 67 deletions

View file

@ -252,9 +252,8 @@
(def ^:private ^:dynamic *dependencies-session* (def ^:private ^:dynamic *dependencies-session*
"This is dynamic in order to avoid memoization issues.") "This is dynamic in order to avoid memoization issues.")
(def ^:private get-dependencies-memoized (defn- get-dependencies*
(memoize [dependencies-key managed-dependencies-key
(fn [dependencies-key managed-dependencies-key
{:keys [repositories local-repo offline? update {:keys [repositories local-repo offline? update
checksum mirrors] :as project} checksum mirrors] :as project}
{:keys [add-classpath?] :as args}] {:keys [add-classpath?] :as args}]
@ -306,16 +305,18 @@
(if (and (or (instance? java.net.UnknownHostException exception-cause) (if (and (or (instance? java.net.UnknownHostException exception-cause)
(instance? java.net.NoRouteToHostException exception-cause)) (instance? java.net.NoRouteToHostException exception-cause))
(not offline?)) (not offline?))
(get-dependencies-memoized dependencies-key managed-dependencies-key (get-dependencies* dependencies-key managed-dependencies-key
(assoc project :offline? true) args) (assoc project :offline? true) args)
(throw e)))))))) (throw e))))))
(def ^:private get-dependencies-memoized (memoize get-dependencies*))
(defn ^:internal get-dependencies [dependencies-key managed-dependencies-key (defn ^:internal get-dependencies [dependencies-key managed-dependencies-key
project & args] project & args]
(let [ranges (atom []), overrides (atom []) (let [ranges (atom []), overrides (atom [])
trimmed (select-keys project [dependencies-key managed-dependencies-key trimmed (select-keys project [dependencies-key managed-dependencies-key
:repositories :checksum :local-repo :repositories :checksum :local-repo
:offline? :update :mirrors]) :offline? :update :mirrors :memoize-buster])
deps-result (binding [*dependencies-session* (pedantic/session deps-result (binding [*dependencies-session* (pedantic/session
project ranges overrides)] project ranges overrides)]
(get-dependencies-memoized dependencies-key (get-dependencies-memoized dependencies-key

View file

@ -96,8 +96,8 @@
;; :plugins and will also be available to deploy to. ;; :plugins and will also be available to deploy to.
;; Add ^:replace (:repositories ^:replace [...]) to only use repositories you ;; Add ^:replace (:repositories ^:replace [...]) to only use repositories you
;; list below. ;; list below.
:repositories [["java.net" "http://download.java.net/maven/2"] :repositories [["java.net" "https://download.java.net/maven/2"]
["sonatype" {:url "http://oss.sonatype.org/content/repositories/releases" ["sonatype" {:url "https://oss.sonatype.org/content/repositories/releases"
;; If a repository contains releases only setting ;; If a repository contains releases only setting
;; :snapshots to false will speed up dependencies. ;; :snapshots to false will speed up dependencies.
:snapshots false :snapshots false
@ -117,8 +117,8 @@
;; Credentials for repositories should *not* be stored ;; Credentials for repositories should *not* be stored
;; in project.clj but in ~/.lein/credentials.clj.gpg instead, ;; in project.clj but in ~/.lein/credentials.clj.gpg instead,
;; see `lein help deploying` under "Authentication". ;; see `lein help deploying` under "Authentication".
["snapshots" "http://blueant.com/archiva/snapshots"] ["snapshots" "https://blueant.com/archiva/snapshots"]
["releases" {:url "http://blueant.com/archiva/internal" ["releases" {:url "https://blueant.com/archiva/internal"
;; Using :env as a value here will cause an ;; Using :env as a value here will cause an
;; environment variable to be used based on ;; environment variable to be used based on
;; the key; in this case LEIN_PASSWORD. ;; the key; in this case LEIN_PASSWORD.

View file

@ -136,3 +136,6 @@
(def #^{:macro true} with-system-out-str #'utils/with-system-out-str) (def #^{:macro true} with-system-out-str #'utils/with-system-out-str)
(def #^{:macro true} with-system-err-str #'utils/with-system-err-str) (def #^{:macro true} with-system-err-str #'utils/with-system-err-str)
(defn unmemoize [v underlying]
(alter-var-root v (constantly underlying)))

View file

@ -6,12 +6,12 @@
[clojure.java.io :only [file]])) [clojure.java.io :only [file]]))
(deftest ^:online test-install (deftest ^:online test-install
(unmemoize #'leiningen.core.classpath/get-dependencies-memoized
#'leiningen.core.classpath/get-dependencies*)
(delete-file-recursively (m2-dir "nomnomnom" "0.5.0-SNAPSHOT") true) (delete-file-recursively (m2-dir "nomnomnom" "0.5.0-SNAPSHOT") true)
(install sample-project) (install sample-project)
(is (not (empty? (.listFiles (m2-dir "nomnomnom" "0.5.0-SNAPSHOT")))))) (is (not (empty? (.listFiles (m2-dir "nomnomnom" "0.5.0-SNAPSHOT"))))))
(def jdom-dir (file local-repo "jdom" "jdom" "1.0"))
(def tricky-m2-dir (file local-repo "org" "domain" "tricky-name" "1.0")) (def tricky-m2-dir (file local-repo "org" "domain" "tricky-name" "1.0"))
(deftest ^:online test-tricky-name-install (deftest ^:online test-tricky-name-install

View file

@ -5,7 +5,8 @@
[leiningen.core.utils :refer [platform-nullsink]] [leiningen.core.utils :refer [platform-nullsink]]
[leiningen.test.helper :as helper] [leiningen.test.helper :as helper]
[robert.hooke :as hooke] [robert.hooke :as hooke]
[leiningen.javac :as javac]) [leiningen.javac :as javac]
[leiningen.test.helper :refer [unmemoize]])
(:use [clojure.test] (:use [clojure.test]
[leiningen.jar])) [leiningen.jar]))
@ -92,6 +93,8 @@
"jar produces two jar files"))) "jar produces two jar files")))
(deftest ^:online test-no-deps-jar (deftest ^:online test-no-deps-jar
(unmemoize #'leiningen.core.classpath/get-dependencies-memoized
#'leiningen.core.classpath/get-dependencies*)
(let [[coord jar-file] (first (let [[coord jar-file] (first
(jar (dissoc helper/sample-project (jar (dissoc helper/sample-project
:dependencies :main)))] :dependencies :main)))]

View file

@ -4,7 +4,8 @@
[clojure.java.io :refer [delete-file]] [clojure.java.io :refer [delete-file]]
[clojure.java.shell :refer [sh]] [clojure.java.shell :refer [sh]]
[clojure.xml :as xml] [clojure.xml :as xml]
[leiningen.test.helper :refer [sample-no-aot-project [leiningen.test.helper :refer [unmemoize
sample-no-aot-project
uberjar-merging-project uberjar-merging-project
provided-project provided-project
managed-deps-project managed-deps-project
@ -68,6 +69,8 @@
(is (= 0 (:exit (sh "java" bootclasspath "-jar" filename)))))) (is (= 0 (:exit (sh "java" bootclasspath "-jar" filename))))))
(deftest test-uberjar-managed-dependencies (deftest test-uberjar-managed-dependencies
(unmemoize #'leiningen.core.classpath/get-dependencies-memoized
#'leiningen.core.classpath/get-dependencies*)
(doseq [[proj jarfile] [[managed-deps-snapshot-project (doseq [[proj jarfile] [[managed-deps-snapshot-project
(str "test_projects/managed-deps-snapshot/target/" (str "test_projects/managed-deps-snapshot/target/"
"mgmt-0.99.0-SNAPSHOT-standalone.jar")] "mgmt-0.99.0-SNAPSHOT-standalone.jar")]