Skip to content

Fix test-seq{-with-skipped} with {root,nested} testable #451

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
## Fixed

- Fix beholder watch functionality that would cause a NullPointerException earlier.
- Fix `kaocha.testable/test-seq` not respecting `:kaocha.testable/skip` on root testable
- Fix `kaocha.testable/test-seq-with-skipped` omitting skipped tests on nested testables

## Changed

Expand Down
28 changes: 15 additions & 13 deletions src/kaocha/testable.clj
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,24 @@
result))))

(defn test-seq [testable]
(cond->> (mapcat test-seq (remove ::skip (or (:kaocha/tests testable)
(:kaocha.test-plan/tests testable)
(:kaocha.result/tests testable))))
;; When calling test-seq on the top level test-plan/result, don't include
;; the outer map. When running on an actual testable, do include it.
(:kaocha.testable/id testable)
(cons testable)))
(if (::skip testable)
()
(cond->> (mapcat test-seq (or (:kaocha/tests testable)
(:kaocha.test-plan/tests testable)
(:kaocha.result/tests testable)))
;; When calling test-seq on the top level test-plan/result, don't include
;; the outer map. When running on an actual testable, do include it.
(:kaocha.testable/id testable)
(cons testable))))

(defn test-seq-with-skipped
[testable]
"Create a seq of all tests, including any skipped tests.
"Create a seq of all tests, including any skipped tests.

Typically you want to look at `test-seq` instead."
(cond->> (mapcat test-seq (or (:kaocha/tests testable)
(:kaocha.test-plan/tests testable)
(:kaocha.result/tests testable)))
Typically you want to look at `test-seq` instead."
[testable]
(cond->> (mapcat test-seq-with-skipped (or (:kaocha/tests testable)
(:kaocha.test-plan/tests testable)
(:kaocha.result/tests testable)))
;; When calling test-seq on the top level test-plan/result, don't include
;; the outer map. When running on an actual testable, do include it.
(:kaocha.testable/id testable)
Expand Down
86 changes: 76 additions & 10 deletions test/unit/kaocha/testable_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,80 @@
:kaocha.testable/desc "foo"}
(f/test-plan {})))))


(deftest test-seq-test
(is (= (testable/test-seq
{:kaocha.testable/id :x/_1
:kaocha/tests [{:kaocha.testable/id :y/_1}
{:kaocha.testable/id :z/_1}]})
[{:kaocha.testable/id :x/_1,
:kaocha/tests [#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}]}
#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}])))
(testing "no skipped tests"
(is (= (testable/test-seq
{:kaocha.testable/id :x/_1
:kaocha/tests [{:kaocha.testable/id :y/_1}
{:kaocha.testable/id :z/_1}]})
[{:kaocha.testable/id :x/_1,
:kaocha/tests [#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}]}
#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}])))
(testing "top level test-plan/result is ignored"
(is (= (testable/test-seq
{:kaocha/tests [{:kaocha.testable/id :y/_1}
{:kaocha.testable/id :z/_1}]})
[#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}])))
(testing "skipped root testable"
(is (= (testable/test-seq
{:kaocha.testable/id :x/_1
:kaocha.testable/skip true
:kaocha/tests [{:kaocha.testable/id :y/_1}
{:kaocha.testable/id :z/_1}]})
[])))
(testing "skipped nested testable"
(is (= (testable/test-seq
{:kaocha.testable/id :x/_1
:kaocha/tests [{:kaocha.testable/id :y/_1
:kaocha.testable/skip true}
{:kaocha.testable/id :z/_1}]})
[{:kaocha.testable/id :x/_1,
:kaocha/tests [#:kaocha.testable{:id :y/_1
:skip true}
#:kaocha.testable{:id :z/_1}]}
#:kaocha.testable{:id :z/_1}]))))

(deftest test-seq-with-skipped-test
(testing "no skipped tests"
(is (= (testable/test-seq-with-skipped
{:kaocha.testable/id :x/_1
:kaocha/tests [{:kaocha.testable/id :y/_1}
{:kaocha.testable/id :z/_1}]})
[{:kaocha.testable/id :x/_1,
:kaocha/tests [#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}]}
#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}])))
(testing "top level test-plan/result is ignored"
(is (= (testable/test-seq-with-skipped
{:kaocha/tests [{:kaocha.testable/id :y/_1}
{:kaocha.testable/id :z/_1}]})
[#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}])))
(testing "skipped outer testable"
(is (= (testable/test-seq-with-skipped
{:kaocha.testable/id :x/_1
:kaocha.testable/skip true
:kaocha/tests [{:kaocha.testable/id :y/_1}
{:kaocha.testable/id :z/_1}]})
[{:kaocha.testable/id :x/_1,
:kaocha.testable/skip true
:kaocha/tests [#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}]}
#:kaocha.testable{:id :y/_1}
#:kaocha.testable{:id :z/_1}])))
(testing "skipped nested testable"
(is (= (testable/test-seq-with-skipped
{:kaocha.testable/id :x/_1
:kaocha/tests [{:kaocha.testable/id :y/_1
:kaocha.testable/skip true}
{:kaocha.testable/id :z/_1}]})
[{:kaocha.testable/id :x/_1,
:kaocha/tests
[#:kaocha.testable{:id :y/_1, :skip true}
#:kaocha.testable{:id :z/_1}]}
#:kaocha.testable{:id :y/_1, :skip true}
#:kaocha.testable{:id :z/_1}]))))
Loading