-
Notifications
You must be signed in to change notification settings - Fork 0
Vendor eftest and fix #26 #46
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
+789
−67
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2ccb770
Vendor eftest; fix #26
camsaul a074d29
Delete eftest junit reporter since we have our own
camsaul 072e80e
Delete more unused parts of eftest
camsaul 79b4407
Cleanup :wrench:
camsaul 7b07684
Kondo cleanup :wrench:
camsaul 84e75b0
Rename the vendored eftest namespaces
camsaul f1fb680
Test fixes :wrench:
camsaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| Update `clj-kondo` configs for libraries using | ||
|
|
||
| ```sh | ||
| clj-kondo --copy-configs --dependencies --lint "$(clojure -Spath)" | ||
| clojure -M:kondo --copy-configs --dependencies --lint "$(clojure -Spath -A:dev)" | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| (ns mb.eftest.output-capture | ||
| (:import | ||
| (java.io ByteArrayOutputStream OutputStream PrintStream PrintWriter))) | ||
|
|
||
| (set! *warn-on-reflection* true) | ||
|
|
||
| (def ^:dynamic ^ByteArrayOutputStream *test-buffer* nil) | ||
|
|
||
| (defn read-test-buffer [] | ||
| (some-> *test-buffer* (.toByteArray) (String.))) | ||
|
|
||
| (def active-buffers (atom #{})) | ||
|
|
||
| (defmacro with-test-buffer [& body] | ||
| `(let [buffer# (ByteArrayOutputStream.)] | ||
| (try | ||
| (swap! active-buffers conj buffer#) | ||
| (binding [*test-buffer* buffer#] ~@body) | ||
| (finally (swap! active-buffers disj buffer#))))) | ||
|
|
||
| (defn- doto-capture-buffer [f] | ||
| (if *test-buffer* | ||
| (f *test-buffer*) | ||
| (doseq [buffer @active-buffers] | ||
| (f buffer)))) | ||
|
|
||
| (defn- create-proxy-output-stream ^OutputStream [] | ||
| (proxy [OutputStream] [] | ||
| (write | ||
| ([data] | ||
| (if (instance? Integer data) | ||
| (doto-capture-buffer #(.write ^OutputStream % ^int data)) | ||
| (doto-capture-buffer #(.write ^OutputStream % ^bytes data 0 (alength ^bytes data))))) | ||
| ([data off len] | ||
| (doto-capture-buffer #(.write ^OutputStream % data off len)))))) | ||
|
|
||
| (defn init-capture [] | ||
| (let [old-out System/out | ||
| old-err System/err | ||
| proxy-output-stream (create-proxy-output-stream) | ||
| new-stream (PrintStream. proxy-output-stream) | ||
| new-writer (PrintWriter. proxy-output-stream)] | ||
| (System/setOut new-stream) | ||
| (System/setErr new-stream) | ||
| {:captured-writer new-writer | ||
| :old-system-out old-out | ||
| :old-system-err old-err})) | ||
|
|
||
| (defn restore-capture [{:keys [old-system-out old-system-err]}] | ||
| (System/setOut old-system-out) | ||
| (System/setErr old-system-err)) | ||
|
|
||
| (defmacro with-capture [& body] | ||
| `(let [context# (init-capture) | ||
| writer# (:captured-writer context#)] | ||
| (try | ||
| (binding [*out* writer#, *err* writer#] | ||
| (with-redefs [*out* writer#, *err* writer#] | ||
| ~@body)) | ||
| (finally | ||
| (restore-capture context#))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| (ns mb.eftest.report | ||
| (:require | ||
| [clojure.java.io :as io] | ||
| [clojure.test :refer [*test-out*]])) | ||
|
|
||
| (set! *warn-on-reflection* true) | ||
|
|
||
| (def ^:dynamic *context* | ||
| "Used by eftest.runner/run-tests to hold a mutable atom that persists for the | ||
| duration of the test run. This atom can be used by reporters to hold | ||
| additional statistics and information during the tests." | ||
| nil) | ||
|
|
||
| (def ^:dynamic *testing-path* | ||
| "2-element vector [ns scope] where scope is either :clojure.test/once-fixtures, | ||
| :clojure.test/each-fixtures or var under test" | ||
| nil) | ||
|
|
||
| (defn report-to-file | ||
| "Wrap a report function so that its output is directed to a file. output-file | ||
| should be something that can be coerced into a Writer." | ||
| [report output-file] | ||
| (let [output-key [::output-files output-file]] | ||
| (fn [m] | ||
| (when (= (:type m) :begin-test-run) | ||
| (io/make-parents (io/file output-file)) | ||
| (swap! *context* assoc-in output-key (io/writer output-file))) | ||
| (let [^java.io.Writer writer (get-in @*context* output-key)] | ||
| (binding [*test-out* writer] | ||
| (report m)) | ||
| (when (= (:type m) :summary) | ||
| (swap! *context* update ::output-files dissoc output-file) | ||
| (.close writer)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| (ns mb.eftest.report.pretty | ||
| "A test reporter with an emphasis on pretty formatting." | ||
| (:refer-clojure :exclude [test]) | ||
| (:require | ||
| [clojure.data :as data] | ||
| [clojure.string :as str] | ||
| [clojure.test :as test] | ||
| [fipp.engine :as fipp] | ||
| [io.aviso.ansi :as ansi] | ||
| [io.aviso.exception :as exception] | ||
| [io.aviso.repl :as repl] | ||
| [mb.eftest.output-capture :as capture] | ||
| [mb.eftest.report :as report] | ||
| [puget.printer :as puget])) | ||
|
|
||
| (def ^:dynamic *fonts* | ||
| "The ANSI codes to use for reporting on tests." | ||
| {:exception ansi/red-font | ||
| :reset ansi/reset-font | ||
| :message ansi/italic-font | ||
| :property ansi/bold-font | ||
| :source ansi/italic-font | ||
| :function-name ansi/blue-font | ||
| :clojure-frame ansi/white-font | ||
| :java-frame ansi/reset-font | ||
| :omitted-frame ansi/reset-font | ||
| :pass ansi/green-font | ||
| :fail ansi/red-font | ||
| :error ansi/red-font | ||
| :divider ansi/yellow-font}) | ||
|
|
||
| (def ^:dynamic *divider* | ||
| "The divider to use between test failure and error reports." | ||
| "\n") | ||
|
|
||
| (defn- testing-scope-str [{:keys [file line]}] | ||
| (let [[test-ns scope] report/*testing-path*] | ||
| (str | ||
| (cond | ||
| (keyword? scope) | ||
| (str (:clojure-frame *fonts*) (ns-name test-ns) (:reset *fonts*) " during " | ||
| (:function-name *fonts*) scope (:reset *fonts*)) | ||
|
|
||
| (var? scope) | ||
| (str (:clojure-frame *fonts*) (ns-name test-ns) "/" | ||
| (:function-name *fonts*) (:name (meta scope)) (:reset *fonts*))) | ||
| (when (or file line) | ||
| (str " (" (:source *fonts*) file ":" line (:reset *fonts*) ")"))))) | ||
|
|
||
| (defn- diff-all [expected actuals] | ||
| (map vector actuals (map #(take 2 (data/diff expected %)) actuals))) | ||
|
|
||
| (defn- pretty-printer [] | ||
| (puget/pretty-printer {:print-color true | ||
| :print-meta false})) | ||
|
|
||
| (defn- pprint-document [doc] | ||
| (fipp/pprint-document doc {:width 80})) | ||
|
|
||
| (defn- equals-fail-report [{:keys [actual]}] | ||
| (let [[_ [_ expected & actuals]] actual | ||
| p (pretty-printer)] | ||
| (doseq [[actual [a b]] (diff-all expected actuals)] | ||
| (pprint-document | ||
| [:group | ||
| [:span "expected: " (puget/format-doc p expected) :break] | ||
| [:span " actual: " (puget/format-doc p actual) :break] | ||
| (when (and (not= expected a) (not= actual b)) | ||
| [:span " diff: " | ||
| (when a | ||
| [:span "- " (puget/format-doc p a) :break]) | ||
| (when b | ||
| [:span | ||
| (if a " + " "+ ") | ||
| (puget/format-doc p b)])])])))) | ||
|
|
||
| (defn- predicate-fail-report [{:keys [expected actual]}] | ||
| (let [p (pretty-printer)] | ||
| (pprint-document | ||
| [:group | ||
| [:span "expected: " (puget/format-doc p expected) :break] | ||
| [:span " actual: " (puget/format-doc p actual)]]))) | ||
|
|
||
| (defn- print-stacktrace [t] | ||
| (binding [exception/*traditional* true | ||
| exception/*fonts* *fonts*] | ||
| (repl/pretty-print-stack-trace t test/*stack-trace-depth*))) | ||
|
|
||
| (defn- error-report [{:keys [expected actual]}] | ||
| (if expected | ||
| (let [p (pretty-printer)] | ||
| (pprint-document | ||
| [:group | ||
| [:span "expected: " (puget/format-doc p expected) :break] | ||
| [:span " actual: " (with-out-str (print-stacktrace actual))]])) | ||
| (print-stacktrace actual))) | ||
|
|
||
| (defn- print-output [output] | ||
| (let [c (:divider *fonts*) | ||
| r (:reset *fonts*)] | ||
| (when-not (str/blank? output) | ||
| (println (str c "---" r " Test output " c "---" r)) | ||
| (println (str/trim-newline output)) | ||
| (println (str c "-------------------" r))))) | ||
|
|
||
| (defmulti report | ||
| "A reporting function compatible with clojure.test. Uses ANSI colors and | ||
| terminal formatting to produce readable and 'pretty' reports." | ||
| :type) | ||
|
|
||
| (defmethod report :default [_m]) | ||
|
|
||
| (defmethod report :pass [_m] | ||
| (test/with-test-out (test/inc-report-counter :pass))) | ||
|
|
||
| (defmethod report :fail [{:keys [message expected] :as m}] | ||
| (test/with-test-out | ||
| (test/inc-report-counter :fail) | ||
| (print *divider*) | ||
| (println (str (:fail *fonts*) "FAIL" (:reset *fonts*) " in") (testing-scope-str m)) | ||
| (when (seq test/*testing-contexts*) (println (test/testing-contexts-str))) | ||
| (when message (println message)) | ||
| (if (and (sequential? expected) | ||
| (= (first expected) '=)) | ||
| (equals-fail-report m) | ||
| (predicate-fail-report m)) | ||
| (print-output (capture/read-test-buffer)))) | ||
|
|
||
| (defmethod report :error [{:keys [message _expected _actual] :as m}] | ||
| (test/with-test-out | ||
| (test/inc-report-counter :error) | ||
| (print *divider*) | ||
| (println (str (:error *fonts*) "ERROR" (:reset *fonts*) " in") (testing-scope-str m)) | ||
| (when (seq test/*testing-contexts*) (println (test/testing-contexts-str))) | ||
| (when message (println message)) | ||
| (error-report m) | ||
| (some-> (capture/read-test-buffer) (print-output)))) | ||
|
|
||
| (defn- pluralize [word n] | ||
| (if (= n 1) word (str word "s"))) | ||
|
|
||
| (defn- format-interval [duration] | ||
| (format "%.3f seconds" (double (/ duration 1e3)))) | ||
|
|
||
| (defmethod report :long-test [{:keys [duration] :as m}] | ||
| (test/with-test-out | ||
| (print *divider*) | ||
| (println (str (:fail *fonts*) "LONG TEST" (:reset *fonts*) " in") (testing-scope-str m)) | ||
| (when duration (println "Test took" (format-interval duration) "seconds to run")))) | ||
|
|
||
| (defmethod report :summary [{:keys [test pass fail error duration]}] | ||
| (let [total (+ pass fail error) | ||
| color (if (= pass total) (:pass *fonts*) (:error *fonts*))] | ||
| (test/with-test-out | ||
| (print *divider*) | ||
| (println "Ran" test "tests in" (format-interval duration)) | ||
| (println (str color | ||
| total " " (pluralize "assertion" total) ", " | ||
| fail " " (pluralize "failure" fail) ", " | ||
| error " " (pluralize "error" error) "." | ||
| (:reset *fonts*)))))) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤝