diff --git a/rustic-compile.el b/rustic-compile.el index 778f5fe..ee19cbb 100644 --- a/rustic-compile.el +++ b/rustic-compile.el @@ -537,21 +537,19 @@ buffer." ;;; Interactive ;;;###autoload -(defun rustic-compile (&optional arg) - "Compile rust project. - -If the variable `compilation-read-command' is non-nil or if -`rustic-compile` is called with prefix argument ARG then read the -command in the minibuffer. Otherwise use -`rustic-compile-command'. - -In either store the used command in `compilation-arguments'." - (interactive "P") - (rustic-set-compilation-arguments - (if (or compilation-read-command arg) - (compilation-read-command (or (car compilation-arguments) - (rustic-compile-command))) - (rustic-compile-command))) +(defun rustic-compile (command) + "Run COMMAND in the current Rust workspace root. + +Interactively, prompts for the command if the variable +`compilation-read-command' is non-nil; otherwise uses +`rustic-compile-command'." + (interactive + (list + (if compilation-read-command + (compilation-read-command (or (car compilation-arguments) + (rustic-compile-command))) + (rustic-compile-command)))) + (rustic-set-compilation-arguments command) (setq compilation-directory (funcall rustic-compile-directory-method)) (rustic-compilation-process-live) (rustic-compilation-start (split-string (car compilation-arguments)) diff --git a/test/rustic-clippy-test.el b/test/rustic-clippy-test.el index 76f942a..ef8d98e 100644 --- a/test/rustic-clippy-test.el +++ b/test/rustic-clippy-test.el @@ -10,8 +10,7 @@ (let* ((buffer1 (get-buffer-create "b1")) (string "fn main() { String::from(' ').extend(String::from(' ').chars()); } ") (formatted-string "fn main() {\n String::from(' ').push_str(&String::from(' '));\n}\n") - (dir (rustic-babel-generate-project t)) - (compilation-read-command nil)) + (dir (rustic-babel-generate-project t))) (let* ((default-directory dir) (src (concat dir "/src")) (file1 (expand-file-name "main.rs" src)) @@ -63,8 +62,7 @@ (let* ((buffer1 (get-buffer-create "b1")) (string "ffn main() { String::from(' ').extend(String::from(' ').chars()); } ") (formatted-string "fn main() {\n String::from(' ').push_str(&String::from(' '));\n}\n") - (dir (rustic-babel-generate-project t)) - (compilation-read-command nil)) + (dir (rustic-babel-generate-project t))) (let* ((default-directory dir) (src (concat dir "/src")) (file1 (expand-file-name "main.rs" src)) diff --git a/test/rustic-compile-test.el b/test/rustic-compile-test.el index 66b050b..4a5c656 100644 --- a/test/rustic-compile-test.el +++ b/test/rustic-compile-test.el @@ -85,12 +85,25 @@ (ert-deftest rustic-test-compile () (let* ((dir (rustic-babel-generate-project t))) - (should-not compilation-directory) - (should-not compilation-arguments) - (setq compilation-arguments "cargo fmt") + (let* ((default-directory dir) + (proc (rustic-compile "cargo fmt"))) + (should (process-live-p proc)) + (while (eq (process-status proc) 'run) + (sit-for 0.1)) + (should (string= compilation-directory dir)) + (let ((proc (rustic-recompile))) + (while (eq (process-status proc) 'run) + (sit-for 0.1))) + (should (string= (car compilation-arguments) "cargo fmt")) + (should (string= compilation-directory dir)))) + (setq compilation-directory nil) + (setq compilation-arguments nil)) + +(ert-deftest rustic-test-compile-interactive () + (let* ((dir (rustic-babel-generate-project t))) (let* ((default-directory dir) (compilation-read-command nil) - (proc (rustic-compile))) + (proc (call-interactively 'rustic-compile))) (should (process-live-p proc)) (while (eq (process-status proc) 'run) (sit-for 0.1)) @@ -107,10 +120,9 @@ (let* ((string "fn main() { let s = 1;}") (buf (rustic-test-count-error-helper-new string)) (default-directory (file-name-directory (buffer-file-name buf))) - (rustic-format-trigger nil) - (compilation-read-command nil)) + (rustic-format-trigger nil)) (with-current-buffer buf - (let* ((proc (rustic-compile)) + (let* ((proc (rustic-compile "cargo build")) (buffer (process-buffer proc))) (while (eq (process-status proc) 'run) (sit-for 0.01)) diff --git a/test/rustic-window-test.el b/test/rustic-window-test.el index b5d7b09..a20decd 100644 --- a/test/rustic-window-test.el +++ b/test/rustic-window-test.el @@ -7,10 +7,8 @@ (ert-deftest rustic-test-window-count () (should (= (length (window-list)) 1)) (let* ((dir (rustic-babel-generate-project t))) - (setq compilation-arguments "cargo fmt") - (let* ((default-directory dir) - (compilation-read-command nil)) - (rustic-compile) + (let* ((default-directory dir)) + (rustic-compile "cargo fmt") (rustic-test--wait-till-finished rustic-compilation-buffer-name) (should (= (length (window-list)) 2)) (should (get-buffer-window rustic-compilation-buffer-name)))))