Skip to content

Commit

Permalink
Update dep logic for lower footprint:
Browse files Browse the repository at this point in the history
- Instead of a coded in :parallel-test profile, just enumerate the
  deps we need
- Insure they're in resultant project, if absent. If present, keep
  what the user project specified.
- Only deal in the :parallel-test profile if the user has specced it.
- Update the core.async version
  • Loading branch information
alexkrysko committed Nov 15, 2018
1 parent 6c3b5b0 commit 72f21fb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parallel, execute all the tests flagged as such.

## Usage

Put `[com.holychao/parallel-test "0.3.1"]` into the `:plugins` vector of your project.clj.
Put `[com.holychao/parallel-test "0.3.2"]` into the `:plugins` vector of your project.clj.

$ lein parallel-test

Expand Down Expand Up @@ -65,6 +65,8 @@ parallel. The default sequencing configuration is:

## Caveats

Parallel-test requires Clojure 1.5 or greater.

Running tests in parallel means exactly that; parallel-test does not
tackle the subjects of isolation or concurrent access for you. If your
tests or their fixtures make use of resources such as global
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.holychao/parallel-test "0.3.1"
(defproject com.holychao/parallel-test "0.3.2"
:description "Executes tests in parallel."
:url "http://github.com/aredington/parallel-test"
:license {:name "EPL"
Expand Down
2 changes: 1 addition & 1 deletion src/com/holychao/parallel_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns com.holychao.parallel-test)

(def VERSION "0.3.1")
(def VERSION "0.3.2")

(def ^:dynamic *category*
"Var holding the current category while tests are being run."
Expand Down
29 changes: 22 additions & 7 deletions src/leiningen/parallel_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Run the project's tests in parallel."
(:refer-clojure :exclude [test])
(:require [clojure.java.io :as io]
[clojure.set :as set]
[bultitude.core :as b]
[leiningen.core.eval :as eval]
[leiningen.core.main :as main]
Expand All @@ -17,10 +18,10 @@
:parallel (fn [] (.availableProcessors (Runtime/getRuntime)))}
:sequence [:serial]})

(def ^:private parallel-test-profile
{:dependencies [['org.clojure/core.async "0.2.395"]
['com.holychao/parallel-test ptest/VERSION]
['robert/hooke "1.3.0"]]})
(def ^:private parallel-test-dependencies
{'org.clojure/core.async "0.4.474"
'com.holychao/parallel-test ptest/VERSION
'robert/hooke "1.3.0"})

;; TODO: make this an arg to form-for-testing-namespaces in 3.0.
(def ^:private ^:dynamic *monkeypatch?* true)
Expand Down Expand Up @@ -93,6 +94,18 @@ namespace and print an overall summary."
(main/abort "Please specify :test-selectors in project.clj"))
[nses selectors]))

(defn ensure-ptest-deps
"Ensure that deps holds SOME version of the libraries required by
parallel-test. This always yields primacy to the project.clj, but if
e.g. core.async is missing, it'll slot in the default version the
plugin defines."
[deps]
(let [missing-deps (->> deps
(map first)
set
(set/difference (set (keys parallel-test-dependencies))))]
(into deps (select-keys parallel-test-dependencies missing-deps))))

(defn parallel-test
"Run the project's tests in parallel."
[project & tests]
Expand All @@ -103,10 +116,12 @@ namespace and print an overall summary."
false
*exit-after-tests*)
*monkeypatch?* (:monkeypatch-clojure-test project true)]
(let [profile (or (:parallel-test (:profiles project)) parallel-test-profile)
(let [profile (:parallel-test (:profiles project))
profile-targets (cond-> [:leiningen/test :test]
profile (conj :parallel-test))
project (-> project
(project/add-profiles {:parallel-test profile})
(project/merge-profiles [:leiningen/test :test :parallel-test]))
(project/merge-profiles profile-targets)
(update :dependencies ensure-ptest-deps))
[nses selectors] (read-args tests project)
config (merge default-config
(:parallel-test project))
Expand Down

0 comments on commit 72f21fb

Please sign in to comment.