Skip to content
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

Integration with cargo nextest #87

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fixed an issue where workspaces were not resolved correctly over TRAMP.
- Implement ~rustic-cargo-test-rerun-current~ for rerunning the
current test from the compile buffer.
- Provde integration with [[https://nexte.st/][cargo nextest]]

* 3.5

Expand Down
43 changes: 15 additions & 28 deletions rustic-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@
:type 'string
:group 'rustic-cargo)

(defcustom rustic-cargo-nextest-exec-command "nextest run"
"Execute command to run `nextest'."
(defcustom rustic-cargo-test-runner 'cargo
"Test runner to use for running tests. By default uses cargo."
:type '(choice (const cargo)
(const nextest))
:group 'rustic-cargo)

(defcustom rustic-cargo-nextest-exec-command (list "nextest" "run")
"Execute command to run nextest."
:type 'string
:group 'rustic-cargo)

Expand Down Expand Up @@ -188,37 +194,18 @@ stored in this variable.")
(when rustic-cargo-test-disable-warnings
(setq-local rustic-compile-rustflags (concat rustic-compile-rustflags " -Awarnings"))))

(defun rustic-cargo-run-nextest (&optional arg)
"Command for running nextest.

If ARG is not nil, get input from minibuffer."
(interactive "P")
(let* ((nextest (if arg
(read-from-minibuffer "nextest command: " rustic-cargo-nextest-exec-command)
rustic-cargo-nextest-exec-command))
(c (-flatten (list (rustic-cargo-bin) (split-string nextest))))
(buf rustic-test-buffer-name)
(proc rustic-test-process-name)
(mode 'rustic-cargo-test-mode))
(rustic-compilation c (list :buffer buf :process proc :mode mode))))

(defun rustic-cargo-nextest-current-test ()
"Run `cargo nextest run' for the test near point."
(interactive)
(rustic-compilation-process-live)
(-if-let (test-to-run (setq rustic-test-arguments
(rustic-cargo--get-test-target)))
(let ((rustic-cargo-nextest-exec-command
(format "%s %s" rustic-cargo-nextest-exec-command test-to-run)))
(rustic-cargo-run-nextest))
(message "Could not find test at point.")))
(defun rustic--cargo-test-runner ()
"Return the test runner command."
(cond ((eq rustic-cargo-test-runner 'cargo) rustic-cargo-test-exec-command)
((eq rustic-cargo-test-runner 'nextest) rustic-cargo-nextest-exec-command)
(t (user-error "Invalid configured value for rustic-cargo-test-runner variable"))))

;;;###autoload
(defun rustic-cargo-test-run (&optional test-args)
"Start compilation process for `cargo test' with optional TEST-ARGS."
(interactive)
(rustic-compilation-process-live)
(let* ((command (list (rustic-cargo-bin) rustic-cargo-test-exec-command))
(let* ((command (flatten-list (list (rustic-cargo-bin) (rustic--cargo-test-runner))))
(c (append command (split-string (if test-args test-args ""))))
(buf rustic-test-buffer-name)
(proc rustic-test-process-name)
Expand Down Expand Up @@ -297,7 +284,7 @@ If ARG is not nil, use value as argument and store it in

(defun rustic-cargo-run-test (test)
"Run TEST which can be a single test or mod name."
(let* ((c (list (rustic-cargo-bin) rustic-cargo-test-exec-command test))
(let* ((c (flatten-list (list (rustic-cargo-bin) (rustic--cargo-test-runner) test)))
(buf rustic-test-buffer-name)
(proc rustic-test-process-name)
(mode 'rustic-cargo-test-mode))
Expand Down