This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-30
Channels
- # adventofcode (3)
- # announcements (4)
- # babashka (42)
- # beginners (56)
- # biff (23)
- # cider (8)
- # clj-yaml (2)
- # cljdoc (16)
- # clojure (83)
- # clojure-europe (52)
- # clojure-nl (3)
- # clojure-norway (4)
- # clojure-sweden (2)
- # clojure-uk (2)
- # clojurebridge (1)
- # clojurescript (2)
- # cloverage (1)
- # cursive (11)
- # data-oriented-programming (1)
- # deps-new (2)
- # dev-tooling (2)
- # emacs (3)
- # etaoin (4)
- # events (5)
- # fulcro (5)
- # gratitude (3)
- # java (3)
- # jobs (1)
- # jobs-discuss (1)
- # joyride (33)
- # malli (16)
- # music (1)
- # nbb (1)
- # nrepl (4)
- # nyc (1)
- # off-topic (25)
- # pathom (8)
- # re-frame (1)
- # reitit (7)
- # remote-jobs (2)
- # shadow-cljs (6)
- # tools-deps (9)
Q about the test-runner in Cursive: in my current setup a failing test is reported with expected and actual value reversed in comparison to clojure.test
and kaocha
output. Could this be a bug or is it a configuration?
kaocha output:
indeed, im seeing the exact same results. also, for the record, loading this file:
(ns cursive.test-runner-test
(:require [clojure.test :refer :all]))
(deftest expected-actual-order-test
(is (= 2 (+ 3 3))))
(run-test expected-actual-order-test)
results in this REPL output:
Loading test/cursive/test_runner_test.clj...
Testing cursive.test-runner-test
FAIL in (expected-actual-order-test) (test_runner_test.clj:5)
expected: (= 2 (+ 3 3))
actual: (not (= 2 6))
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
Loaded
tried it from the command line too, without any kaocha or matcher combinators being present on the classpath and the result is the same:
❯ time clojure -Srepro -Sdeps '{:paths ["test"]}' -M -e "(require 'cursive.test-runner-test)"
Testing cursive.test-runner-test
FAIL in (expected-actual-order-test) (test_runner_test.clj:5)
expected: (= 2 (+ 3 3))
actual: (not (= 2 6))
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
clojure -Srepro -Sdeps '{:paths ["test"]}' -M -e 0.98s user 0.08s system 80% cpu 1.326 total
so, i agree, it seems, that the built-in cursive reporter explanation is backwards.The thing is that there’s no defined order - kaocha might have a convention, but (is (= x y))
just checks that two things are equal, with no concept of which is expected and which has been calculated. However, that message in the test runner doesn’t come from Cursive so it must be coming from either the IntelliJ test runner or clojure.test - I’ll check. It’s possible I’m swapping the first and second values somewhere.
I was also thinking about where did the convention of the ordering come from.
I think the most authorative suggestion is the docstring of the is
macro:
(defmacro is
"Generic assertion macro. 'form' is any predicate test.
'msg' is an optional message to attach to the assertion.
Example: (is (= 4 (+ 2 2)) "Two plus two should be 4")
...
which is also in-line with tests of Clojure itself, eg:
https://github.com/clojure/clojure/blob/828d82fb5bae9a985f32279b819e22ae436022da/test/clojure/test_clojure/string.clj
though u can see an order reversal here:
https://github.com/clojure/clojure/blob/7b102d84c60ed88d62989d6fd4a6994bd33b3bec/test/clojure/test_clojure/parse.clj#L10-L14
but still, it's been made explicit, that the 1st argument of the predicate within is
is the expected
one.Thank you @U0567Q30W and @U086D6TBN for looking into this . That said, it's not a critical issue so don't feel pressed.
BTW, there is a package for kaocha
, which flips the order of actual and expected:
https://github.com/magnars/kaocha-noyoda
it's mentioned here:
https://github.com/lambdaisland/kaocha/blob/main/README.md?plain=1#L261-L262
Right, I definitely think the order of expected/actual is pretty loosely defined here. I’d have to check, but I’m pretty sure the Cursive diff view uses “Left” and “Right” instead of “Expected” and “Actual”. But I’ll have to figure out where that message is actually coming from first.