Skip to content

Fix and clean up load-error handling, remove Orchestra #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
- kaocha/execute:
args: "integration --reporter documentation --plugin cloverage --codecov"
clojure_version: << parameters.clojure_version >>
- kaocha/execute:
args: "generative-fdef-checks --reporter documentation"
clojure_version: << parameters.clojure_version >>
- kaocha/upload_codecov:
flags: integration
file: target/coverage/integration*/codecov.json
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
## Added

## Fixed

- Fix load-error handling in `kaocha.watch`
- Fix `could not resolve symbol require` error that occured sporadically when requiring certain kaocha namespaces.
- Fix printing of boolean options in the print-invocations plugin
- Fix Java reflection warning in the Notifier plugin

## Changed

- [BREAKING] Remove the Orchestra dependency, and no longer auto-instrument.
You'll have to list Orchestra in your own `deps.edn`/`project.clj` if you want
to use the Orchestra plugin.
- Version bumps of Clojure, tools.cli, spec.alpha, expound

# 1.0.861 (2021-05-21 / dbfd6e8)

## Added

- Formatting of failed test results using deep-diff can be disabled with `--diff-style :none` on the command line or `:diff-style :none` in `tests.edn`.

## Fixed

- Fix at least some cases of syntax errors being suppressed by the "no tests found" message.

## Changed
Expand Down
2 changes: 1 addition & 1 deletion bin/kaocha
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
clojure -J-Dline.separator=$'\n' -A:dev:test -m kaocha.runner "$@"
clojure -J-Dline.separator=$'\n' -A:dev:test -M -m kaocha.runner "$@"
24 changes: 13 additions & 11 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
{:paths ["src" "resources"]

:deps
{org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/spec.alpha {:mvn/version "0.2.187"}
org.clojure/tools.cli {:mvn/version "1.0.194"}
{org.clojure/clojure {:mvn/version "1.10.3"}
org.clojure/spec.alpha {:mvn/version "0.2.194"}
org.clojure/tools.cli {:mvn/version "1.0.206"}
lambdaisland/tools.namespace {:mvn/version "0.0-237"}
lambdaisland/deep-diff {:mvn/version "0.0-47"}
org.tcrawley/dynapath {:mvn/version "1.1.0"}
slingshot/slingshot {:mvn/version "0.12.2"}
hawk/hawk {:mvn/version "0.2.11"}
expound/expound {:mvn/version "0.8.5"}
orchestra/orchestra {:mvn/version "2020.07.12-1"}
expound/expound {:mvn/version "0.8.9"}
aero/aero {:mvn/version "1.1.6"}
progrock/progrock {:mvn/version "0.1.2"}
meta-merge/meta-merge {:mvn/version "1.0.0"}}

:aliases
{:test
{:extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}
lambdaisland/kaocha-cucumber {:mvn/version "0.0-53" :exclusions [lambdaisland/kaocha]}
lambdaisland/kaocha-cloverage {:mvn/version "1.0.75" :exclusions [lambdaisland/kaocha]}
nubank/matcher-combinators {:mvn/version "1.5.2"}
akvo/fs {:mvn/version "20180904-152732.6dad3934"}}}
{:extra-paths ["test/shared" "test/unit"]
:extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}
lambdaisland/kaocha-cucumber {:mvn/version "0.0-53" :exclusions [lambdaisland/kaocha]}
lambdaisland/kaocha-cloverage {:mvn/version "1.0.75" :exclusions [lambdaisland/kaocha]}
nubank/matcher-combinators {:mvn/version "1.5.2"}
akvo/fs {:mvn/version "20180904-152732.6dad3934"}
orchestra/orchestra {:mvn/version "2020.07.12-1"}}}

:dev
{}}}
{:extra-paths ["dev"]
:extra-deps {djblue/portal {:mvn/version "RELEASE"}}}}}
17 changes: 17 additions & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns user)

(defmacro jit [sym]
`(requiring-resolve '~sym))

(def portal-instance (atom nil))

(defn portal
"Open a Portal window and register a tap handler for it. The result can be
treated like an atom."
[]
;; Portal is both an IPersistentMap and an IDeref, which confuses pprint.
(prefer-method @(jit clojure.pprint/simple-dispatch) clojure.lang.IPersistentMap clojure.lang.IDeref)
(let [p ((jit portal.api/open) @portal-instance)]
(reset! portal-instance p)
(add-tap (jit portal.api/submit))
p))
7 changes: 4 additions & 3 deletions src/kaocha/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[kaocha.plugin :as plugin]
[kaocha.report :as report]
[kaocha.result :as result]
[kaocha.util :as util]
[kaocha.stacktrace :as stacktrace]
[kaocha.testable :as testable]
[slingshot.slingshot :refer [try+ throw+]]))
Expand Down Expand Up @@ -72,10 +73,10 @@
(if (:kaocha/fail-fast (ex-data e))
(throw e)
(do
(output/error "Error in reporter: " (ex-data e) " when processing " (:type m))
(output/error "Error in reporter: " (ex-data e) " when processing " (pr-str (util/minimal-test-event m)))
(stacktrace/print-cause-trace e))))
(catch Throwable t
(output/error "Error in reporter: " (.getClass t) " when processing " (:type m))
(output/error "Error in reporter: " (.getClass t) " when processing " (pr-str (util/minimal-test-event m)))
(stacktrace/print-cause-trace t))))))

(catch :kaocha/reporter-not-found {:kaocha/keys [reporter-not-found]}
Expand All @@ -101,7 +102,7 @@
(when-not (some #(or (hierarchy/leaf? %)
(::testable/load-error %))
(testable/test-seq test-plan))

(output/warn (str "No tests were found, make sure :test-paths and "
":ns-patterns are configured correctly in tests.edn."))
(throw+ {:kaocha/early-exit 0 }))
Expand Down
30 changes: 14 additions & 16 deletions src/kaocha/plugin/notifier.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
[clojure.java.io :as io]
[slingshot.slingshot :refer [throw+]])
(:import [java.nio.file Files]
[java.io IOException]
[java.awt SystemTray TrayIcon TrayIcon$MessageType Toolkit]))
[java.io IOException]
[java.awt SystemTray TrayIcon TrayIcon$MessageType Toolkit]))

;; special thanks for terminal-notify stuff to
;; https://github.com/glittershark/midje-notifier/blob/master/src/midje/notifier.clj

(defn exists? [program]
(let [cmd (if (platform/on-windows?)
"where.exe" "which" )]
(try
(try
(= 0 (:exit (sh cmd program)))
(catch IOException e ;in the unlikely event where.exe or which isn't available
(output/warn (format "Unable to determine whether '%s' exists. Notifications may not work." program)) ))))


(defn detect-command []
(cond
(exists? "notify-send")
Expand Down Expand Up @@ -64,32 +63,31 @@
(io/copy (io/make-input-stream resource {}) file)
(str file)))))))


(def tray-icon
"Creates a system tray icon."
(memoize
(fn [icon-path]
(let [tray-icon (-> (Toolkit/getDefaultToolkit)
(.getImage icon-path)
(TrayIcon. "Kaocha Notification"))]
(doto (SystemTray/getSystemTray)
(.add tray-icon))
tray-icon))))

(defn send-tray-notification
(fn [icon-path]
(let [^java.awt.Toolkit toolkit (Toolkit/getDefaultToolkit)
tray-icon (-> toolkit
(.getImage ^String icon-path)
(TrayIcon. "Kaocha Notification"))]
(doto (SystemTray/getSystemTray)
(.add tray-icon))
tray-icon))))

(defn send-tray-notification
"Use Java's built-in functionality to display a notification.

Not preferred over shelling out because the built-in notification sometimes
looks out of place, and isn't consistently available on Linux."
[result]
(try
(try
(let [icon (tray-icon "kaocha/clojure_logo.png")
urgency (if (result/failed? result) TrayIcon$MessageType/ERROR TrayIcon$MessageType/INFO) ]
(.displayMessage icon (title result) (message result) urgency))
(catch java.awt.HeadlessException e
(output/warn (str "Notification not shown because system is headless. AWT error: " e)) )))


(defn expand-command
"Takes a command string including replacement patterns, and a map of
replacements, and returns a vector of command + arguments.
Expand Down
2 changes: 1 addition & 1 deletion src/kaocha/plugin/profiling.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
(when (::profiling? result)
(let [tests (->> result
testable/test-seq
(remove :kaocha.test-plan/load-error)
(remove ::testable/load-error)
(remove ::testable/skip))
types (group-by :kaocha.testable/type tests)
total-dur (::duration result)
Expand Down
29 changes: 9 additions & 20 deletions src/kaocha/report.clj
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,19 @@
(kaocha.hierarchy/derive! :mismatch :kaocha/fail-type)
```"
(:refer-clojure :exclude [symbol])
(:require [kaocha.core-ext :refer :all]
(:require [clojure.string :as str]
[clojure.test :as t]
[kaocha.core-ext :refer :all]
[kaocha.hierarchy :as hierarchy]
[kaocha.history :as history]
[kaocha.jit :refer [jit]]
[kaocha.output :as output]
[kaocha.plugin.capture-output :as capture]
[kaocha.stacktrace :as stacktrace]
[kaocha.testable :as testable]
[clojure.test :as t]
[slingshot.slingshot :refer [throw+]]
[clojure.string :as str]
[kaocha.history :as history]
[kaocha.testable :as testable]
[kaocha.hierarchy :as hierarchy]
[kaocha.jit :refer [jit]]))
[kaocha.util :as util]
[slingshot.slingshot :refer [throw+]]))

(defonce clojure-test-report t/report)

Expand Down Expand Up @@ -414,19 +415,7 @@

(defn debug [m]
(t/with-test-out
(prn (cond-> (select-keys m [:type
:file
:line
:var
:ns
:expected
:actual
:message
:kaocha/testable
:debug
::printed-expression])
(:kaocha/testable m)
(update :kaocha/testable select-keys [:kaocha.testable/id :kaocha.testable/type])))))
(prn (util/minimal-test-event m))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
26 changes: 10 additions & 16 deletions src/kaocha/runner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@
(ns kaocha.runner
"Main entry point for command line use."
(:gen-class)
(:require [kaocha.api :as api]
[clojure.java.io :as io]
(:require [clojure.java.io :as io]
[clojure.pprint :as pprint]
[clojure.set :as set]
[clojure.spec.alpha :as spec]
[clojure.string :as str]
[clojure.tools.cli :as cli]
[expound.alpha :as expound]
[kaocha.api :as api]
[kaocha.config :as config]
[kaocha.jit :refer [jit]]
[kaocha.output :as output]
[kaocha.plugin :as plugin]
[kaocha.result :as result]
[kaocha.specs :as specs]
[orchestra.spec.test :as orchestra]
[slingshot.slingshot :refer [try+ throw+]])
(:import [java.io File]))

(orchestra/instrument
(filter #(or (str/starts-with? (str %) "kaocha.")
(str/starts-with? (str %) "lambdaisland."))
(map ns-name (all-ns))))
[slingshot.slingshot :refer [throw+ try+]])
(:import java.io.File))

(defn- accumulate [m k v]
(update m k (fnil conj []) v))
Expand Down Expand Up @@ -159,17 +153,17 @@
(config/load-config (if profile
{:profile profile}
{})))
_check_config_file (when (not (. (File. (or config-file "tests.edn")) exists))
(output/warn (format (str "Did not load a configuration file and using the defaults.\n"
_check_config_file (when (not (. (File. (or config-file "tests.edn")) exists))
(output/warn (format (str "Did not load a configuration file and using the defaults.\n"
"This is fine for experimenting, but for long-term use, we recommend creating a configuration file to avoid changes in behavior between releases.\n"
"To create a configuration file using the current defaults, create a file named tests.edn that contains '#%s {}'.")
config/current-reader)))
_check (try
_check (try
(specs/assert-spec :kaocha/config config)
(catch AssertionError e
(output/error "Invalid configuration file:\n"
(catch AssertionError e
(output/error "Invalid configuration file:\n"
(.getMessage e))
(throw+ {:kaocha/early-exit 252})))
(throw+ {:kaocha/early-exit 252})))
plugin-chain (plugin/load-all (concat (:kaocha/plugins config) plugin))
cli-options (plugin/run-hook* plugin-chain :kaocha.hooks/cli-options cli-options)

Expand Down
8 changes: 4 additions & 4 deletions src/kaocha/specs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@
(s/keys :req []
:opt [:kaocha.testable/desc
:kaocha.test-plan/tests
:kaocha.test-plan/load-error])))
:kaocha.testable/load-error])))

(s/def :kaocha.test-plan/load-error (s-with-gen
#(instance? Throwable %)
#(s-gen #{(ex-info "load error" {:oops "not good"})})))
(s/def :kaocha.testable/load-error (s-with-gen
#(instance? Throwable %)
#(s-gen #{(ex-info "load error" {:oops "not good"})})))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; result
Expand Down
Loading