Fork me on GitHub
#hyperfiddle
<
2022-08-11
>
Eugen22:08:14

hi, thanks for rcf ! . Some feedback: more documentation, for noobs as well. I got lucky and found https://github.com/hyperfiddle/rcf/issues/53 quite fast

Dustin Getz22:08:04

will add lein instructions to the readme. hope to publish a new build soon as well, master is stable

๐ŸŽ‰ 2
Eugen22:08:52

looking forward to it

Eugen22:08:53

is this the right way to do multiple tests on a value?

(let [m (->month-names RO)]
   (count m) := 12
   (first m) := "Ianuarie")
clj-kondo complains about := with "redundant expression"

Dustin Getz22:08:58

it's correct, maybe someone can contribute a kondo rule

Dustin Getz22:08:21

you can also use def or *1

Eugen22:08:52

thanks, I have not reached the level of kondo rules... yet

Eugen22:08:26

I could use those but for a noob that seems a bit like magic

Eugen22:08:55

it also takes the code locality away a bit

Eugen22:08:09

if it's not too much to ask, I think that the above (multiple tests on a value) can also make it to the docs.

Eugen22:08:37

or I can try to add it ?!

๐Ÿ‘ 1
Dustin Getz23:08:32

you can send a PR that adds an example to the readme if you want

h0bbit12:06:10

I have added a PR to remove the warning around := here: https://github.com/hyperfiddle/rcf/pull/77

Dustin Getz12:06:09

@U051S5XR3 can you post here a concrete example you are using to test?

Dustin Getz12:06:52

I.e. this seems a bit nuanced, in (tests (def a 1) a := 1) is 1 also considered unused by kondo? is a?

h0bbit12:06:52

a is considered unused here

h0bbit12:06:49

I have to go AFK at the moment, but I will test this against a repl and update here later in the night. Yea, this PR removes the warnings for all unused values, but I thought it was a decent compromise. Linting it using other means seems much more complicated.

Dustin Getz13:06:35

I'll ping borkdude to validate but i want to make sure I understand the exact pain point you're solving first

Dustin Getz13:06:46

so it is not just := but also a

h0bbit04:06:49

Okay, so I looked into it some more today

h0bbit04:06:40

The definition of :unused-value in the documentation is: _Description:_ warn on unused value: constants, unrealized lazy values, pure functions and transient ops (assoc!, conj! etc).

h0bbit04:06:46

without any clj-kondo config, if I have the following code:

(rcf/tests
 "Ensure connection"
 (start-pool! *test-data-source*) := nil
 *test-data-source* := nil
 (start-pool! *test-data-source*) *test-data-source* := nil

 "Drop existing test table, if any"
 (-> *test-data-source*
     (jdbc/execute-one! ["drop table if exists invoice"])
     keys)
 := '(:next.jdbc/update-count))
^ no linting error or warning is thrown here. nothing is considered unused

h0bbit04:06:41

but if I put this in a let binding:

(ns temp
  (:require
   [hyperfiddle.rcf :as rcf]
   [next.jdbc :as jdbc]))

(defn start-pool!
  [data-source]
  (with-open [conn (jdbc/get-connection data-source)]
    (.close conn)))

(rcf/tests
 (let [*test-data-source* {:dbtype "sqlite"
                           :dbname "development/db/testing.sqlite"
                           :dataSourceProperties {:socketTimeout 30}}]
   "Ensure connection"
   (start-pool! *test-data-source*) := nil
   *test-data-source* := nil
   (start-pool! *test-data-source*) *test-data-source* := nil

   "Drop existing test table, if any"
   (-> *test-data-source*
       (jdbc/execute-one! ["drop table if exists invoice"])
       keys)
   := '(:next.jdbc/update-count)))
every constant is an unused value:
15   4 warning         Unused value: "Ensure connection" (clj-kondo-clj)
           16  37 warning         Unused value: := (clj-kondo-clj)
           16  40 warning         Unused value: nil (clj-kondo-clj)
           17   4 warning         Unused value: *test-data-source* (clj-kondo-clj)
           17  23 warning         Unused value: := (clj-kondo-clj)
           17  26 warning         Unused value: nil (clj-kondo-clj)
           18  37 warning         Unused value: *test-data-source* (clj-kondo-clj)
           18  56 warning         Unused value: := (clj-kondo-clj)
           18  59 warning         Unused value: nil (clj-kondo-clj)
           20   4 warning         Unused value: "Drop existing test table, if any" (clj-kondo-clj)
           24   4 warning         Unused value: := (clj-kondo-clj)
(probably because it is not used in the let form, from the point of view of standard Clojure code)

h0bbit04:06:14

With the clj-kondo config I have proposed all these warnings are removed. Even if itโ€™s excessive, I think it is an acceptable linting configuration, since rcf/tests forms are only meant to work during development. Let me know what you think.

h0bbit05:06:46

The pain point is that these warnings mix up with other warnings and leads to everyone ignoring warnings altogether, which is not nice. It should be possible to write tests nested in a let or when or other Clojure forms without clj-kondo blowing up