Skip to content

Commit

Permalink
Merge branch 'main' into issue-370-ensure-unskipped-testable-for-load…
Browse files Browse the repository at this point in the history
…-error
  • Loading branch information
alysbrooks authored Jan 16, 2023
2 parents ba5c20e + b979e29 commit ab2d804
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .VERSION_PREFIX
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.71
1.72
4 changes: 2 additions & 2 deletions .github/workflows/add_to_project_board.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Add new pr or issue to project board

on: [issues, pull_request]
on: [issues]

jobs:
add-to-project:
uses: lambdaisland/open-source/.github/workflows/add-to-project-board.yml@main
secrets: inherit


12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@
## Fixed

- Ensure reloading errors are printed in watch mode when the first test suite is disabled.
- Using a try-catch (without rethrowing) in an `:each` fixture could swallow
thrown exceptions, resulting in a test being treated as passing when it should
have been reported as an error. Fixed by changing how `:each` fixtures wrap
the test function in execution. (thanks
[@NoahTheDuke](https://github.com/NoahTheDuke))
- Fix crash on Windows when using `--watch` with the default Beholder watcher.

## Changed

# 1.72.1136 (2023-01-09 / d9f0728)

## Fixed

- Documentation fixes and improvements

# 1.71.1119 (2022-10-24 / 4317878)

## Added
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ There is also a [#kaocha](https://clojurians.slack.com/messages/CCY2V0U6A/convo/
- [Orchestra (spec instrumentation)](https://cljdoc.org/d/lambdaisland/kaocha/CURRENT/doc/orchestra-spec-instrumentation-)
- [Plugin: Clojure/Java Version filter](https://cljdoc.org/d/lambdaisland/kaocha/CURRENT/doc/plugin-clojure-java-version-filter)
- [Automatic spec test check generation](https://cljdoc.org/d/lambdaisland/kaocha/CURRENT/doc/automatic-spec-test-check-generation)
- [Syntax errors are preserved](https://cljdoc.org/d/lambdaisland/kaocha/CURRENT/doc/syntax-errors-are-preserved)
<!-- /docs-toc -->

## Features
Expand Down Expand Up @@ -102,7 +103,7 @@ Add Kaocha as a dependency, preferably under an alias.
;; deps.edn
{:deps { ,,, }
:aliases
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}
:main-opts ["-m" "kaocha.runner"]}}}
```

Expand All @@ -123,7 +124,7 @@ Add a profile and alias
;; project.clj
(defproject my-proj "0.1.0"
:dependencies [,,,]
:profiles {:kaocha {:dependencies [[lambdaisland/kaocha "1.71.1119"]]}}
:profiles {:kaocha {:dependencies [[lambdaisland/kaocha "1.72.1136"]]}}
:aliases {"kaocha" ["with-profile" "+kaocha" "run" "-m" "kaocha.runner"]})
```

Expand Down Expand Up @@ -167,7 +168,7 @@ options. If you nonetheless prefer `:exec-fn`/`-X`, you can set up `deps.edn`:
;; deps.edn
{:deps { ,,, }
:aliases
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {}}}}
```
Expand All @@ -188,10 +189,10 @@ of tests skipped. You could save that configuration with an additional alias:
;; deps.edn
{:deps { ,,, }
:aliases
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {}}
:watch-test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
:watch-test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {:watch? true
:skip-meta :slow
Expand Down
14 changes: 7 additions & 7 deletions doc/02_installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The main namespace for use at the command line is `kaocha.runner`, regardless of
For example:

``` shell
clojure -Sdeps '{:deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}}' -m kaocha.runner --test-help
clojure -Sdeps '{:deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}}' -m kaocha.runner --test-help
```

Below are instructions on the recommended way to set things up for various build tools.
Expand All @@ -23,7 +23,7 @@ In `deps.edn`, create a `test` "alias" (profile) that loads the `lambdaisland/ka
{:deps { ,,, }
:aliases
{:test {:main-opts ["-m" "kaocha.runner"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}}}}
:extra-deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}}}}
```

Other dependencies that are only used for tests, like test framework or assertion
Expand Down Expand Up @@ -82,7 +82,7 @@ options. If you nonetheless prefer `:exec-fn`/`-X`, you can set up `deps.edn`:
;; deps.edn
{:deps { ,,, }
:aliases
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {}}}}
```
Expand All @@ -103,10 +103,10 @@ of tests skipped. You could save that configuration with an additional alias:
;; deps.edn
{:deps { ,,, }
:aliases
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {}}
:watch-test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
:watch-test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.72.1136"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {:watch? true
:skip-meta :slow
Expand All @@ -123,7 +123,7 @@ Add Kaocha to your `:dev` profile, then add an alias that invokes `lein run -m k
``` clojure
(defproject my-proj "0.1.0"
:dependencies [,,,]
:profiles {:dev {:dependencies [,,, [lambdaisland/kaocha "1.71.1119"]]}}
:profiles {:dev {:dependencies [,,, [lambdaisland/kaocha "1.72.1136"]]}}
:aliases {"kaocha" ["run" "-m" "kaocha.runner"]})
```

Expand Down Expand Up @@ -156,7 +156,7 @@ alias that activates the profile and invokes `lein run -m kaocha.runner`:
``` clojure
(defproject my-proj "0.1.0"
:dependencies [,,,]
:profiles {:kaocha {:dependencies [[lambdaisland/kaocha "1.71.1119"]]}}
:profiles {:kaocha {:dependencies [[lambdaisland/kaocha "1.72.1136"]]}}
:aliases {"kaocha" ["with-profile" "+kaocha" "run" "-m" "kaocha.runner"]})
```

Expand Down
3 changes: 2 additions & 1 deletion doc/07_watch_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Currently these features of `.gitignore` are not supported:

Kaocha uses [Beholder](https://github.com/nextjournal/beholder) to watch the
filesystem for changes. By default Beholder will pick a mechanism suitable for
your operating system. Beholder works with OSX and M1 mac machines as well.
your operating system. Beholder works with macOS and ARM Mac machines (Apple silicon)
as well.

Previously Kaocha used another watcher, [Hawk](https://github.com/wkf/hawk), which
has been deprecated in favour of Beholder. If you still want to use it for some
Expand Down
20 changes: 20 additions & 0 deletions fixtures/a-tests/baz/qux_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns baz.qux-test
(:require [clojure.test :as t :refer [deftest is use-fixtures]]))

(defn once-fix
[f]
(try (f)
(catch Throwable _)))

(defn each-fix
[f]
(try (f)
(catch Throwable _)))

(use-fixtures :once #'once-fix)
(use-fixtures :each #'each-fix)

(deftest nested-test
(is (= 1 1))
(throw (Exception. "fake exception"))
(is (= 2 1)))
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lambdaisland</groupId>
<artifactId>kaocha</artifactId>
<version>1.71.1119</version>
<version>1.72.1136</version>
<name>kaocha</name>
<description>Full featured next generation test runner for Clojure.</description>
<url>https://github.com/lambdaisland/kaocha</url>
Expand All @@ -25,7 +25,7 @@
<url>https://github.com/lambdaisland/kaocha</url>
<connection>scm:git:git://github.com/lambdaisland/kaocha.git</connection>
<developerConnection>scm:git:ssh://[email protected]/lambdaisland/kaocha.git</developerConnection>
<tag>c63f3acce7230d7abdf74d05ad111c02981cb354</tag>
<tag>f576bfc7c4b94b7d61ed643af50e0bdffe847630</tag>
</scm>
<dependencies>
<dependency>
Expand Down Expand Up @@ -157,7 +157,7 @@
<configuration>
<archive>
<manifestEntries>
<git-revision>c63f3acce7230d7abdf74d05ad111c02981cb354</git-revision>
<git-revision>f576bfc7c4b94b7d61ed643af50e0bdffe847630</git-revision>
</manifestEntries>
</archive>
</configuration>
Expand Down
46 changes: 25 additions & 21 deletions src/kaocha/type/var.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,32 @@
(println "Test ran without assertions. Did you forget an (is ...)?")
(report/print-output m))

(defmethod testable/-run :kaocha.type/var [{test :kaocha.var/test
wrap :kaocha.testable/wrap
the-var :kaocha.var/var
meta' :kaocha.testable/meta
:as testable} test-plan]
(defn test-var [{test :kaocha.var/test
the-var :kaocha.var/var
meta' :kaocha.testable/meta
:as testable}]
(binding [t/*testing-vars* (conj t/*testing-vars* the-var)]
(t/do-report {:type :begin-test-var, :var the-var})
(try
(test)
(catch clojure.lang.ExceptionInfo e
(when-not (:kaocha/fail-fast (ex-data e))
(report/report-exception e)))
(catch Throwable e (report/report-exception e)))
(let [{::result/keys [pass error fail pending] :as result} (type/report-count)]
(when (= pass error fail pending 0)
(binding [testable/*fail-fast?* false
testable/*test-location* {:file (:file meta') :line (:line meta')}]
(t/do-report {:type ::zero-assertions}))))
(t/do-report {:type :end-test-var, :var the-var})
(merge testable {:kaocha.result/count 1} (type/report-count))))

(defmethod testable/-run :kaocha.type/var [{wrap :kaocha.testable/wrap
:as testable} test-plan]
(type/with-report-counters
(let [test (reduce #(%2 %1) test wrap)]
(binding [t/*testing-vars* (conj t/*testing-vars* the-var)]
(t/do-report {:type :begin-test-var, :var the-var})
(try
(test)
(catch clojure.lang.ExceptionInfo e
(when-not (:kaocha/fail-fast (ex-data e))
(report/report-exception e)))
(catch Throwable e (report/report-exception e))))
(let [{::result/keys [pass error fail pending] :as result} (type/report-count)]
(when (= pass error fail pending 0)
(binding [testable/*fail-fast?* false
testable/*test-location* {:file (:file meta') :line (:line meta')}]
(t/do-report {:type ::zero-assertions})))
(t/do-report {:type :end-test-var, :var the-var})
(merge testable {:kaocha.result/count 1} (type/report-count))))))
(let [wrapped-test (fn [] (test-var testable))
wrapped-test (reduce #(%2 %1) wrapped-test wrap)]
(wrapped-test))))

(s/def :kaocha.type/var (s/keys :req [:kaocha.testable/type
:kaocha.testable/id
Expand Down
3 changes: 2 additions & 1 deletion src/kaocha/watch.clj
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ errors as test errors."
:watch-paths watch-paths
:opts watcher-opts})
(when-let [config-file (get-in config [:kaocha/cli-options :config-file])]
(when (.exists (io/file config-file))
(when (and (= watcher-type :hawk) ;;Only Hawk supports watching single files.
(.exists (io/file config-file)))
(watch! {:type watcher-type
:q q
:watch-paths #{config-file}
Expand Down
10 changes: 6 additions & 4 deletions test/features/command_line/capability_check.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Feature: Capability check for org.clojure/tools.cli If a project's dependency
pulls in an old version of tools.cli, then this may break command line flags
of the form `--[no-]xxx`. Before starting the main command line runner, Kaocha
verifies that tools.cli has the necessary capabilities.
Feature: Capability check for org.clojure/tools.cli

If a project's dependency pulls in an old version of tools.cli, then this may
break command line flags of the form `--[no-]xxx`. Before starting the main
command line runner, Kaocha verifies that tools.cli has the necessary
capabilities.

Scenario: With an outdated tools.cli
When I run `clojure -Sdeps '{:deps {org.clojure/tools.cli {:mvn/version "0.3.5"}}}' --main kaocha.runner`
Expand Down
11 changes: 11 additions & 0 deletions test/unit/kaocha/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
:kaocha/ns-patterns ["-test$"]
:kaocha.result/tests
[{:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :baz.qux-test
:kaocha.result/tests
[{:kaocha.testable/type :kaocha.type/var
:kaocha.testable/id :baz.qux-test/nested-test
:kaocha.testable/desc "nested-test"
:kaocha.var/name 'baz.qux-test/nested-test
:kaocha.result/count 1
:kaocha.result/pass 1
:kaocha.result/error 1
:kaocha.result/fail 0}]}
{:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :foo.bar-test
:kaocha.result/tests
[{:kaocha.testable/type :kaocha.type/var
Expand Down
23 changes: 23 additions & 0 deletions test/unit/kaocha/type/clojure/test_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
:kaocha/test-paths ["fixtures/a-tests"]
:kaocha/ns-patterns [".*"]
:kaocha.test-plan/tests [{:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :baz.qux-test
:kaocha.ns/name 'baz.qux-test
:kaocha.ns/ns ns?
:kaocha.test-plan/tests [{:kaocha.testable/type :kaocha.type/var
:kaocha.testable/id :baz.qux-test/nested-test
:kaocha.var/name 'baz.qux-test/nested-test
:kaocha.var/var var?
:kaocha.var/test fn?}]}
{:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :foo.bar-test
:kaocha.ns/name 'foo.bar-test
:kaocha.ns/ns ns?
Expand All @@ -38,6 +47,20 @@
:kaocha/test-paths ["fixtures/a-tests"]
:kaocha/ns-patterns [".*"]
:kaocha.result/tests [{:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :baz.qux-test
:kaocha.ns/name 'baz.qux-test
:kaocha.ns/ns ns?
:kaocha.result/tests [{:kaocha.testable/type :kaocha.type/var
:kaocha.testable/id :baz.qux-test/nested-test
:kaocha.var/name 'baz.qux-test/nested-test
:kaocha.var/var var?
:kaocha.var/test fn?
:kaocha.result/count 1
:kaocha.result/pass 1
:kaocha.result/error 1
:kaocha.result/fail 0
:kaocha.result/pending 0}]}
{:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :foo.bar-test
:kaocha.ns/name 'foo.bar-test
:kaocha.ns/ns ns?
Expand Down
25 changes: 24 additions & 1 deletion test/unit/kaocha/type/ns_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,27 @@
:kaocha.result/fail 0}]}
(:result
(with-test-ctx {:fail-fast? true}
(testable/run testable testable)))))))
(testable/run testable testable))))))

(let [testable (testable/load {:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :baz.qux-test
:kaocha.testable/desc "baz.qux-test"
:kaocha.ns/name 'baz.qux-test})]
(is (match? {:kaocha.testable/type :kaocha.type/ns
:kaocha.testable/id :baz.qux-test
:kaocha.ns/name 'baz.qux-test
:kaocha.ns/ns ns?
:kaocha.result/tests [{:kaocha.testable/type :kaocha.type/var
:kaocha.testable/id :baz.qux-test/nested-test
:kaocha.testable/desc "nested-test"
:kaocha.var/name 'baz.qux-test/nested-test
:kaocha.var/var var?
:kaocha.var/test fn?
:kaocha.result/count 1
:kaocha.result/pass 1
:kaocha.result/error 1
:kaocha.result/pending 0
:kaocha.result/fail 0}]}
(:result
(with-test-ctx {}
(testable/run testable testable)))))))

0 comments on commit ab2d804

Please sign in to comment.