Git Product home page Git Product logo

utils.test's Introduction

utils.test CircleCI

A collection of test helpers.

Synopsis

  • nedap.utils.test.api/meta= compares both objects and their metadata, recursively.

  • nedap.utils.test.api/macroexpansion= compares objects, deeming any gensyms as equal.

  • nedap.utils.test.api/run-tests macroexpands to its clojure.test/cljs.test counterpart. It only adds something for the cljs variant: it sets an adequate exit code to the Node process.

  • nedap.utils.test.api/expect allows you to assert side effects in code. look at examples in the tests.

  • nedap.kacoha.focus-file-plugin Kaocha plugin which adds --focus-file cli-option. Can be used to test a specific file rather than a specific file.

Installation

[com.nedap.staffing-solutions/utils.test "1.9.0"]

ns organisation

Documentation

Please browse the public namespaces, which are documented, speced and tested.

Development

The default namespace is dev. Under it, (refresh) is available, which should give you a basic "Reloaded workflow".

It is recommended that you use (clojure.tools.namespace.repl/refresh :after 'formatting-stack.core/format!).

You can find examples in the api test.

License

Copyright © Nedap

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0.

utils.test's People

Contributors

tcoenraad avatar thumbnail avatar vemv avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

utils.test's Issues

Add `match?`-declaration in u-t.matcher-combinators

Problem statement

match? is a multi-method dispatch symbol, not a function. So it misses highlighting and a proper refer.

This has a couple of caveats:

  • lack of traceability. The assert-expr is registered when nedap.utils.test.matcher-combinators is loaded, which might be in a different ns
  • formatters might remove [nedap.utils.test.matcher-combinators] as a dependency, if it is only loaded for registering the match?-matcher.

Proposal

add a declaration for the multimethod. Similar to matcher-combinators:
https://github.com/nubank/matcher-combinators/blob/b3da18923f0aa6a5ef924e9303f690a3efa1d978/src/cljc/matcher_combinators/test.cljc#L10-L11

expect-match?

Context

The expect helper is locked to use meta= internally. This has a couple of disadvantages;

  • lack of flexibility.
  • cloverage uses metadata to measure coverage; breaks expect-tests.

Task

  1. add matcher-combinators namespace (see #28)
  2. add expect-match? which uses matcher-combinators.core/match for the :form-assertion, and matcher-combinators.test/match? for the :to assertion.

Additional resources

https://github.com/nubank/matcher-combinators

Add meta=

Rightfully, (= ^:a [] ^:b []) is true, but one may want metadata to be part of the equality criteria.

Fail-fasting test runner

Context

"Fail-fast" is a commonly wanted feature. Some alternative test runners provide a form of it, although they may be a bit framework-ish. I like that utils.test is literally a collection of utils for clojure.test, assuming nothing.

It seems great to have a reusable defn that can be invoked from any project (especially from a repl) regardless of its setup.

Proposal

Bundle a helper such as:

(defn run-tests [& namespaces]
  (let [summary (-> (->> namespaces
                         (reduce (bound-fn [r n]
                                   (let [{:keys [fail error]
                                          :as v} (clojure.test/test-ns n)
                                         failed? (some pos? [fail error])
                                         ret (merge-with + r v)]
                                     (cond-> ret
                                       failed? reduced)))
                                 clojure.test/*initial-report-counters*))
                    (assoc :type :summary))]
    (clojure.test/do-report summary)
    summary))

(defn run-all-tests
  "Like `clojure.test/run-all-tests` but fails-fast."
  []
  (->> (all-ns)
       (filter (fn [n]
                 (->> n
                      ns-publics
                      vals
                      (some (fn [var-ref]
                              {:pre [(var? var-ref)]}
                              (-> var-ref meta :test))))))
       (sort-by pr-str)
       (reverse) ;; unit.* first
       (apply run-tests)))

Then one can do (clojure.tools.namespace.repl/refresh :after 'my/run-all-tests).

This could be further integrated with formatting-stack's test runner, with the project template, etc

...the snippet has worked well for me over the last month, also I had a similar but more intrincate incarnation of it based off CircleCI's test runner over 2020.

Thoughts?

cc/ @thumbnail

matcher for gensyms

Context

macroexpand= is great; but unifies any symbol it recognizes as a gensym. providing a matcher-combinators matcher for gensyms allows for more specific matches

Task

  1. add a GensymMatcher + wrapper fns
  2. add readme examples

Additional resources

Blocked by #28, at least for the opt-in requirement of m-c.

In an internal project we use:

(defrecord GensymMatcher [expected]
 matcher-combinators.core/Matcher
 (match [_this actual]
   (let [value (symbol (string/replace actual #"(.?+)(\d)*" "$1"))]
     (if (= expected value)
       {:matcher-combinators.result/type   :match
        :matcher-combinators.result/value  value
        :matcher-combinators.result/weight 0}
       {:matcher-combinators.result/type   :mismatch
        :matcher-combinators.result/value  (model/->Mismatch expected value)
        :matcher-combinators.result/weight 1}))))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.