项目作者: borkdude

项目描述 :
speculative kaocha plugin
高级语言: Clojure
项目地址: git://github.com/borkdude/speculative-kaocha-plugin.git
创建时间: 2019-01-30T16:56:08Z
项目社区:https://github.com/borkdude/speculative-kaocha-plugin

开源协议:Eclipse Public License 1.0

下载


speculative kaocha plugin

Clojars Project
cljdoc badge

This kaocha plugin instruments tests
with speculative clojure.core specs.

Installation

Tools.deps

  1. {:deps {speculative/kaocha-plugin {:mvn/version "0.0.1"}}}

Leiningen / Boot

  1. [speculative/kaocha-plugin "0.0.1"]

Configuration

Add :speculative-kaocha.plugin/instrument to the :plugins key in
tests.edn.

By default clojure.core functions are instrumented. This can be disabled by
setting :speculative-kaocha.plugin/no-instrument to true on a per test suite
basis.

  1. #kaocha/v1
  2. {:plugins [:speculative-kaocha.plugin/instrument]
  3. :tests [{:id :unit
  4. :kaocha/test-paths ["test/unit"]}
  5. {:id :integration
  6. :speculative-kaocha.plugin/no-instrument true
  7. :kaocha/test-paths ["test/integration"]}]}

Demo

  1. $ cat test/demo/core_test.cljc
  2. (ns demo.core-test
  3. (:require [clojure.test :as t]))
  4. (t/deftest foo
  5. (t/is (flatten 1)))
  6. $ clojure -A:test -m kaocha.runner
  7. [(.)]
  8. 1 tests, 1 assertions, 0 failures.
  9. $ clojure -A:test -m kaocha.runner --plugin speculative-kaocha.plugin/instrument
  10. [(E)]
  11. Randomized with --seed 1206313428
  12. ERROR in demo.core-test/foo (alpha.clj:132)
  13. Exception: clojure.lang.ExceptionInfo: Call to #'clojure.core/flatten did not conform to spec.
  14. {:clojure.spec.alpha/problems [{:path [:x :clojure.spec.alpha/pred], :pred clojure.core/sequential?, :val 1, :via [:speculative.specs/sequential], :in [0]} {:path [:x :clojure.spec.alpha/nil], :pred nil?, :val 1, :via [], :in [0]}], :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x76596288 "clojure.spec.alpha$regex_spec_impl$reify__2509@76596288"], :clojure.spec.alpha/value (1), :clojure.spec.alpha/fn clojure.core/flatten, :clojure.spec.alpha/args (1), :clojure.spec.alpha/failure :instrument, :clojure.spec.test.alpha/caller {:file "core.clj", :line 665, :var-scope clojure.core/apply}}

Selectively disabling specs

In the unfortunate event that a speculative spec is wrong, or your code is
offending a spec and you don’t want to fix it right away, you can selectively
disable specs by def‘ing them to nil after loading speculative.instrument.

E.g. (s/def clojure.core/re-find nil).

In deps.edn this can be done as follows:

  1. :main-opts
  2. ["-e" "(require,'[speculative.instrument])"
  3. "-e" "(require,'[clojure.spec.alpha,:as,s])"
  4. "-e" "(s/def,clojure.core/re-find,nil)"
  5. "-m" "kaocha.runner" "--no-capture-output"]

Tests

  1. clojure -A:test
  2. lein kaocha

License

Copyright © 2018 Michiel Borkent

Distributed under the EPL License, same as Clojure. See LICENSE.