Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
option. This is handy when you are working on multiple
projects. Refer the variable docs and README for more details.
- Replace Cask with Eask for CI testing.
- Implement ~rustic-cargo-nextest-current-test~ for running test at a
point using nextest.
- Provde integration with [[https://nexte.st/][cargo nextest]]

* 3.5

Expand Down
44 changes: 17 additions & 27 deletions rustic-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
:type 'string
:group 'rustic-cargo)

(defcustom rustic-cargo-nextest-exec-command "nextest run"
(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 @@ -183,37 +189,21 @@ 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 (is-filter)
"Return the test runner command. IS-FILTER indicates if only specific test are filtered."
(cond ((eq rustic-cargo-test-runner 'cargo) rustic-cargo-test-exec-command)
((eq rustic-cargo-test-runner 'nextest)
(if is-filter
(list rustic-cargo-nextest-exec-command " -- ")
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 nil))))
(c (append command (split-string (if test-args test-args ""))))
(buf rustic-test-buffer-name)
(proc rustic-test-process-name)
Expand Down Expand Up @@ -264,7 +254,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 t) test)))
(buf rustic-test-buffer-name)
(proc rustic-test-process-name)
(mode 'rustic-cargo-test-mode))
Expand Down
Loading