summaryrefslogtreecommitdiffhomepage
path: root/lib/prog
diff options
context:
space:
mode:
Diffstat (limited to 'lib/prog')
-rw-r--r--lib/prog/jao-rust.el54
1 files changed, 49 insertions, 5 deletions
diff --git a/lib/prog/jao-rust.el b/lib/prog/jao-rust.el
index 9c08e9b..436de00 100644
--- a/lib/prog/jao-rust.el
+++ b/lib/prog/jao-rust.el
@@ -20,7 +20,8 @@
;;; Code:
-(defun jao-rust--root () (project-root (project-current)))
+(defun jao-rust--root ()
+ (locate-dominating-file default-directory "Cargo.toml"))
(defun jao-rust-open-cargo ()
(interactive)
@@ -40,14 +41,45 @@
(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))))
+
+
+(defconst jao-rust--tests-mod-rx "^\\(pub\\)? *mod tests {")
+
+(defun jao-rust-goto-tests ()
+ (interactive)
+ (or (re-search-forward jao-rust--tests-mod-rx nil t)
+ (re-search-backward jao-rust--tests-mod-rx nil t)
+ (message "No tests module")))
+
+(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,13 +89,25 @@
(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-retest ()
+ (interactive)
+ (let* ((rustic-test-arguments "-R latest")
+ (rustic-cargo-use-last-stored-arguments t))
+ (rustic-cargo-test)))
+
(defun jao-rust-test-workspace ()
(interactive)
(let ((rustic-test-arguments rustic-default-test-arguments))
(rustic-cargo-test)))
+
+(defun jao-rust-build-doc (deps)
+ (interactive "P")
+ (rustic-run-cargo-command `(,(rustic-cargo-bin) "doc" ,@(unless deps '("--no-deps")))))
+
(provide 'jao-rust)
;;; jao-rust.el ends here