summaryrefslogtreecommitdiffhomepage
path: root/lib/prog
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2026-05-18 13:29:37 +0100
committerjao <jao@gnu.org>2026-05-18 13:29:37 +0100
commite55e64373c0b2ac0462df9e90417f854dcb16d11 (patch)
tree25482f6b06fc40592f3872f41185ffd035d0bdac /lib/prog
parent8743437098ad658446cb5b63b356e4e5c79170bc (diff)
downloadelibs-e55e64373c0b2ac0462df9e90417f854dcb16d11.tar.gz
elibs-e55e64373c0b2ac0462df9e90417f854dcb16d11.tar.bz2
rust: improvements locating validation testsmain
Diffstat (limited to 'lib/prog')
-rw-r--r--lib/prog/jao-rust.el33
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/prog/jao-rust.el b/lib/prog/jao-rust.el
index 5e20744..2281875 100644
--- a/lib/prog/jao-rust.el
+++ b/lib/prog/jao-rust.el
@@ -34,17 +34,23 @@
(let* ((root (expand-file-name (jao-rust--root)))
(current (file-name-sans-extension (buffer-file-name)))
(rel (string-replace root "" current)))
- (thread-last
- rel
- (replace-regexp-in-string "^src\\(/bin\\)?/" "")
- (string-replace "-" "_")
- (replace-regexp-in-string "/\\(mod\\|lib\\|main\\)$" "")
- (string-replace "/" "::"))))
+ (and (string-prefix-p "src/" rel)
+ (thread-last
+ rel
+ (replace-regexp-in-string "^src\\(/bin\\)?/" "")
+ (string-replace "-" "_")
+ (replace-regexp-in-string "/\\(mod\\|lib\\|main\\)$" "")
+ (string-replace "/" "::")))))
+
+(defun jao-rust--tests-prefix ()
+ (if-let* ((m (jao-rust-current-module-name)))
+ (concat m "::tests::")
+ ""))
(defconst jao-rust--test-header-rx
(concat "#\\[" (regexp-opt '("test" "quickcheck" "tokio::test") t)))
-(defconst jao-rust--test-name-rx "^ *\\(pub\\)?\\( async\\)? fn \\([^(]+\\)(")
+(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)))
@@ -62,6 +68,9 @@
(interactive)
(or (re-search-forward jao-rust--tests-mod-rx nil t)
(re-search-backward jao-rust--tests-mod-rx nil t)
+ (progn
+ (goto-char (point-min))
+ (re-search-forward jao-rust--test-header-rx nil t))
(when (y-or-n-p "No tests module. Add it?")
(goto-char (point-max))
(insert "\n#[cfg(test)]\nmod tests {\n\n}")
@@ -69,9 +78,9 @@
(defun jao-rust-test-current ()
(interactive)
- (if-let* ((m (jao-rust-current-module-name))
+ (if-let* ((m (jao-rust--tests-prefix))
(n (jao-rust-test-before-point)))
- (let ((rustic-test-arguments (format "-- --exact %s::tests::%s" m n))
+ (let ((rustic-test-arguments (format "-- --exact %s%s" m n))
(rustic-cargo-use-last-stored-arguments t))
(rustic-cargo-test))
(message "No test before point")))
@@ -89,9 +98,9 @@
(interactive)
(let ((tests (jao-rust-buffer-tests)))
(if (seq-empty-p tests)
- (messages "No tests in this module")
- (let* ((mod (jao-rust-current-module-name))
- (tests (mapconcat (lambda (x) (format "%s::tests::%s" mod x)) tests " "))
+ (message "No tests in this module")
+ (let* ((prefix (jao-rust--tests-prefix))
+ (tests (mapconcat (lambda (x) (format "%s%s" prefix x)) tests " "))
(rustic-test-arguments (format "-- --exact %s" tests))
(rustic-cargo-use-last-stored-arguments t))
(rustic-cargo-test)))))