Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #9 #11

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-and-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
restore-keys: cljdeps-

- name: Run Clojure tests
run: bb run test
run: bb run test :all :project
6 changes: 2 additions & 4 deletions bases/test-runner/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}}}}
Original file line number Diff line number Diff line change
@@ -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)))))
Original file line number Diff line number Diff line change
Expand Up @@ -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/([^/]+)")
Expand Down
Original file line number Diff line number Diff line change
@@ -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))))))))))
15 changes: 2 additions & 13 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions development/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:alias "dev"}
10 changes: 10 additions & 0 deletions projects/example/config.edn
Original file line number Diff line number Diff line change
@@ -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}}
1 change: 1 addition & 0 deletions projects/kaocha-wrapper/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:alias "kw"}
1 change: 1 addition & 0 deletions projects/test-runner/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:alias "tr"}
Loading
Loading