diff --git a/rust-cargo-tests.el b/rust-cargo-tests.el index 1b072ee..a029b2a 100644 --- a/rust-cargo-tests.el +++ b/rust-cargo-tests.el @@ -60,6 +60,22 @@ (rust-test--wait-process-exit) (should (rust-test--find-string "***run interactive: 1234"))))) +(ert-deftest rust-test-test () + (skip-unless (executable-find rust-cargo-bin)) + (setq rust-cargo-default-arguments "") + (rust-test--with-main-file-buffer + (with-current-buffer (rust-test) + (rust-test--wait-process-exit) + (should (rust-test--find-string "running 1 test"))))) + +(ert-deftest rust-test-test-with-arg () + (skip-unless (executable-find rust-cargo-bin)) + (setq rust-cargo-default-arguments "") + (rust-test--with-main-file-buffer + (with-current-buffer (rust-test t t) + (rust-test--wait-process-exit) + (should (rust-test--find-string "***output test"))))) + (ert-deftest rust-test-rustfmt () (skip-unless (executable-find "rustfmt")) (rust-test--with-main-file-buffer diff --git a/rust-cargo.el b/rust-cargo.el index d323b5d..9e07fdd 100644 --- a/rust-cargo.el +++ b/rust-cargo.el @@ -129,10 +129,29 @@ output buffer will be in comint mode, i.e. interactive." (interactive "P") (rust--compile comint "%s run --release" rust-cargo-bin)) -(defun rust-test () - "Test using `cargo test`" - (interactive) - (rust--compile nil "%s test %s" rust-cargo-bin rust-cargo-default-arguments)) +(defun rust-test (&optional arg is-test) + "Test using `cargo test`. + +If prefixed with `C-u`, pass additional arguments to the command +(from a string read from the minibuffer). + +If optional arg IS-TEST is non-nil, +the argument `-- --show-output' will be automatically +added instead of being read from the minibuffer. + +Note that the IS-TEST arg is not meant for general use, +and only exists for testing the `rust-mode' package. " + (interactive "P") + (let ((test-command + (if arg + (progn + (let ((custom-arg + (if is-test + "-- --show-output" + (string-trim (read-string "Enter Arguments: "))))) + (concat "%s test " custom-arg " %s"))) + "%s test %s"))) + (rust--compile nil test-command rust-cargo-bin rust-cargo-default-arguments))) (defun rust-run-clippy () "Run `cargo clippy'." diff --git a/test-project/src/main.rs b/test-project/src/main.rs index 4d22e98..47fd06a 100644 --- a/test-project/src/main.rs +++ b/test-project/src/main.rs @@ -23,3 +23,11 @@ fn main() { } } } + +#[cfg(test)] +mod tests { + #[test] + fn test() { + println!("***output test"); + } +}