-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pluggable test runner.
- Loading branch information
Showing
53 changed files
with
1,578 additions
and
855 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{:paths ["src"] | ||
:deps {} | ||
:aliases {:test {:extra-paths [] | ||
:aliases {:test {:extra-paths ["test"] | ||
:extra-deps {}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
99 changes: 99 additions & 0 deletions
99
components/clojure-test-test-runner/src/polylith/clj/core/clojure_test_test_runner/core.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
(ns polylith.clj.core.clojure-test-test-runner.core | ||
(:require [clojure.string :as str] | ||
[polylith.clj.core.test-runner-contract.interface :as test-runner-contract] | ||
[polylith.clj.core.util.interface.color :as color] | ||
[polylith.clj.core.util.interface.str :as str-util])) | ||
|
||
(defn ->test-statement [ns-name] | ||
(let [ns-symbol (symbol ns-name)] | ||
`(do (use 'clojure.test) | ||
(require '~ns-symbol) | ||
(clojure.test/run-tests '~ns-symbol)))) | ||
|
||
(defn brick-test-namespaces [bricks test-brick-names] | ||
(let [brick-name->namespaces (into {} (map (juxt :name #(-> % :namespaces :test))) bricks)] | ||
(into [] | ||
(comp (mapcat brick-name->namespaces) | ||
(map :namespace)) | ||
test-brick-names))) | ||
|
||
(defn project-test-namespaces [project-name projects-to-test namespaces] | ||
(when (contains? (set projects-to-test) project-name) | ||
(mapv :namespace (:test namespaces)))) | ||
|
||
(defn components-msg [component-names color-mode] | ||
(when (seq component-names) | ||
[(color/component (str/join ", " component-names) color-mode)])) | ||
|
||
(defn bases-msg [base-names color-mode] | ||
(when (seq base-names) | ||
[(color/base (str/join ", " base-names) color-mode)])) | ||
|
||
(defn run-message [project-name components bases bricks-to-test projects-to-test color-mode] | ||
(let [component-names (into #{} (map :name) components) | ||
base-names (into #{} (map :name) bases) | ||
bases-to-test (filterv #(contains? base-names %) bricks-to-test) | ||
bases-to-test-msg (bases-msg bases-to-test color-mode) | ||
components-to-test (filterv #(contains? component-names %) bricks-to-test) | ||
components-to-test-msg (components-msg components-to-test color-mode) | ||
projects-to-test-msg (when (seq projects-to-test) | ||
[(color/project (str/join ", " projects-to-test) color-mode)]) | ||
entities-msg (str/join ", " (into [] cat [components-to-test-msg | ||
bases-to-test-msg | ||
projects-to-test-msg])) | ||
project-cnt (count projects-to-test) | ||
bricks-cnt (count bricks-to-test) | ||
project-msg (if (zero? project-cnt) | ||
"" | ||
(str " and " (str-util/count-things "project" project-cnt)))] | ||
(str "Running tests from the " (color/project project-name color-mode) " project, including " | ||
(str-util/count-things "brick" bricks-cnt) project-msg ": " entities-msg))) | ||
|
||
(defn run-test-statements [project-name eval-in-project test-statements run-message is-verbose color-mode] | ||
(println (str run-message)) | ||
(when is-verbose (println (str "# test-statements:\n" test-statements) "\n")) | ||
|
||
(doseq [statement test-statements] | ||
(let [{:keys [error fail pass]} | ||
(try | ||
(eval-in-project statement) | ||
(catch Exception e | ||
(.printStackTrace e) | ||
(println (str (color/error color-mode "Couldn't run test statement") " for the " (color/project project-name color-mode) " project: " statement " " (color/error color-mode e))))) | ||
result-str (str "Test results: " pass " passes, " fail " failures, " error " errors.")] | ||
(when (or (nil? error) | ||
(< 0 error) | ||
(< 0 fail)) | ||
(throw (Exception. (str "\n" (color/error color-mode result-str))))) | ||
(println (str "\n" (color/ok color-mode result-str)))))) | ||
|
||
(defn create | ||
[{:keys [workspace project changes #_test-settings]}] | ||
(let [{:keys [bases components]} workspace | ||
{:keys [name namespaces paths]} project | ||
{:keys [project-to-bricks-to-test project-to-projects-to-test]} changes | ||
|
||
;; TODO: if the project tests aren't to be run, we might further narrow this down | ||
test-sources-present* (delay (-> paths :test seq)) | ||
bricks-to-test* (delay (project-to-bricks-to-test name)) | ||
projects-to-test* (delay (project-to-projects-to-test name)) | ||
test-statements* (->> [(brick-test-namespaces (into components bases) @bricks-to-test*) | ||
(project-test-namespaces name @projects-to-test* namespaces)] | ||
(into [] (comp cat (map ->test-statement))) | ||
(delay))] | ||
|
||
(reify test-runner-contract/TestRunner | ||
(test-runner-name [_] "Polylith built-in clojure.test runner") | ||
|
||
(test-sources-present? [_] @test-sources-present*) | ||
|
||
(tests-present? [this {_eval-in-project :eval-in-project :as _opts}] | ||
(and (test-runner-contract/test-sources-present? this) | ||
(seq @test-statements*))) | ||
|
||
(run-tests [this {:keys [color-mode eval-in-project is-verbose] :as opts}] | ||
(when (test-runner-contract/tests-present? this opts) | ||
(let [run-message (run-message name components bases @bricks-to-test* | ||
@projects-to-test* color-mode)] | ||
(run-test-statements | ||
name eval-in-project @test-statements* run-message is-verbose color-mode))))))) |
5 changes: 5 additions & 0 deletions
5
...nts/clojure-test-test-runner/src/polylith/clj/core/clojure_test_test_runner/interface.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns polylith.clj.core.clojure-test-test-runner.interface | ||
(:require [polylith.clj.core.clojure-test-test-runner.core :as core])) | ||
|
||
(defn create [opts] | ||
(core/create opts)) |
13 changes: 13 additions & 0 deletions
13
...ojure-test-test-runner/test/polylith/clj/core/clojure_test_test_runner/interface_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(ns polylith.clj.core.clojure-test-test-runner.interface-test | ||
(:require | ||
[clojure.test :refer :all] | ||
[polylith.clj.core.clojure-test-test-runner.interface :as sut] | ||
[polylith.clj.core.test-runner-contract.interface.initializers :as test-runner-initializers] | ||
[polylith.clj.core.test-runner-contract.interface.verifiers :as test-runner-verifiers])) | ||
|
||
(deftest clojure-test-test-runner-is-valid | ||
(let [constructor (test-runner-initializers/->constructor-var `sut/create)] | ||
(is (test-runner-verifiers/valid-constructor-var? constructor)) | ||
(let [test-runner (constructor {})] | ||
(is (test-runner-verifiers/valid-test-runner? test-runner)) | ||
(is (test-runner-verifiers/ensure-valid-test-runner test-runner))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
(ns polylith.clj.core.command.test | ||
(:require [polylith.clj.core.test-runner.interface :as test-runner] | ||
[polylith.clj.core.common.interface :as common])) | ||
(:require [polylith.clj.core.common.interface :as common] | ||
[polylith.clj.core.test-runner-orchestrator.interface :as test-runner-orchestrator])) | ||
|
||
(defn run | ||
"Return true if the tests could be executed correctly." | ||
[workspace unnamed-args test-result is-verbose color-mode] | ||
(let [{:keys [ok? message]} (common/validate-args unnamed-args "test project:dev")] | ||
(if ok? | ||
(reset! test-result | ||
(test-runner/run workspace is-verbose color-mode)) | ||
(test-runner-orchestrator/run workspace is-verbose color-mode)) | ||
(println message)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
components/test-helper/src/polylith/clj/core/test_helper/core.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{:paths ["src"] | ||
:deps {} | ||
:aliases {:test {:extra-paths ["test"] | ||
:extra-deps {}}}} |
10 changes: 10 additions & 0 deletions
10
components/test-runner-contract/src/polylith/clj/core/test_runner_contract/initializers.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(ns polylith.clj.core.test-runner-contract.initializers) | ||
|
||
(defn ensure-var [candidate sym] | ||
(when-not (var? candidate) | ||
(throw | ||
(ex-info (str "Unable to resolve symbol " sym " to a var.") {:symbol sym})))) | ||
|
||
(defn ->constructor-var [create-test-runner-sym] | ||
(doto (requiring-resolve create-test-runner-sym) | ||
(ensure-var create-test-runner-sym))) |
Oops, something went wrong.