From 1b5a01ea70c0a86eca6f8cdc42c8d9324f1e3bb1 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Sun, 12 Jan 2025 21:48:14 +0530 Subject: [PATCH 1/4] Nextest integration: Provide a way to override test runner I have tested with these two commands specifically and can confirm it works fine: - rustic-cargo-test - rustic-cargo-current-test --- rustic-cargo.el | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/rustic-cargo.el b/rustic-cargo.el index 2cf7927..3a32ee9 100644 --- a/rustic-cargo.el +++ b/rustic-cargo.el @@ -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) @@ -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) @@ -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)) From b3a462973c9295aa856028c846fbd1b7bdd75bdc Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Sun, 12 Jan 2025 21:49:27 +0530 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.org | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 84db999..b928488 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -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 From f44b88ee4fb67e9aedf777f87212476918f445ad Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Fri, 21 Feb 2025 22:08:08 +0530 Subject: [PATCH 3/4] More cleanup --- rustic-cargo.el | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/rustic-cargo.el b/rustic-cargo.el index 3a32ee9..76a34e8 100644 --- a/rustic-cargo.el +++ b/rustic-cargo.el @@ -189,13 +189,10 @@ stored in this variable.") (when rustic-cargo-test-disable-warnings (setq-local rustic-compile-rustflags (concat rustic-compile-rustflags " -Awarnings")))) -(defun rustic--cargo-test-runner (is-filter) +(defun rustic--cargo-test-runner () "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)) + ((eq rustic-cargo-test-runner 'nextest) rustic-cargo-nextest-exec-command) (t (user-error "Invalid configured value for rustic-cargo-test-runner variable")))) ;;;###autoload @@ -203,7 +200,7 @@ stored in this variable.") "Start compilation process for 'cargo test' with optional TEST-ARGS." (interactive) (rustic-compilation-process-live) - (let* ((command (flatten-list (list (rustic-cargo-bin) (rustic--cargo-test-runner nil)))) + (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) @@ -254,7 +251,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 (flatten-list (list (rustic-cargo-bin) (rustic--cargo-test-runner t) 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)) From 625e4957ef424dc6f85fa38a0d6ed6472a5d9ba0 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Fri, 21 Feb 2025 22:20:20 +0530 Subject: [PATCH 4/4] Restore the removed lines --- rustic-cargo.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rustic-cargo.el b/rustic-cargo.el index 1a4ea0a..aa72382 100644 --- a/rustic-cargo.el +++ b/rustic-cargo.el @@ -241,8 +241,32 @@ If ARG is not nil, use value as argument and store it in "Run `cargo test' with `rustic-test-arguments'." (interactive "P") (let ((default-directory (or rustic-compilation-directory default-directory))) + (setq rustic-test-arguments + (if arg + (read-from-minibuffer "Cargo test arguments: " rustic-test-arguments nil nil 'rustic-test-history) + rustic-test-arguments)) (rustic-cargo-test-run rustic-test-arguments))) +(defun rustic-cargo-test-rerun-current (arg) + "Rerun the test at point from `rustic-cargo-test-mode'." + (interactive "P") + (let* ((default-directory (or rustic-compilation-directory default-directory)) + (test (rustic-cargo--get-test-at-point)) + (command (if test + (concat "-- --exact " test) + (error "No test found at point")))) + (setq rustic-test-arguments + (if arg + (read-from-minibuffer "Cargo test arguments: " command nil nil 'rustic-test-history) + command)) + (rustic-cargo-test-run rustic-test-arguments))) + +(defun rustic-cargo--get-test-at-point () + (save-excursion + (beginning-of-line) + (when (re-search-forward "^test \\([^ ]+\\) ..." (line-end-position) t) + (buffer-substring-no-properties (match-beginning 1) (match-end 1))))) + ;;;###autoload (defun rustic-cargo-current-test () "Run `cargo test' for the test near point."