From 5c11fc1947560a1535cf093e1fbab241b4412a97 Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 10 Mar 2026 10:22:26 +0000 Subject: more on rust tests --- lib/prog/jao-rust.el | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'lib') 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 () -- cgit v1.2.3