speculative

https://github.com/borkdude/speculative
slipset 2018-10-23T05:58:34.000100Z

Another interesting side effect of this project is that I’ve always considered Clojure(script) to be rock solid. But when you start poking at the corner cases…

borkdude 2018-10-23T08:34:19.000100Z

made PR for swap!

borkdude 2018-10-23T08:40:42.000100Z

and reset!

slipset 2018-10-23T10:19:24.000100Z

merged.

slipset 2018-10-23T10:19:36.000100Z

I’m a bit hesitant about the cleaning one.

slipset 2018-10-23T10:20:11.000100Z

I’m hesitant to removing :ret specs

slipset 2018-10-23T10:21:13.000100Z

Even though speculative’s raison d’etre isn’t necessarily to test core, :ret doesn’t hurt and it does aid wrt documentation.

slipset 2018-10-23T10:22:06.000100Z

So for = the specs are useless in terms of better error messages, but useful (kind’a sort’a) doc purposes, as the spec is reflected in the docs.

borkdude 2018-10-23T10:24:28.000100Z

@slipset I only removed a :ret any? since this is a bit pointless

borkdude 2018-10-23T10:24:47.000100Z

and removed some stale comments

borkdude 2018-10-23T10:24:54.000100Z

and a duplicate fdef for =

borkdude 2018-10-23T10:25:38.000100Z

https://github.com/slipset/speculative/pull/33/files

borkdude 2018-10-23T10:28:26.000100Z

I first posted some comments about (s/* any?)-ish args specs, but I later removed them

borkdude 2018-10-23T10:34:21.000100Z

if you expand the code a bit, it might be clearer why I removed the = spec 😉

borkdude 2018-10-23T10:36:24.000100Z

if you want I can revert the :ret thing and we can discuss later

slipset 2018-10-23T11:08:02.000100Z

Ah! I see it now. D’oh!

slipset 2018-10-23T11:08:27.000100Z

Thanks for seeing that!

borkdude 2018-10-23T11:09:14.000100Z

👍

borkdude 2018-10-23T15:34:26.000100Z

I wonder how the coal-mine adventure turned out, did it run?

mfikes 2018-10-23T16:38:46.000100Z

I didn't let coal-mine run all the way through to completion, but after about an hour or two it had made it through about half of the problems successfully.

slipset 2018-10-23T16:57:19.000100Z

funny that sets are not associative?

slipset 2018-10-23T16:58:28.000100Z

they’re sort of maps with keys that map onto themselves?

slipset 2018-10-23T17:16:25.000100Z

Found another bug in spec or such which only manifests in planck

slipset 2018-10-23T17:16:42.000100Z

19:13 $ plk -A:test
ClojureScript 1.10.339
cljs.user=> (ns speculative.core
       #_=>   (:require [clojure.spec.alpha :as s]
       #_=>             [clojure.spec.test.alpha :as stest]))
nil
speculative.core=> (s/fdef clojure.core/assoc
              #_=>   :args (s/cat :map (s/nilable associative?) :key any? :val any? :kvs (s/* (s/cat :ks any? :vs any?)))
                                                                                                                                       #_=              #_=>   :ret map?)
cljs.core/assoc
speculative.core=>   (stest/instrument)
Vector's key for assoc must be a number.
	cljs.core/-assoc [cljs.core/IAssociative] (cljs/core.cljs:5546:14)
	cljs.core/-assoc (cljs/core.cljs:630:24)
	cljs.core/apply-to (cljs/core.cljs:3845:1)
	cljs.spec.test.alpha/c (cljs/spec/test/alpha.cljs:120:34)
	cljs.spec.test.alpha/d (cljs/spec/test/alpha.cljs:114:29)
	cljs.core/-assoc [cljs.core/IAssociative] (cljs/core.cljs:6621:6)
	cljs.core/-assoc (cljs/core.cljs:630:24)
	cljs.core/apply-to (cljs/core.cljs:3845:1)
	cljs.spec.test.alpha/c (cljs/spec/test/alpha.cljs:120:34)
	cljs.spec.test.alpha/d (cljs/spec/test/alpha.cljs:114:29)
	cljs/lang/applyTo (cljs/core.cljs:1961:7)
	cljs.spec.test.alpha/f (cljs/spec/test/alpha.cljs:113:16)
	cljs.spec.alpha/rep* (cljs/spec/alpha.cljs:953:10)
	cljs.spec.alpha/deriv (cljs/spec/alpha.cljs:1090:22)
	cljs.spec.alpha/deriv (cljs/spec/alpha.cljs:1087:50)
	cljs.spec.alpha/re-conform (cljs/spec/alpha.cljs:1211:17)
	cljs.spec.alpha/conform* [cljs.spec.alpha/Spec] (cljs/spec/alpha.cljs:1252:10)
	cljs.spec.alpha/conform* (cljs/spec/alpha.cljs:39:1)
	cljs.spec.alpha/conform (cljs/spec/alpha.cljs:153:4)
	cljs.spec.test.alpha/f (cljs/spec/test/alpha.cljs:110:39)
	planck.pprint.width-adjust/generate-sample (planck/pprint/width_adjust.cljs:5:218)
	planck.pprint.width-adjust/bisect (planck/pprint/width_adjust.cljs:7:302)
	planck.pprint.width-adjust/adjusted-with (planck/pprint/width_adjust.cljs:11:143)
	planck.pprint.width-adjust/d (planck/pprint/width_adjust.cljs:12:301)
	planck.repl/print-value (planck/repl.cljs:1940:12)
	cljs.core/e (cljs/core.cljs:4240:17)
	cljs.js/B (cljs/js.cljs:1133:24)
	cljs.js/eval-str* (cljs/js.cljs:1047:6)
	planck.repl/process-execute-source (planck/repl.cljs:2003:11)
	planck.repl/execute-source (planck/repl.cljs:2056:18)
	planck.repl/execute (planck/repl.cljs:2065:7)

borkdude 2018-10-23T17:34:29.000100Z

@mfikes can I get some output using the coal mine runner? I made an intentional bug in juxt:

(s/fdef clojure.core/juxt
  :args (s/+ int? #_ifn?)
  :ret fn?)
and I see it’s used in some code, but I’m not sure if it’s hitting that code

mfikes 2018-10-23T19:25:48.000100Z

@borkdude check out the coal-mine aliases in deps.edn—they’ve been committed and merged in

borkdude 2018-10-23T21:05:39.000100Z

@mfikes do you mean like clj -A:test:coal-mine-clj? I have done that, but my CPU spins and I see no progress bar or anything.

borkdude 2018-10-23T21:05:59.000100Z

I looked a bit into the source code of coal-mine and there seems to be something for this. I’m not sure how to activate that

mfikes 2018-10-23T21:05:59.000200Z

You have to wait for a few hours

mfikes 2018-10-23T21:06:53.000100Z

You can instead run a few test namespaces to see if things work. (The code is pretty straightforward, just start a REPL instead and run-tests on a namespace.)

borkdude 2018-10-23T21:07:14.000100Z

k

borkdude 2018-10-23T21:11:13.000100Z

ah, now I see why my wrong juxt wasn’t catched. these puzzles try to re-implement juxt, but never call it… https://github.com/mfikes/coal-mine/blob/master/src/coal_mine/problem_59.cljc

borkdude 2018-10-23T21:11:33.000200Z

🙂

mfikes 2018-10-23T21:12:05.000100Z

@slipset The Planck issue you mentioned above might be similar to some of the other tickets logged where instrumenting a variadic function appears to offset the arguments. (It is interesting that it would only affect self-host, though.)

borkdude 2018-10-23T21:12:53.000100Z

it’s sometimes triggered during instrumentation instead of during checking something

borkdude 2018-10-23T21:13:07.000100Z

hmm, juxt is used in other places

mfikes 2018-10-23T21:13:17.000100Z

@borkdude Problem 168 uses juxt in its tests: https://github.com/mfikes/coal-mine/blob/master/src/coal_mine/checks.cljc#L1607-L1608

borkdude 2018-10-23T21:20:57.000100Z

I’m running this, but no catch:

:main-opts ["-e" "(require,'speculative.core,'clojure.spec.test.alpha)"
               "-e" "(clojure.spec.test.alpha/instrument)"
               "-e" "(require,'coal-mine.checks)"
               "-e" "(require,'clojure.test)"
               "-e" "(clojure.test/run-tests,'coal-mine.checks)"
               ]

borkdude 2018-10-23T21:22:31.000100Z

it doesn’t even catch this when I insert it in between: "-e" "(juxt,1)"

borkdude 2018-10-23T21:23:39.000100Z

my bad, it does catch a mistake, I just changed the juxt spec to

(s/fdef clojure.core/juxt
  :args (s/+ int? #_ifn?)
  :ret fn?)
so on "-e" "(juxt,identity)" it complains

borkdude 2018-10-23T21:24:47.000100Z

but still doesn’t catch the call in coal-mine it seems

borkdude 2018-10-23T21:26:45.000100Z

$ clj -A:test:coal-mine-clj
[clojure.core/remove clojure.core// clojure.core/reduce clojure.core/first clojure.core/= clojure.core/every? clojure.core/some clojure.core/merge clojure.core/some? clojure.core/str clojure.core/count clojure.core/apply clojure.core/filter clojure.core/not-any? clojure.core/not-every? clojure.core/reset! clojure.core/juxt clojure.core/map clojure.core/merge-with clojure.core/fnil clojure.core/swap!]

Testing coal-mine.checks

Ran 0 tests containing 0 assertions.
0 failures, 0 errors.
{:test 0, :pass 0, :fail 0, :error 0, :type :summary}

borkdude 2018-10-23T21:37:17.000100Z

cool, with

:main-opts ["-e" "(require,'speculative.core,'clojure.spec.test.alpha)"
               "-e" "(clojure.spec.test.alpha/instrument)"
               "-e" "(require,'coal-mine.problem-171)"
               "-e" "(require,'clojure.test)"
               "-e" "(clojure.test/run-tests,'coal-mine.problem-171)"
               ]
I get an error:
actual: clojure.lang.ExceptionInfo: Call to #'clojure.core/juxt did not conform to spec.

mfikes 2018-10-23T21:52:50.000100Z

coal-mine.checks isn't actually a test namespace... it is a utility namespace included by the test namespaces

borkdude 2018-10-23T21:59:56.000100Z

yeah but with 168 I didn’t get an error either