-
-
Notifications
You must be signed in to change notification settings - Fork 652
Refine cider-test-run-test
#3481
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -60,13 +60,7 @@ | |
:type 'boolean | ||
:package-version '(cider . "0.9.0")) | ||
|
||
(defcustom cider-test-defining-forms '("deftest" "defspec") | ||
"Forms that define individual tests. | ||
CIDER considers the \"top-level\" form around point to define a test if | ||
the form starts with one of these forms. | ||
Add to this list to have CIDER recognize additional test defining macros." | ||
:type '(repeat string) | ||
:package-version '(cider . "0.15.0")) | ||
(make-obsolete 'cider-test-defining-forms nil "1.8.0") | ||
|
||
(defvar cider-test-last-summary nil | ||
"The summary of the last run test.") | ||
|
@@ -838,31 +832,52 @@ See `cider-test-rerun-test'." | |
(setq cider-test-last-test-ns ns | ||
cider-test-last-test-var var)) | ||
|
||
(defun cider--test-var-p (ns var) | ||
"Determines if the VAR in NS is a test." | ||
(if (cider-nrepl-op-supported-p "cider/get-state") | ||
(cider-resolve--get-in ns "interns" var "test") | ||
(equal "true" | ||
(nrepl-dict-get (cider-sync-tooling-eval | ||
(format "(clojure.core/-> %s var clojure.core/meta (clojure.core/contains? :test))" | ||
var) | ||
ns) | ||
"value")))) | ||
|
||
(defun cider-test-run-test () | ||
"Run the test at point. | ||
The test ns/var exist as text properties on report items and on highlighted | ||
failed/erred test definitions. When not found, a test definition at point | ||
is searched." | ||
failed/erred test definitions. | ||
|
||
When not found, a test definition at point | ||
or in a corresponding test namespace is searched." | ||
(interactive) | ||
(let ((ns (get-text-property (point) 'ns)) | ||
(var (get-text-property (point) 'var))) | ||
(if (and ns var) | ||
;; we're in a `cider-test-report-mode' buffer | ||
;; or on a highlighted failed/erred test definition | ||
(progn | ||
(cider-test-update-last-test ns var) | ||
(cider-test-execute ns (list var))) | ||
;; we're in a `clojure-mode' buffer | ||
(or (when-let* ((ns (cider-get-ns-name)) | ||
(def (clojure-find-def)) ; it's a list of the form (deftest something) | ||
(deftype (car def)) | ||
(var (cadr def))) | ||
(if (and ns (member deftype cider-test-defining-forms)) | ||
(progn | ||
(cider-test-update-last-test ns (list var)) | ||
(cider-test-execute ns (list var))) | ||
(message "No test at point"))) | ||
(message "No test at point"))))) | ||
(let* ((ns-from-text-property (get-text-property (point) 'ns)) | ||
(var-from-text-property (when ns-from-text-property | ||
;; we're in a `cider-test-report-mode' buffer | ||
;; or on a highlighted failed/erred test definition | ||
(get-text-property (point) 'var))) | ||
(found (or (when (and var-from-text-property | ||
|
||
;; Slightly redundant check. However querying `cider-resolve--get-in` is cheap: | ||
(cider--test-var-p ns-from-text-property var-from-text-property)) | ||
(list ns-from-text-property var-from-text-property)) | ||
(when-let* ((n (cider-get-ns-name)) | ||
(v (cadr (clojure-find-def)))) | ||
(or (when (cider--test-var-p n v) | ||
(list n v)) | ||
(let ((derived-ns (funcall cider-test-infer-test-ns n)) | ||
(derived-var (concat v "-test"))) | ||
;; deftest foo-test: | ||
(or (when (cider--test-var-p derived-ns derived-var) | ||
(list derived-ns derived-var)) | ||
;; deftest foo (less usual, but quite frequent): | ||
(when (cider--test-var-p derived-ns v) | ||
(list derived-ns v)))))))) | ||
(found-ns (car found)) | ||
(found-var (cadr found))) | ||
(if (not found-var) | ||
(message "No test found at point") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it could be a |
||
(cider-test-update-last-test found-ns (list found-var)) | ||
(cider-test-execute found-ns (list found-var))))) | ||
|
||
(defun cider-test-rerun-test () | ||
"Re-run the test that was previously ran." | ||
|
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
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.
This will do for now, but it'd be nice if we made something more portable at some point. I was also thinking it'd be handy to have a command that just dumps a var metadata in an overlay or a buffer.
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.
Speaking of, cljs functionality for our test-related functionality doesn't seem as hard as it might have been in the past.
Inspecting the cljs env, and
eval
ing cljs code seem pretty vanilla things to do nowadays. We could look into it soon enough.