summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--custom/jao-custom-programming.el2
-rw-r--r--lib/prog/jao-rust.el31
2 files changed, 28 insertions, 5 deletions
diff --git a/custom/jao-custom-programming.el b/custom/jao-custom-programming.el
index 6106e9a..3f17c1a 100644
--- a/custom/jao-custom-programming.el
+++ b/custom/jao-custom-programming.el
@@ -343,7 +343,7 @@
:bind (:map rustic-mode-map (("C-c d" . rustic-cargo-build-doc)
("C-c t w" . jao-rust-test-workspace)
("C-c t m" . jao-rust-test-module)
- ("C-c t t" . rustic-cargo-current-test))))
+ ("C-c t t" . jao-rust-test-current))))
(use-package rust-playground
:ensure t)
diff --git a/lib/prog/jao-rust.el b/lib/prog/jao-rust.el
index 9c08e9b..fdc6b0d 100644
--- a/lib/prog/jao-rust.el
+++ b/lib/prog/jao-rust.el
@@ -40,14 +40,36 @@
(replace-regexp-in-string "/\\(mod\\|lib\\|main\\)$" "")
(string-replace "/" "::"))))
+(defconst jao-rust--test-header-rx
+ (concat "#\\[" (regexp-opt '("test" "quickcheck" "tokio::test") t)))
+
+(defconst jao-rust--test-name-rx "^ *\\(pub\\)?\\( async\\)? fn \\([^(]+\\)(")
+
+(defun jao-rust-test-at-point ()
+ (when (looking-at jao-rust--test-name-rx) (match-string-no-properties 3)))
+
+(defun jao-rust-test-before-point ()
+ (save-excursion
+ (when (re-search-backward jao-rust--test-header-rx nil t)
+ (forward-line)
+ (jao-rust-test-at-point))))
+
+(defun jao-rust-test-current ()
+ (interactive)
+ (if-let* ((m (jao-rust-current-module-name))
+ (n (jao-rust-test-before-point)))
+ (let ((rustic-test-arguments (format "-- --exact %s::tests::%s" m n))
+ (rustic-cargo-use-last-stored-arguments t))
+ (rustic-cargo-test))
+ (message "No test before point")))
+
(defun jao-rust-buffer-tests ()
(save-excursion
(goto-char (point-min))
(let ((res '()))
- (while (re-search-forward "#\\[\\(tokio::test\\|test\\|quickcheck\\)" nil t)
+ (while (re-search-forward jao-rust--test-header-rx nil t)
(forward-line)
- (when (looking-at "^ *\\(pub\\)?\\( async\\)? fn \\([^(]+\\)(")
- (push (match-string-no-properties 3) res)))
+ (when-let* ((name (jao-rust-test-at-point))) (push name res)))
res)))
(defun jao-rust-test-module ()
@@ -57,7 +79,8 @@
(messages "No tests in this module")
(let* ((mod (jao-rust-current-module-name))
(tests (mapconcat (lambda (x) (format "%s::tests::%s" mod x)) tests " "))
- (rustic-test-arguments (format "-- --exact %s" tests)))
+ (rustic-test-arguments (format "-- --exact %s" tests))
+ (rustic-cargo-use-last-stored-arguments t))
(rustic-cargo-test)))))
(defun jao-rust-test-workspace ()