Fork me on GitHub
#clojure
<
2018-07-10
>
roklenarcic13:07:27

Anyone using Specter? How does one make something like clojure.walk, e.g. I want to walk a datastructure and swap all sequences for vectors

jsa-aerial21:07:53

I believe this will do the job in Specter - but may want to ask in #specter if this isn't sufficient for your purposes

jjttjj13:07:47

not specter but you could do this:

(clojure.walk/postwalk
 #(if (seq? %)
    (vec %)
    %)
 [1 2 '(3 4 5) {:x '(6 7 8)}])
;;=>
;;[1 2 [3 4 5] {:x [6 7 8]}]

cpmcdaniel13:07:46

what is the best way to run a unit test many many times?

cpmcdaniel13:07:52

looking for an easy way to do this from the repl

yogsototh14:07:50

(while true (run-all-test))

yogsototh14:07:23

aren't you looking for generative testing instead?

cpmcdaniel14:07:26

but I only want 1 specific test to run

yogsototh14:07:46

I don't see why you would want to run the same test more than once

dpsutton14:07:04

do you want it to run constantly as you're editing code to see it turn green as your code?

cpmcdaniel14:07:06

it’s a bit more of an integration test really

cpmcdaniel14:07:16

and there is apparently a race condition somewhere

cpmcdaniel14:07:28

no, it’s a flaky test

cpmcdaniel14:07:32

fails very rarely

yogsototh14:07:54

ah I see now.

yogsototh14:07:13

I'm not sure (while (my-test-fn) :another-try)

yogsototh14:07:29

or something similar maybe

yogsototh14:07:42

up until it fails

cpmcdaniel14:07:59

I might need something like (while (my-fixture my-test-fn) :another-try)

cpmcdaniel14:07:44

hmmm… (my-fixture my-test-fn) returns nil

cpmcdaniel14:07:21

apparently the deftest macro does not return the value of the last expression

yogsototh14:07:20

ah yes you shouldn't use the deftest name, unfortunately you'll need to use a temporary intermediate fn

yogsototh14:07:49

(defn my-test-fn ...) (deftest my-test (my-test-fn))

noisesmith15:07:21

@cpmcdaniel to run a test with all applicable fixtures, use clojure.test/test-var

=> (clojure.repl/doc clojure.test/test-var)
-------------------------
clojure.test/test-var
([v])
  If v has a function in its :test metadata, calls that function,
  with *testing-vars* bound to (conj *testing-vars* v).
nil

noisesmith15:07:01

also, for flaky tests, I am fond of making a fixture like (defn flake-fixture [f] (dotimes [n 1000] (println 'run n) (f)))

lilactown17:07:58

is it possible to use Cursive's code formatter outside of cursive?

lilactown17:07:07

slash what do people use for code formatting?

lilactown17:07:57

my team is deciding on a standard formatter - most use Cursive or are switching to Cursive (from Atom), I'm the lone Emacs user 😞

wilkerlucio17:07:32

@lilactown I asked that before, apparently no, seems like is tightly integrated with IntelliJ stuff

😞 4
wilkerlucio17:07:55

I suggest you look at zprint: https://github.com/kkinnear/zprint

👍 4
noisesmith17:07:52

I've had good luck with cljfmt which has editor integration, and lein cljfmt fix can be used in CI to auto-fix indentation and whitespace issues in place

👍 4
lilactown18:07:12

does anyone use cljfmt with parinfer?

jsa-aerial21:07:53

I believe this will do the job in Specter - but may want to ask in #specter if this isn't sufficient for your purposes

jsa-aerial21:07:35

=> {:a [[:x 1] [2 3 4]], :b {:c [4], :d [5], :e [0 1 2 3 4 5 6 7 8 9]}}