Skip to content

Commit

Permalink
Implement fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Mar 22, 2024
1 parent 316a49d commit 25f9272
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/kaocha/type/ns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
(defn run-tests [testable test-plan fixture-fn]
;; It's not guaranteed the the fixture-fn returns the result of calling the
;; tests function, so we need to put it in a box for reference.
(let [result (atom (:kaocha.test-plan/tests testable))]
(fixture-fn #(swap! result testable/run-testables test-plan))
(let [testables (:kaocha.test-plan/tests testable)
result (atom [])]
(fixture-fn #(let [test-result (testable/run-testables testables test-plan)]
(swap! result into test-result)))
@result))

(defmethod testable/-load :kaocha.type/ns [testable]
Expand Down
60 changes: 40 additions & 20 deletions test/unit/kaocha/fixtures_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,50 @@
(require 'ddd.double-once-fixture-test)
(let [{:keys [result report]}
(with-test-ctx {:fail-fast? false}
(testable/run {:kaocha.testable/type :kaocha.type/var
:kaocha.testable/id :ddd.double-once-fixture-test/example-fail-test
:kaocha.testable/desc "example-fail-test"
:kaocha.var/name 'ddd.double-once-fixture-test/example-fail-test
:kaocha.var/var (resolve 'ddd.double-once-fixture-test/example-fail-test)
:kaocha.var/test (-> (resolve 'ddd.double-once-fixture-test/example-fail-test) meta :test)}
(testable/run (testable/load {:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :ddd.double-once-fixture-test
:kaocha.testable/desc "ddd.double-once-fixture-test"
:kaocha.ns/name 'ddd.double-once-fixture-test})
(f/test-plan {})))]

(is (match? {:kaocha.testable/type :kaocha.type/var
:kaocha.testable/id :ddd.double-once-fixture-test/example-fail-test
:kaocha.testable/desc "example-fail-test"
:kaocha.var/name 'ddd.double-once-fixture-test/example-fail-test
:kaocha.var/var (resolve 'ddd.double-once-fixture-test/example-fail-test)
:kaocha.var/test fn?
:kaocha.result/count 1
:kaocha.result/pass 0
:kaocha.result/error 0
:kaocha.result/fail 1}
(is (match? {:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :ddd.double-once-fixture-test
:kaocha.testable/desc "ddd.double-once-fixture-test"
:kaocha.result/tests
[{:kaocha.testable/type :kaocha.type/var
:kaocha.testable/id :ddd.double-once-fixture-test/example-fail-test
:kaocha.testable/desc "example-fail-test"
:kaocha.var/name 'ddd.double-once-fixture-test/example-fail-test
:kaocha.var/var (resolve 'ddd.double-once-fixture-test/example-fail-test)
:kaocha.var/test fn?
:kaocha.result/count 1
:kaocha.result/pass 0
:kaocha.result/error 0
:kaocha.result/fail 1}
{:kaocha.testable/type :kaocha.type/var
:kaocha.testable/id :ddd.double-once-fixture-test/example-fail-test
:kaocha.testable/desc "example-fail-test"
:kaocha.var/name 'ddd.double-once-fixture-test/example-fail-test
:kaocha.var/var (resolve 'ddd.double-once-fixture-test/example-fail-test)
:kaocha.var/test fn?
:kaocha.result/count 1
:kaocha.result/pass 1
:kaocha.result/error 0
:kaocha.result/fail 0}]}
result))

(is (match? [{:type :begin-test-var}
{:type :pass
(is (match? [{:type :begin-test-ns}
{:type :begin-test-var}
{:type :fail
:expected '(= 1 2)
:actual '(not (= 1 2))
:message nil}
{:type :end-test-var}]
report)))))
{:type :end-test-var}
{:type :begin-test-var}
{:type :pass
:expected '(= 2 2)
:actual '(= 2 2)
:message nil}
{:type :end-test-var}
{:type :end-test-ns}]
(mapv #(select-keys % [:type :expected :actual :message]) report))))))

0 comments on commit 25f9272

Please sign in to comment.