diff --git a/.github/workflows/tests-and-checks.yml b/.github/workflows/tests-and-checks.yml index 6fac330..6ac635d 100644 --- a/.github/workflows/tests-and-checks.yml +++ b/.github/workflows/tests-and-checks.yml @@ -44,4 +44,4 @@ jobs: restore-keys: cljdeps- - name: Run Clojure tests - run: bb run test + run: bb run test :all :project diff --git a/bases/test-runner/deps.edn b/bases/test-runner/deps.edn index d024f77..15f8543 100644 --- a/bases/test-runner/deps.edn +++ b/bases/test-runner/deps.edn @@ -5,12 +5,10 @@ ;; those pulled into a workspace when used :aliases {:dev {:extra-deps {polylith/clj-poly {:git/url "https://github.com/polyfy/polylith" - :git/tag "v0.2.18" - :git/sha "e8feb79" + :git/sha "aece34ab40255fd40038abbff79433fdf7cd5759" :deps/root "projects/poly"}}} :test {:extra-paths [] :extra-deps {polylith/clj-poly {:git/url "https://github.com/polyfy/polylith" - :git/tag "v0.2.18" - :git/sha "e8feb79" + :git/sha "aece34ab40255fd40038abbff79433fdf7cd5759" :deps/root "projects/poly"}}}}} diff --git a/components/kaocha-test-runner/src/polylith_kaocha/kaocha_test_runner/bricks_to_test.clj b/components/kaocha-test-runner/src/polylith_kaocha/kaocha_test_runner/bricks_to_test.clj index 6bacfca..59a8270 100644 --- a/components/kaocha-test-runner/src/polylith_kaocha/kaocha_test_runner/bricks_to_test.clj +++ b/components/kaocha-test-runner/src/polylith_kaocha/kaocha_test_runner/bricks_to_test.clj @@ -1,84 +1,68 @@ (ns polylith-kaocha.kaocha-test-runner.bricks-to-test "Copied from polylith.clj.core.change.bricks-to-test, so it doesn't filter out bricks that don't have dedicated test sources." - (:require [clojure.set :as set])) + (:require + [clojure.set :as set] + [polylith.clj.core.common.interface :as common])) -(defn bricks-to-test-for-project [{:keys [is-dev alias name base-names component-names]} - settings - changed-projects - changed-components - changed-bases - project-to-indirect-changes - selected-bricks - selected-projects - is-dev-user-input - is-run-all-brick-tests] +(defn bricks-to-test- + "Copied from polylith. + + At commit https://github.com/polyfy/polylith/blob/00579eefcaaa853ede3275e1c6a3395c1f37710b/components/change/src/polylith/clj/core/change/bricks_to_test.clj#L5 + + Change indicated inline." + [{:keys [is-dev alias name test base-names component-names indirect-changes]} + source + changed-projects + changed-bricks + selected-bricks + selected-projects + is-dev-user-input + is-run-all-brick-tests] (let [include-project? (or (or (contains? selected-projects name) (contains? selected-projects alias)) (and (empty? selected-projects) (or (not is-dev) is-dev-user-input))) project-has-changed? (contains? (set changed-projects) name) - - - ;; - ;; HERE IS THE CHANGE PART 1 - ;; - ;; all-brick-names (into #{} (mapcat :test) [base-names component-names]) - ;; - all-brick-names (into #{} (comp (mapcat vals) cat) [base-names component-names]) - ;; - ;; - ;; END OF CHANGE PART 1 - ;; - - - - ;; If the :test key is given for a project in workspace.edn, then only include - ;; the specified bricks, otherwise, run tests for all bricks that have tests. - included-bricks (if-let [bricks (get-in settings [:projects name :test :include])] - (set/intersection all-brick-names (set bricks)) - all-brick-names) + ;; change + ;; we need to consider all referenced bricks as Kaocha might discover tests in src-only bricks too + bricks-for-source (into #{} (comp (mapcat vals) cat) [base-names component-names]) + ;; end change + included-bricks (common/brick-names-to-test test bricks-for-source) selected-bricks (if selected-bricks (set selected-bricks) - all-brick-names) + bricks-for-source) changed-bricks (if include-project? (if (or is-run-all-brick-tests project-has-changed?) - ;; if we pass in :all or :all-bricks or if the project has changed - ;; then always run all brick tests. included-bricks (set/intersection included-bricks selected-bricks (into #{} cat - [changed-components - changed-bases - (-> name project-to-indirect-changes :src) - (-> name project-to-indirect-changes :test)]))) - #{}) - ;; And finally, if brick:BRICK is given, also filter on that, which means that if we - ;; pass in both brick:BRICK and :all, we will run the tests for all these bricks, - ;; whether they have changed or not (directly or indirectly). - bricks-to-test (set/intersection changed-bricks selected-bricks)] - + [changed-bricks (source indirect-changes)]))) + #{})] + (set/intersection changed-bricks selected-bricks))) - ;; - ;; HERE IS THE CHANGE PART 2 - ;; - ;; WE ONLY NEED A SET THAT REPRESENTS THE PROJECT'S BRICKS TO TEST - ;; - bricks-to-test - ;; - ;; END OF CHANGE PART 2 - ;; - )) +(defn ensure-at-least-0-2-19 + "The function bricks-to-test- operates on >=0.2.19-snapshot data so older projects need to be patched." + [project settings] + (cond-> project + (not (contains? project :test)) + (assoc :test (get-in settings [:projects (:name project) :test])))) (defn bricks-to-test + "Copied from polylith. + + At commit https://github.com/polyfy/polylith/blob/00579eefcaaa853ede3275e1c6a3395c1f37710b/components/change/src/polylith/clj/core/change/bricks_to_test.clj#L49 + + Changes: + - not associng into project just returning + - less lazy" [project {:keys [changes settings user-input] :as _workspace}] - (let [{:keys [is-dev is-run-all-brick-tests selected-bricks selected-projects]} user-input - {:keys [changed-components - changed-bases - changed-projects - project-to-indirect-changes]} changes] - (bricks-to-test-for-project - project settings changed-projects changed-components changed-bases - project-to-indirect-changes selected-bricks selected-projects is-dev - is-run-all-brick-tests))) + (let [project (ensure-at-least-0-2-19 project settings) + {:keys [is-dev is-run-all-brick-tests selected-bricks selected-projects]} user-input + {:keys [changed-components changed-bases changed-projects]} changes] + (-> #{} + (into (bricks-to-test- project :src changed-projects changed-bases selected-bricks selected-projects is-dev is-run-all-brick-tests)) + (into (bricks-to-test- project :src changed-projects changed-components selected-bricks selected-projects is-dev is-run-all-brick-tests)) + (into (bricks-to-test- project :test changed-projects changed-bases selected-bricks selected-projects is-dev is-run-all-brick-tests)) + (into (bricks-to-test- project :test changed-projects changed-components selected-bricks selected-projects is-dev is-run-all-brick-tests))))) diff --git a/components/kaocha-test-runner/src/polylith_kaocha/kaocha_test_runner/core.clj b/components/kaocha-test-runner/src/polylith_kaocha/kaocha_test_runner/core.clj index 673adb9..c4e72a5 100644 --- a/components/kaocha-test-runner/src/polylith_kaocha/kaocha_test_runner/core.clj +++ b/components/kaocha-test-runner/src/polylith_kaocha/kaocha_test_runner/core.clj @@ -40,11 +40,16 @@ "is NOT considered for Kaocha's test discovery") (->> (verbose-println runner-opts "Path" path))))))) +(defn project-to-test-0-2-19 + [{:keys [name projects-to-test] :as _project} + {:keys [project-to-projects-to-test] :as _changes}] + (or projects-to-test ;; poly version > 0.2.18 + (project-to-projects-to-test name) ;; poly version up to 0.2.18 + )) + (defn path-of-project-to-test?-fn [{:keys [project changes] :as _runner-opts}] - (let [{:keys [name]} project - {:keys [project-to-projects-to-test]} changes - projects-to-test (set (project-to-projects-to-test name))] + (let [projects-to-test (set (project-to-test-0-2-19 project changes))] (fn path-of-project-to-test? [path] (->> path (re-find #"^projects/([^/]+)") diff --git a/components/kaocha-test-runner/test/polylith_kaocha/kaocha_test_runner/bricks_to_test_test.clj b/components/kaocha-test-runner/test/polylith_kaocha/kaocha_test_runner/bricks_to_test_test.clj new file mode 100644 index 0000000..81b1c45 --- /dev/null +++ b/components/kaocha-test-runner/test/polylith_kaocha/kaocha_test_runner/bricks_to_test_test.clj @@ -0,0 +1,150 @@ +(ns polylith-kaocha.kaocha-test-runner.bricks-to-test-test + (:require + [clojure.test :refer :all] + [polylith-kaocha.kaocha-test-runner.bricks-to-test :as sut])) + +(deftest + ^{:doc "Regression test. + Extracted from a run of `clojure -Srepro -M:poly test` at https://github.com/imrekoszo/polylith-kaocha-issue-repro/tree/f16f3a4e58d61c3e916bada6736fafbb1d45cff7"} + bricks-to-test-test + (let [args-0-2-18 + [{:base-names {:src ["d"], :test ["d"]}, + :is-dev false, + :name "p", + :type "project", + :alias "p", + :component-names {:src ["a" "b" "c" "s"], :test ["a" "b" "c"]}, + :deps {"d" {:src {:direct ["a" "b" "c" "s"]}, :test {:direct ["a" "b" "c" "s"]}}, + "a" {:src {:direct ["b"]}, :test {:direct ["b"]}}, + "b" {:src {}, :test {}}, + "c" {:src {}, :test {}}, + "s" {:src {}, :test {}}}} + {:user-input {:is-dev false, :is-run-all-brick-tests false, :selected-projects #{}}, + :settings {:projects {"development" {:alias "dev", :test #:polylith-kaocha{:config-resource "tests.edn"}}, + "p" {:alias "p", :test #:polylith-kaocha{:config-resource "tests.edn"}}, + "r" {:alias "r", :test #:polylith-kaocha{:config-resource "tests.edn"}}}}, + :changes {:changed-components ["a" "s"], + :changed-bases [], + :changed-projects ["development" "p" "r"], + :project-to-indirect-changes {"p" {:src ["d"], :test ["d"]}, + "r" {:src [], :test []}, + "development" {:src ["d"], :test ["d"]}}}}] + + args-0-2-19 + [{:base-names {:src ["d"], :test ["d"]}, + :is-dev false, + :name "p", + :indirect-changes {:src ["d"], :test ["d"]}, + :alias "p", + :projects-to-test [], + :component-names {:src ["a" "b" "c" "s"], :test ["a" "b" "c"]}, + :test #:polylith-kaocha{:config-resource "tests.edn"}, + :bricks-to-test ["a" "b" "c" "d"],} + {:projects [{:base-names {:src ["d"], :test ["d"]}, + :is-dev false, + :name "p", + :type "project", + :indirect-changes {:src ["d"], :test ["d"]}, + :alias "p", + :projects-to-test [], + :component-names {:src ["a" "b" "c" "s"], :test ["a" "b" "c"]}, + :test #:polylith-kaocha{:config-resource "tests.edn"}, + :bricks-to-test ["a" "b" "c" "d"],} + {:base-names {}, + :is-dev false, + :name "r", + :type "project", + :indirect-changes {:src [], :test []}, + :alias "r", + :projects-to-test [], + :component-names {:src ["c"], :test ["c"]}, + :test #:polylith-kaocha{:config-resource "tests.edn"}, + :bricks-to-test ["c"]} + {:base-names {:src ["d"], :test ["d"]}, + :is-dev true, + :name "development", + :type "project", + :indirect-changes {:src ["d"], :test ["d"]}, + :alias "dev", + :projects-to-test [], + :component-names {:src ["a" "b" "c" "s"], :test ["a" "b" "c"]}, + :test #:polylith-kaocha{:config-resource "tests.edn"}, + :bricks-to-test []}], + :user-input {:args ["test"], + :unnamed-args [], + :is-dev false, + :is-commit false, + :is-run-project-tests false, + :is-compact false, + :is-run-all-brick-tests false, + :is-fake-poly false, + :is-verbose false, + :is-latest-sha false, + :selected-projects #{}, + :is-update false, + :is-github false, + :is-no-changes false, + :is-search-for-ws-dir false, + :is-swap-axes false, + :is-outdated false, + :is-local false, + :is-show-brick false, + :is-show-resources false, + :selected-profiles #{}, + :cmd "test", + :is-show-project false, + :is-all false, + :is-show-workspace false, + :is-tap false, + :is-show-loc false, + :is-no-exit false}, + :settings {:top-namespace "fun", + :default-profile-name "default", + :thousand-separator ",", + :compact-views #{}, + :active-profiles #{}, + :interface-ns "interface", + :tag-patterns {:stable "stable-*", :release "v[0-9]*"}, + :color-mode "dark", + :empty-character "."}, + :ws-type "toolsdeps2", + :changes {:since "stable", + :changed-projects ["development" "p" "r"], + :changed-bases [], + :since-sha "46bcf2c0c7eebfc54c074d43290a81d14d2da614", + :changed-files [".gitignore" + "components/a/src/fun/a/interface.clj" + "components/s/src/fun/s/interface.clj" + "deps.edn" + "development/config.edn" + "projects/p/config.edn" + "projects/p/deps.edn" + "projects/r/config.edn" + "projects/r/deps.edn" + "workspace.edn"], + :git-diff-command "git diff 46bcf2c0c7eebfc54c074d43290a81d14d2da614 --name-only", + :changed-components ["a" "s"], + :since-tag "stable-3", + :changed-or-affected-projects ["development" "p" "r"]}, + :profiles []}]] + (testing "bricks that do not have test files are also selected" + (let [expected #{"d" "s" "a" "b" "c"}] + + (testing "up to poly v0.2.18" + (is (= expected (apply sut/bricks-to-test args-0-2-18)))) + + (testing "from poly v0.2.19" + (is (= expected (apply sut/bricks-to-test args-0-2-19)))))) + + (testing "include bricks" + (let [expected #{"b" "c"}] + + (testing "up to poly v0.2.18" + (let [with-include #(assoc-in % [1 :settings :projects "p" :test :include] ["b" "c"])] + (is (= expected + (apply sut/bricks-to-test (with-include args-0-2-18)))))) + + (testing "from poly v0.2.19" + (let [with-include #(assoc-in % [0 :test :include] ["b" "c"])] + (is (= expected + (apply sut/bricks-to-test (with-include args-0-2-19)))))))))) diff --git a/deps.edn b/deps.edn index 78c7582..0a9342a 100644 --- a/deps.edn +++ b/deps.edn @@ -1,15 +1,5 @@ {:aliases - {:dev {:extra-paths ["development/src" - - ;; poly modules workaround for Cursive, https://github.com/cursive-ide/cursive/issues/2554 - "bases/example/src" - "bases/test-runner/src" - "components/kaocha-resource-config-loader/resources" - "components/kaocha-resource-config-loader/src" - "components/kaocha-test-runner/src" - "components/kaocha-wrapper/resources" - "components/kaocha-wrapper/src" - "components/util/src"] + {:dev {:extra-paths ["development/src"] :extra-deps {org.clojure/clojure {:mvn/version "1.11.1"} ;; poly modules @@ -35,8 +25,7 @@ :extra-paths ["development/poly"] :extra-deps {polylith/clj-poly {:git/url "https://github.com/polyfy/polylith" - :git/tag "v0.2.18" - :git/sha "e8feb79" + :git/sha "aece34ab40255fd40038abbff79433fdf7cd5759" :deps/root "projects/poly"} polylith-kaocha/test-runner diff --git a/development/config.edn b/development/config.edn new file mode 100644 index 0000000..8643092 --- /dev/null +++ b/development/config.edn @@ -0,0 +1 @@ +{:alias "dev"} diff --git a/projects/example/config.edn b/projects/example/config.edn new file mode 100644 index 0000000..344ba46 --- /dev/null +++ b/projects/example/config.edn @@ -0,0 +1,10 @@ +{:alias "ex" + :test {;; must be available on the project's classpath + :polylith-kaocha/config-resource "polylith-kaocha/example/tests.edn" + :polylith-kaocha.kaocha-wrapper/post-load-config polylith-kaocha.example.hooks/post-load-config + :polylith-kaocha.kaocha-wrapper/post-enhance-config polylith-kaocha.example.hooks/post-enhance-config + :polylith-kaocha/tests-present? polylith-kaocha.example.hooks/tests-present? + :polylith-kaocha/run-tests polylith-kaocha.example.hooks/run-tests + + ;; must be available on the poly tool's classpath + :polylith-kaocha/runner-opts->kaocha-poly-opts polylith-kaocha.hooks/runner-opts->kaocha-poly-opts}} diff --git a/projects/kaocha-wrapper/config.edn b/projects/kaocha-wrapper/config.edn new file mode 100644 index 0000000..8df404d --- /dev/null +++ b/projects/kaocha-wrapper/config.edn @@ -0,0 +1 @@ +{:alias "kw"} diff --git a/projects/test-runner/config.edn b/projects/test-runner/config.edn new file mode 100644 index 0000000..8829892 --- /dev/null +++ b/projects/test-runner/config.edn @@ -0,0 +1 @@ +{:alias "tr"} diff --git a/readme.md b/readme.md index 27002e1..e8c7b5d 100644 --- a/readme.md +++ b/readme.md @@ -24,7 +24,7 @@ Alpha software. While breaking changes are not planned at this point, they shoul ## Usage -For deps coordinates, see the [Releases](https://github.com/imrekoszo/polylith-kaocha/releases) page. +For deps coordinates, see the [Releases](https://github.com/imrekoszo/polylith-kaocha/releases) page. This section assumes that at least `v0.2.19-SNAPSHOT (aece34ab40255fd40038abbff79433fdf7cd5759)` of the poly tool is used. To set polylith-kaocha up with an older version of the poly tool, please see the docs at `v0.8.3` of polylith-kaocha. ### 1. Add dep to :poly alias @@ -40,8 +40,7 @@ includes [pluggable test runner support](https://github.com/polyfy/polylith/pull {:extra-deps {polylith/clj-poly {:git/url "https://github.com/polyfy/polylith" - :git/tag "v0.2.18" - :git/sha "e8feb79" + :git/sha "aece34ab40255fd40038abbff79433fdf7cd5759" :deps/root "projects/poly"} polylith-kaocha/test-runner @@ -53,29 +52,28 @@ includes [pluggable test runner support](https://github.com/polyfy/polylith/pull } ``` -### 2. Reference in workspace config +### 2. Reference in workspace/project config After which you can configure your projects to be tested with it -in `workspace.edn`: +in `workspace.edn` and/or individual project `config.edn`-s: ```clojure -{ +;; To use it as the default test runner in the workspace +;; +;; In workspace.edn: +{:test {:create-test-runner polylith-kaocha.test-runner/create}} - ;; To use it as the default test runner in the workspace - :test {:create-test-runner polylith-kaocha.test-runner/create} - :projects - { - ;; To only use it for specific projects - "foo" {:test {:create-test-runner polylith-kaocha.test-runner/create}} +;; In project config.edn files: - ;; To revert to the default test runner only for specific projects - "bar" {:test {:create-test-runner :default}} +;; To only use it for specific projects +{:test {:create-test-runner polylith-kaocha.test-runner/create}} - ;; To use it in addition to the default test runner - "baz" {:test {:create-test-runner [:default polylith-kaocha.test-runner/create]}} - } - } +;; To revert to the default test runner only for specific projects +{:test {:create-test-runner :default}} + +;; To use it in addition to the default test runner +{:test {:create-test-runner [:default polylith-kaocha.test-runner/create]}} ``` ### 3. Add kaocha wrapper dep to affected projects @@ -124,17 +122,14 @@ Out of the box this applies the default Kaocha configuration which at this time is to run `clojure.test` tests. There are a few options to change this. All the following settings can either be applied to the entire workspace, or -specific projects by adding them to `workspace.edn`: +specific projects by adding them to configuration: ```clojure -{ - :test {;; here to apply them to the entire workspace - } +;; In workspace.edn to make them apply to the entire workspace +;; In project config.edn files to apply them to specific projects - :projects - {"foo" {:test {;; here to apply to specific projects - }}} - } +{:test {;; here + }} ``` #### Kaocha configuration diff --git a/workspace.edn b/workspace.edn index 336c188..a59b5fc 100644 --- a/workspace.edn +++ b/workspace.edn @@ -8,24 +8,4 @@ :release "v[0-9]*"} :test {:create-test-runner [:default polylith-kaocha.test-runner/create - #_polylith-kaocha.reload-runner/create]} - :projects {"development" - {:alias "dev"} - - "example" - {:alias "ex" - :test {;; must be available on the project's classpath - :polylith-kaocha/config-resource "polylith-kaocha/example/tests.edn" - :polylith-kaocha.kaocha-wrapper/post-load-config polylith-kaocha.example.hooks/post-load-config - :polylith-kaocha.kaocha-wrapper/post-enhance-config polylith-kaocha.example.hooks/post-enhance-config - :polylith-kaocha/tests-present? polylith-kaocha.example.hooks/tests-present? - :polylith-kaocha/run-tests polylith-kaocha.example.hooks/run-tests - - ;; must be available on the poly tool's classpath - :polylith-kaocha/runner-opts->kaocha-poly-opts polylith-kaocha.hooks/runner-opts->kaocha-poly-opts}} - - "kaocha-wrapper" - {:alias "kw"} - - "test-runner" - {:alias "tr"}}} + #_polylith-kaocha.reload-runner/create]}}