Code Monkey home page Code Monkey logo

test-runner's Introduction

test-runner

test-runner is a small library for discovering and running tests in projects using native Clojure deps (i.e, those that use only Clojure's built-in dependency tooling, not Leiningen/boot/etc.)

Rationale

Clojure's 1.9 release included standalone tools for dependency resolution, classpath construction, and launching processes. Clojure also ships with a straightforward testing library, clojure.test.

Using these tools, however, there was no standard way to discover and run unit tests. Including a heavyweight project tool such as Leiningen or Boot just for the purpose of testing is overkill. Projects can build their own ad-hoc test runners, but these tend to lack features that will eventually be desired, and tend towards the "quick and dirty," besides being nonstandard from project to project.

This library aims to fill in the gap and provide a standardized, easy-to-use entry point for discovering and running unit and property-based tests while remaining a lightweight entry in Clojure's suite of decomplected project management tools.

Configuration

Include a dependency on this project in your deps.edn. You will probably wish to put it in the test alias:

;; v0.5.1
:aliases {:test {:extra-paths ["test"]
                 :extra-deps {io.github.cognitect-labs/test-runner 
                              {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
                 :main-opts ["-m" "cognitect.test-runner"]
                 :exec-fn cognitect.test-runner.api/test}}

Invoke with clojure -X (exec style)

Invoking the test-runner with clojure -X will call the test function with a map of arguments, which can be supplied either in the alias (via :exec-args) or on the command-line, or both.

Invoke it with:

clj -X:test ...args...

This will scan your project's test directory for any tests defined using clojure.test and run them.

You may also supply any of the additional command line options:

  :dirs - coll of directories containing tests, default= ["test"]
  :nses - coll of namespace symbols to test
  :patterns - coll of regex strings to match namespaces
  :vars - coll of fully qualified symbols to run tests on
  :includes - coll of test metadata keywords to include
  :excludes - coll of test metadata keywords to exclude"

If neither :dirs or :nses is supplied, will use:

  :patterns [".*-test$"]

Note that when supplying collections of values via clj -X, you will need to quote those vectors (also see quoting for more):

clj -X:test :dirs '["test" "integration"]'

Invoke with clojure -M (clojure.main)

To use the older clojure.main command line style:

clj -M:test ...args...

Use any of the additional command line options:

  -d, --dir DIRNAME            Name of the directory containing tests. Defaults to "test".
  -n, --namespace SYMBOL       Symbol indicating a specific namespace to test.
  -r, --namespace-regex REGEX  Regex for namespaces to test. Defaults to #".*-test$"
                               (i.e, only namespaces ending in '-test' are evaluated)
  -v, --var SYMBOL             Symbol indicating the fully qualified name of a specific test.
  -i, --include KEYWORD        Run only tests that have this metadata keyword.
  -e, --exclude KEYWORD        Exclude tests with this metadata keyword.
  -H, --test-help              Display this help message

Operation

There are three main steps to test execution:

  • Find dirs to scan - by default "test"
  • Find namespaces in those dirs (either by specific name or regex pattern or both) - by default all ending in "-test"
  • Find vars to invoke in those namespaces - by default all, unless specific vars are listed, further filtered by include and exclude metadata

Using Inclusions and Exclusions

You can use inclusions and exclusions to run only a subset of your tests, identified by metadata on the test var.

For example, you could tag your integration tests like so:

(deftest ^:integration test-live-system
  (is (= 200 (:status (http/get "http://example.com")))))

Then to run only integration tests, you could do one of:

clj -X:test :includes '[:integration]'
clj -M:test -i :integration

Or to run all tests except for integration tests, one of:

clj -X:test :excludes '[:integration]'
clj -M:test -e :integration

If both inclusions and exclusions are present, exclusions take priority over inclusions.

Copyright and License

Copyright © 2018-2022 Cognitect

Licensed under the Eclipse Public License, Version 2.0

test-runner's People

Contributors

cap10morgan avatar enaeher avatar frenchy64 avatar ghadishayban avatar kawas44 avatar levand avatar mainej avatar mthl avatar pemtajo avatar puredanger avatar seancorfield avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

test-runner's Issues

Unable to run tests based on specific directory

Hi All,

My application has below directory structure.

   src 
   |
   - ---hi.clj
   test
   |    
   ----- unit
   |       |
   |       ------ hi_test.clj 
   |
   ------- integration
            |
            ----  hi_test.clj

I was trying to run tests based on directory as per the test-runner document. I was getting the below error:

clj -X:test :dirs ["test/integration"]
Execution error (IllegalArgumentException) at cognitect.test-runner/test (test_runner.clj:68).
No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.Symbol

Later, I gave the args like below and it started working. ( I just surrounded ["test/integration" with single quotes.)

clj -X:test :dirs '["test/integration"]'

Am using ubuntu 20. It took 4 hours to figure out the mistake. Can it be included in the document / example? so that no one will have to waste the time like me.

public auth fail on circleCI test runner

This isn't really your problem, per se, but it did prevent me being able to use the cognitect-lab test runner in CI/CD.
Note: the clojure -A:test:runner works locally but not in circleCI on cloud. In this case, a explanation would probably be an acceptable solution as I I don't believe this is a bug in the software.

This is the circleCI error:

org.eclipse.jgit.api.errors.TransportException: ssh://[email protected]/cognitect-labs/test-runner.git: Auth fail
	at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:248)
	at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306)
	at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200)
	at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:89)
	at clojure.tools.gitlibs.impl$call_with_auth.invokeStatic(impl.clj:52)
	at clojure.tools.gitlibs.impl$call_with_auth.invoke(impl.clj:43)
	at clojure.tools.gitlibs.impl$git_clone_bare.invokeStatic(impl.clj:73)
	at clojure.tools.gitlibs.impl$git_clone_bare.invoke(impl.clj:70)
	at clojure.tools.gitlibs.impl$ensure_git_dir.invokeStatic(impl.clj:112)
	at clojure.tools.gitlibs.impl$ensure_git_dir.invoke(impl.clj:102)
	at clojure.tools.gitlibs$resolve.invokeStatic(gitlibs.clj:33)
	at clojure.tools.gitlibs$resolve.invoke(gitlibs.clj:29)
	at clojure.tools.gitlibs$procure.invokeStatic(gitlibs.clj:47)
	at clojure.tools.gitlibs$procure.invoke(gitlibs.clj:41)
	at clojure.tools.deps.alpha.extensions.git$eval1259$fn__1261.invoke(git.clj:42)
	at clojure.lang.MultiFn.invoke(MultiFn.java:239)
	at clojure.tools.deps.alpha$expand_deps.invokeStatic(alpha.clj:386)
	at clojure.tools.deps.alpha$expand_deps.invoke(alpha.clj:354)
	at clojure.tools.deps.alpha$resolve_deps.invokeStatic(alpha.clj:444)
	at clojure.tools.deps.alpha$resolve_deps.invoke(alpha.clj:424)
	at clojure.tools.deps.alpha$calc_basis.invokeStatic(alpha.clj:550)
	at clojure.tools.deps.alpha$calc_basis.invoke(alpha.clj:525)
	at clojure.tools.deps.alpha.script.make_classpath2$run_core.invokeStatic(make_classpath2.clj:86)
	at clojure.tools.deps.alpha.script.make_classpath2$run_core.invoke(make_classpath2.clj:56)
	at clojure.tools.deps.alpha.script.make_classpath2$run.invokeStatic(make_classpath2.clj:109)
	at clojure.tools.deps.alpha.script.make_classpath2$run.invoke(make_classpath2.clj:103)
	at clojure.tools.deps.alpha.script.make_classpath2$_main.invokeStatic(make_classpath2.clj:158)
	at clojure.tools.deps.alpha.script.make_classpath2$_main.doInvoke(make_classpath2.clj:128)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:705)
	at clojure.core$apply.invokeStatic(core.clj:665)
	at clojure.main$main_opt.invokeStatic(main.clj:514)
	at clojure.main$main_opt.invoke(main.clj:510)
	at clojure.main$main.invokeStatic(main.clj:664)
	at clojure.main$main.doInvoke(main.clj:616)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:705)
	at clojure.main.main(main.java:40)
Caused by: org.eclipse.jgit.errors.TransportException: ssh://[email protected]/cognitect-labs/test-runner.git: Auth fail
	at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:172)
	at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:140)
	at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:280)
	at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:170)
	at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:137)
	at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:123)
	at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1269)
	at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:237)
	... 37 more
Caused by: com.jcraft.jsch.JSchException: Auth fail
	at com.jcraft.jsch.Session.connect(Session.java:519)
	at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:126)
	... 44 more

I couldn't find anything online about it.

deps.edn

{:mvn/repos {"clojars" {:url "https://repo.clojars.org/"}
             "central" {:url "https://repo1.maven.org/maven2/"}}
 :paths     ["src" "resources"]
 :deps      {org.clojure/clojure                  {:mvn/version "1.10.1"}
             techascent/tech.ml.dataset           {:mvn/version "5.00-beta-6"}
             org.apache.hadoop/hadoop-common      {:mvn/version "3.1.1"}
             org.apache.arrow/arrow-memory-unsafe {:mvn/version "2.0.0"}
             org.apache.arrow/arrow-memory-core   {:mvn/version "2.0.0"}
             org.apache.arrow/arrow-vector        {:mvn/version "2.0.0"}
             cnuernber/dtype-next                 {:mvn/version "6.00-beta-5"}}
 :aliases   {:test   {:extra-paths ["test"]}
             :runner { :extra-deps
                      {com.cognitect/test-runner
                       {:git/url "https://github.com/cognitect-labs/test-runner.git"
                        :sha     "209b64504cb3bd3b99ecfec7937b358a879f55c1"}}
                      :main-opts   ["-m" "cognitect.test-runner"]}}}

.circleCI

version: 2.1
jobs:
  build:
    working_directory: ********************
    docker:
      - image: circleci/clojure:tools-deps-1.10.1.619
    environment:
      - CIRCLE_ARTIFACTS: /tmp/artifacts
    steps:
      - add_ssh_keys
      - checkout
      - restore_cache:
          key: ********************
      - run:
          name: Run all tests
          command: clojure -A:test:runner
      - save_cache:
          paths:
            - ~/.m2
          key: ****************
      - store_artifacts:
          path: /tmp/artifacts

Tests do not finish if an agent has been started.

If an agent is started, tests do not finish, waiting for the agent threads to finish:

These files should reproduce the issue:
deps.edn:

{:paths ["src"]
 :deps {}
 :aliases {:test {:extra-paths ["test"]
                  :extra-deps {io.github.cognitect-labs/test-runner {:git/sha "a522ab2851a2aa5bf9c22a942b45287a3a019310"}}
                  :main-opts ["-m" "cognitect.test-runner"]
                  :exec-fn cognitect.test-runner.api/test}}}

core_test.clj:

(ns core-test
  (:require [clojure.test :refer :all]))

(deftest duration-test
  (let [a (agent 0)]
    (send a inc)
    (await a)
    (is (= 1 @a))))

I've seen a PR which could be very useful for this: Add before and after options
since it will allow to run (shutdown-agents) after running the tests.

ClojureScript support

Thoughts / opinions about ClojureScript support? It would be nice if this tool could cover the two common use cases.

Tests are run in `user` namespace

Using clj -X:test seems to run the tests in the user namespace, which breaks tests that rely on *ns*. Here's a repro.

(ns example.core-test
  (:require
    [clojure.test :refer [deftest is]]))

(deftest example-test
  (is (= (str *ns*) "example.core-test")))

Result:

FAIL in (example-test) (core_test.cljc:24)
expected: (= (str *ns*) "example.core-test")
  actual: (not (= "user" "example.core-test"))

Out of spec defn re: docstring

The defn for cognitect.test-runner.api/test is malformed and throws a spec exception. Looks like there are stray characters outside the closing " of the docstring.

CompilerException clojure.lang.ExceptionInfo: Call to clojure.core/defn did not conform to spec:
In: [2 0] val: quote fails spec: :clojure.core.specs.alpha/arg-list at: [:args :bs :arity-n :bodies :args] predicate: vector?
In: [2] val: (quote .) fails spec: :clojure.core.specs.alpha/arg-list at: [:args :bs :arity-1 :args] predicate: vector?
 #:clojure.spec.alpha{:problems ({:path [:args :bs :arity-1 :args], :pred clojure.core/vector?, :val (quote .), :via [:clojure.core.specs.alpha/defn-args :clojure.core.specs.alpha/args+body :clojure.core.specs.alpha/arg-list :clojure.core.specs.alpha/arg-list], :in [2]} {:path [:args :bs :arity-n :bodies :args], :pred clojure.core/vector?, :val quote, :via [:clojure.core.specs.alpha/defn-args :clojure.core.specs.alpha/args+body :clojure.core.specs.alpha/args+body :clojure.core.specs.alpha/args+body :clojure.core.specs.alpha/arg-list :clojure.core.specs.alpha/arg-list], :in [2 0]}), :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x3997ffc7 "clojure.spec.alpha$regex_spec_impl$reify__2436@3997ffc7"], :value (test "Invoke the test-runner with the following options:\n\n  * :dirs - coll of directories containing tests, default= [\"test\"]\n  * :nses - coll of namespace symbols to test\n  * :patterns - coll of regex strings to match namespaces\n  * :vars - coll of fully qualified symbols to run tests on\n  * :includes - coll of test metadata keywords to include\n  * :excludes - coll of test metadata keywords to exclude\n\n  If neither :nses nor :patterns is supplied, use `:patterns [\".*-test$\"]" (quote .) [opts] (try (let [{:keys [fail error]} (do-test opts)] (System/exit (if (zero? (+ fail error)) 0 1))) (finally (shutdown-agents)))), :args (test "Invoke the test-runner with the following options:\n\n  * :dirs - coll of directories containing tests, default= [\"test\"]\n  * :nses - coll of namespace symbols to test\n  * :patterns - coll of regex strings to match namespaces\n  * :vars - coll of fully qualified symbols to run tests on\n  * :includes - coll of test metadata keywords to include\n  * :excludes - coll of test metadata keywords to exclude\n\n  If neither :nses nor :patterns is supplied, use `:patterns [\".*-test$\"]" (quote .) [opts] (try (let [{:keys [fail error]} (do-test opts)] (System/exit (if (zero? (+ fail error)) 0 1))) (finally (shutdown-agents))))}, compiling:(/Users/dpassen/apps/test-runner/src/cognitect/test_runner/api.clj:16:1) 

Troubles installing on linux

I wanted to try out this library, so I run the following command on my linux box:

clojure -Sdeps '{:deps {com.cognitect/test-runner {:git/url "[email protected]:cognitect-labs/test-runner" :sha "dc5c899ff0dbb2c3651f6c90d12b594e45ae6452"}}}'

I got the following error:

Error building classpath. [email protected]:cognitect-labs/test-runner: java.lang.NoClassDefFoundError: com/jcraft/jzlib/ZStream
org.eclipse.jgit.api.errors.TransportException: [email protected]:cognitect-labs/test-runner: java.lang.NoClassDefFoundError: com/jcraft/jzlib/ZStream
	at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:248)
	at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306)
	at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200)
	at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:89)
	at clojure.tools.gitlibs.impl$call_with_auth.invokeStatic(impl.clj:49)
	at clojure.tools.gitlibs.impl$call_with_auth.invoke(impl.clj:41)
	at clojure.tools.gitlibs.impl$git_clone_bare.invokeStatic(impl.clj:71)
	at clojure.tools.gitlibs.impl$git_clone_bare.invoke(impl.clj:68)
	at clojure.tools.gitlibs.impl$ensure_git_dir.invokeStatic(impl.clj:106)
	at clojure.tools.gitlibs.impl$ensure_git_dir.invoke(impl.clj:100)
	at clojure.tools.gitlibs$resolve.invokeStatic(gitlibs.clj:27)
	at clojure.tools.gitlibs$resolve.invoke(gitlibs.clj:23)
	at clojure.tools.gitlibs$procure.invokeStatic(gitlibs.clj:41)
	at clojure.tools.gitlibs$procure.invoke(gitlibs.clj:35)
	at clojure.tools.deps.alpha.extensions.git$eval958$fn__960.invoke(git.clj:35)
	at clojure.lang.MultiFn.invoke(MultiFn.java:238)
	at clojure.tools.deps.alpha$expand_deps.invokeStatic(alpha.clj:153)
	at clojure.tools.deps.alpha$expand_deps.invoke(alpha.clj:137)
	at clojure.tools.deps.alpha$resolve_deps.invokeStatic(alpha.clj:191)
	at clojure.tools.deps.alpha$resolve_deps.invoke(alpha.clj:182)
	at clojure.tools.deps.alpha.script.make_classpath$run.invokeStatic(make_classpath.clj:56)
	at clojure.tools.deps.alpha.script.make_classpath$run.invoke(make_classpath.clj:44)
	at clojure.tools.deps.alpha.script.make_classpath$_main.invokeStatic(make_classpath.clj:98)
	at clojure.tools.deps.alpha.script.make_classpath$_main.doInvoke(make_classpath.clj:73)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:702)
	at clojure.core$apply.invokeStatic(core.clj:657)
	at clojure.main$main_opt.invokeStatic(main.clj:317)
	at clojure.main$main_opt.invoke(main.clj:313)
	at clojure.main$main.invokeStatic(main.clj:424)
	at clojure.main$main.doInvoke(main.clj:387)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:702)
	at clojure.main.main(main.java:37)
Caused by: org.eclipse.jgit.errors.TransportException: [email protected]:cognitect-labs/test-runner: java.lang.NoClassDefFoundError: com/jcraft/jzlib/ZStream
	at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:172)
	at clojure.tools.gitlibs.impl.proxy$org.eclipse.jgit.transport.JschConfigSessionFactory$ff19274a.getSession(Unknown Source)
	at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:140)
	at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:280)
	at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:170)
	at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:137)
	at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:123)
	at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1269)
	at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:237)
	... 33 more
Caused by: com.jcraft.jsch.JSchException: java.lang.NoClassDefFoundError: com/jcraft/jzlib/ZStream
	at com.jcraft.jsch.Session.initDeflater(Session.java:2241)
	at com.jcraft.jsch.Session.read(Session.java:1048)
	at com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:198)
	at com.jcraft.jsch.Session.connect(Session.java:470)
	at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:126)
	... 41 more
Caused by: java.lang.NoClassDefFoundError: com/jcraft/jzlib/ZStream
	at com.jcraft.jsch.jcraft.Compression.<init>(Compression.java:42)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at com.jcraft.jsch.Session.initDeflater(Session.java:2234)
	... 45 more
Caused by: java.lang.ClassNotFoundException: com.jcraft.jzlib.ZStream
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 52 more

Other dependencies were installed correctly, I do not really know if the error is in tools.deps or elsewhere.

Anyone else having trouble installing this library? Any idea what might be wrong here?

Reflection warning

Reflection warning, cognitect/test_runner.clj:71:7 - call to method startsWith can't be resolved (target class is unknown).

The code block is:

(defn- parse-kw
  [s]
  (if (.startsWith s ":") (read-string s) (keyword s)))

I would just create the PR, but im not 100% what the type of s is. If you are not familiar with reflection warnings s needs a type hint. something like ^String for a java.String. Just make sure to import the type you are hinting.

Alternative output formats

For me, it would be useful to have the junit output format in particular for tooling. Both junit & tap are argument-less and use the same macro signature, so it's possible that this is all that needs supporting. If you need something else, you can always wrap the underlying format with your own macro which does conform.

Release on Maven?

Hi,

I appreciate test-runner's lean-ness and simplicity which can lead to solutions that can be well understood and maintained.

This IMO contrasts withlein test. Its test.clj backing namespace is not a vanilla one that can be required and executed by vanilla (non-lein-plugin) Clojure code.

However that's just one of the many concerns that may lead a team or individual to choose tools.deps over Lein, or vice versa.

Accordingly, I'd like to suggest that this library is also offered as a Maven artifact, so that one can choose to use it from a Lein project.

There are alternatives (forking, vendoring, using lein-git-down, etc) but one can also consider the technical and social risk/cost of deviating from an official artifact.

WDYT?

Thanks - V

Report a non-zero exit code when tests fail

When tests fail, the process should exit with a non-zero exit code. This is especially important for people using this in CI.

Current behavior

$ clj -Atest

Running tests in #{"test"}

Testing foo

FAIL in (foo-test) (foo.clj:5)
expected: false
  actual: false

Ran 1 tests containing 1 assertions.
1 failures, 0 errors.

$ echo $?
0

Expected

$ echo $?
1

Fix for #17 loads too many namespaces when using -n option

This commit c1a74fc broke my test setup.

I'm using the following script:

#!/usr/bin/env bash

if [ "$POD_DB_TYPE" = "postgresql" ]
then
    clojure -M:test -n pod.babashka.postgresql-test
fi

if [ "$POD_DB_TYPE" = "hsqldb" ]
then
    clojure -M:test -n pod.babashka.hsqldb-test
fi

if [ "$POD_DB_TYPE" = "mysql" ]
then
    clojure -M:test -n pod.babashka.mysql-test
fi

if [ "$POD_DB_TYPE" = "oracle" ]
then
    clojure -M:test -n pod.babashka.oracle-test
fi

if [ "$POD_DB_TYPE" = "mssql" ]
then
    clojure -M:test -n pod.babashka.mssql-test
fi

I am relying on the -n foo setting to not load any other namespaces, but it currently does, which causes my tests to fail whereas before the commit it worked as intended.

Limiting tests to a single var with --var/:vars still prints out other namespaces

If I limit tests to a single var with something like

clojure -X:test :vars '[my.project.core-test/my-test]'

The test runner output still includes output like

Testing my.project.another-namespace-test

Testing my.project.some-other-namespace-test

...

This can be quite noisy in a project with a lot of test namespaces. Should ns-filter also filter out namespaces that aren't present in :vars, if :vars is set? Alternatively maybe test-ns itself should take care of printing the Testing message, but only do so if there are some test vars present in that namespace.

I can PR either change if you'd like.

Not finding any tests to run

clj -Atest -d src/test

Running tests in #{"src/test"}

Testing user

Ran 0 tests containing 0 assertions.
0 failures, 0 errors.

I don't understand why it is saying "Testing user". Is this the user namespace? The alias from deps.edn looks like this:

{:test {:extra-paths ["src/test"]
        :extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner.git" :sha "209b64504cb3bd3b99ecfec7937b358a879f55c1"}}
        :main-opts ["-m" "cognitect.test-runner"]}}

src/test is a directory off the project root directory, under which there are many namespaces that have many deftests in them.

Returns zero (success) exit code on bad command-line arguments

Currently if any command-line arguments passed to cognitect.test-runner/-main contain errors, help messages are printed but the exit code is still 0. It might be a better idea to return a non-zero code so CI builds fail in this case.

FWIW I came across this while changing my scripts from -A to -M, and I had to move an -Sdeps directive to before the -M.

Exclusion Feature: Fixture functions should not be run if no tests will be run from this namespace

Scenario

  • Create a test namespace
  • Add a costly init fixtures function
    (use-fixtures :once (fn [f] (println "Execute costly integration fixture")(f)))
  • Add a test tagged with the integration keyword
  • Launch all tests ignoring the integration keyword

Result
Initialization fixture function is executed, but no tests were selected in this namespace to be run

Expected
As with lein test. No fixture execution when no tests will be run from namespace

Workaround
If you happen to have grouped your tests in the same namespace. Use regexp exclusion.

Cheers

unit tests fail console, but reporting success

When some unit tests fail, in the log it reports the failure, but in the end it reports a success.
This is a big problem, wen using the test-runner in ci.

versions: cognitect test runner: f597341
clojure: 1.10.3
core.async: 1.3.618

failed case:

Running tests in #{"test"}

Testing picasso.full-test

Testing picasso.hiccup-reagent-test

Testing picasso.kernel-clj-test

Testing picasso.render-clj-types-test

Testing picasso.render-custom-test

FAIL in (test-eval-clj) (kernel_clj_test.clj:15)
expected: (r= (<! (kernel-eval {:kernel :clj, :code "13"})) {:picasso {:type :hiccup, :content [:span {:class "clj-long"} "13"]}})
  actual: (not (r= {:id :c222739a-8b39-4561-96ec-1a944c2dfe31, :err "kernel unknown: :clj"} {:picasso {:type :hiccup, :content [:span {:class "clj-long"} "13"]}}))

FAIL in (test-eval-clj) (kernel_clj_test.clj:15)
expected: (r= (<! (kernel-eval {:kernel :clj, :code "[7 8]"})) {:picasso {:type :list-like, :content {:class "clj-vector", :open "[", :close "]", :separator " ", :items (quote ({:type :hiccup, :content [:span {:class "clj-long"} "7"]} {:type :hiccup, :content [:span {:class "clj-long"} "8"]})), :value "[7 8]"}}})
  actual: 
Testing picasso.render-image-test
(not (r= {:id :1364f388-3a99-4e71-bf38-7d69026eed5b, :err "kernel unknown: :clj"} {:picasso {:type :list-like, :content {:class "clj-vector", :open "[", :close "]", :separator " ", :items ({:type :hiccup, :content [:span {:class "clj-long"} "7"]} {:type :hiccup, :content [:span {:class "clj-long"} "8"]}), :value "[7 8]"}}}))

Ran 17 tests containing 18 assertions.
0 failures, 0 errors.

When I fix the unit test I get this:

 clojure -X:test

Running tests in #{"test"}

Testing picasso.full-test

Testing picasso.hiccup-reagent-test

Testing picasso.kernel-clj-test

Testing picasso.render-clj-types-test

Testing picasso.render-custom-test

Testing picasso.render-image-test
2021-07-04T06:24:54.260Z UnknownHost INFO [picasso.kernel.clj:13] - clj-eval:  13
2021-07-04T06:24:54.458Z UnknownHost INFO [picasso.kernel.clj:13] - clj-eval:  [7 8]

Ran 17 tests containing 18 assertions.
0 failures, 0 errors.

This is the code of my test:

(deftest test-eval-clj
  "eval with several expressions"
  (go (are [input-clj result]
           (r= (<! (kernel-eval {:kernel :clj :code input-clj}))
               result)

        "13"
        {:picasso {:type :hiccup :content [:span {:class "clj-long"} "13"]}}

        "[7 8]"
        {:picasso
         {:type :list-like
          :content
          {:class "clj-vector"
           :open "["
           :close "]"
           :separator " "
           :items
           '({:type :hiccup, :content [:span {:class "clj-long"} "7"]}
             {:type :hiccup, :content [:span {:class "clj-long"} "8"]})
           :value "[7 8]"}}})))

tis is the code that gets called i the failed test,.

#?(:clj (defmulti kernel-eval (fn [e] (:kernel e)))
   :cljs (defmulti kernel-eval (fn [e] (:kernel e))))

(defmethod kernel-eval :default [m]
  (let [c (chan)]
    (go (>! c {:id (guuid)
               :err (str "kernel unknown: " (:kernel m))})
        (close! c))
    c))

Publishing a maven artifact

Hello! I'm wondering if a maven artifact could be published for this project, it'd be nice for those of us dealing with proxy issues with github repo clones, thanks so much!

Readme example uses sha with syntax error

README references

 :aliases {:test {:extra-deps {io.github.cognitect-labs/test-runner
                               {:git/url "https://github.com/cognitect-labs/test-runner.git"
                                :sha "d579a19d058993085b9e3ba5247c89f3f3318b47"}}
                  :main-opts ["-m" "cognitect.test-runner"]
                  :exec-fn cognitect.test-runner.api/test}}

but should use

 :aliases {:test {:extra-deps {io.github.cognitect-labs/test-runner
                               {:git/url "https://github.com/cognitect-labs/test-runner.git"
                                :sha "705ad25bbf0228b1c38d0244a36001c2987d7337"}}
                  :main-opts ["-m" "cognitect.test-runner"]
                  :exec-fn cognitect.test-runner.api/test}}

Bug was #31 but commit in readme points to before it was fixed.

test-runner does not exit correctly since v0.5.0

Background

  • I am migrating https://github.com/gnarroway/hato to use GitHub actions for the test/publish CI workflow (previously circleCI)
  • As part of this, I am using deps.edn with this test-runner library
  • cli version 1.11.1.1155, java 11 or 17

Behaviour

  • Using v0.5.0 or later, the test job hangs (invoking clojure -X:test with :exec-fn cognitect.test-runner.api/test), after logging the test results (0 failures, 0 errors.)
  • Downgrading to v0.4.0, the test job finishes successfully

Analysis

  • 0.5.0 included a change to the exit logic, so am guessing it is somehow related to this and the job is not exiting correctly (or in a manner GitHub actions expects, though I don't know what that is)

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.