-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API and interface for inspecting exceptions
This adds a new `analyze_exception` API which will analyze a givena symbol using the same logic used for test reporting. This exception analysis will then be used to render a dedicated exception popup window.
- Loading branch information
1 parent
6a45440
commit fa55aa9
Showing
9 changed files
with
114 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,42 @@ | ||
(ns io.julienvincent.clojure-test.serialization | ||
(:require | ||
[clj-commons.format.exceptions :as pretty.exceptions] | ||
[clojure.pprint :as pprint])) | ||
|
||
(defn- remove-commas | ||
"Clojures pprint function adds commas in whitespace. This removes them while maintaining | ||
any commas that are within strings" | ||
[s] | ||
(let [pattern #"(?<=^|[^\\])(\"(?:[^\"\\]|\\.)*\"|[^,\"]+)|(,)" | ||
matches (re-seq pattern s)] | ||
(apply str (map | ||
(fn [[_ group1]] | ||
(or group1 "")) | ||
matches)))) | ||
|
||
(defn- pretty-print [data] | ||
(-> (with-out-str | ||
(pprint/pprint data)) | ||
remove-commas)) | ||
|
||
(defn parse-diff [diff] | ||
(when-let [mc (try (requiring-resolve 'matcher-combinators.config/disable-ansi-color!) | ||
(catch Exception _))] | ||
(mc)) | ||
|
||
(cond | ||
(= :matcher-combinators.clj-test/mismatch (:type (meta diff))) | ||
(-> diff pr-str remove-commas) | ||
|
||
:else | ||
(pretty-print diff))) | ||
|
||
(defn analyze-exception [exception] | ||
(mapv | ||
(fn [{:keys [properties] :as ex}] | ||
(let [props (when properties | ||
(pretty-print properties))] | ||
(if props | ||
(assoc ex :properties props) | ||
ex))) | ||
(pretty.exceptions/analyze-exception exception {}))) |
This file contains 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 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,16 @@ | ||
local ui_exceptions = require("clojure-test.ui.exceptions") | ||
local config = require("clojure-test.config") | ||
|
||
local M = {} | ||
|
||
function M.render_exception(sym) | ||
local exceptions = config.backend:analyze_exception(sym) | ||
if not exceptions or exceptions == vim.NIL then | ||
return | ||
end | ||
|
||
local popup = ui_exceptions.open_exception_popup() | ||
ui_exceptions.render_exceptions_to_buf(popup.bufnr, exceptions) | ||
end | ||
|
||
return M |
This file contains 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 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 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