diff options
Diffstat (limited to '.emacs.d/lisp/rust-cargo-tests.el')
| -rw-r--r-- | .emacs.d/lisp/rust-cargo-tests.el | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/.emacs.d/lisp/rust-cargo-tests.el b/.emacs.d/lisp/rust-cargo-tests.el new file mode 100644 index 0000000..f49cba0 --- /dev/null +++ b/.emacs.d/lisp/rust-cargo-tests.el | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | ;;; rust-cargo-tests.el --- ERT tests for rust-cargo.el -*- lexical-binding: t; -*- | ||
| 2 | (require 'rust-cargo) | ||
| 3 | (require 'ert) | ||
| 4 | |||
| 5 | (defun rust-test--wait-process-exit () | ||
| 6 | "Wait for comint process for current buffer to exit." | ||
| 7 | (let ((proc (get-buffer-process (current-buffer)))) | ||
| 8 | (while (not (eq (process-status proc) 'exit)) | ||
| 9 | (sit-for 0.2)))) | ||
| 10 | |||
| 11 | (defun rust-test--send-process-string (string) | ||
| 12 | "Send STRING to comint process for current buffer." | ||
| 13 | (let ((proc (get-buffer-process (current-buffer)))) | ||
| 14 | (comint-send-string proc string))) | ||
| 15 | |||
| 16 | (defmacro rust-test--with-main-file-buffer (expr) | ||
| 17 | `(let* ((test-dir (expand-file-name "test-project/" default-directory)) | ||
| 18 | (main-file (expand-file-name "src/main.rs" test-dir))) | ||
| 19 | (save-current-buffer | ||
| 20 | (find-file main-file) | ||
| 21 | ,expr))) | ||
| 22 | |||
| 23 | (defun rust-test--find-string (string) | ||
| 24 | "Find STRING in current buffer." | ||
| 25 | (goto-char (point-min)) | ||
| 26 | (not (null (search-forward string nil t)))) | ||
| 27 | |||
| 28 | |||
| 29 | (ert-deftest rust-test-compile () | ||
| 30 | (skip-unless (executable-find rust-cargo-bin)) | ||
| 31 | (setq rust-cargo-default-arguments "") | ||
| 32 | (rust-test--with-main-file-buffer | ||
| 33 | (with-current-buffer (rust-compile) | ||
| 34 | (rust-test--wait-process-exit) | ||
| 35 | (should (rust-test--find-string "Compilation finished"))))) | ||
| 36 | |||
| 37 | (ert-deftest rust-test-run () | ||
| 38 | (skip-unless (executable-find rust-cargo-bin)) | ||
| 39 | (setq rust-cargo-default-arguments "") | ||
| 40 | (rust-test--with-main-file-buffer | ||
| 41 | (with-current-buffer (rust-run) | ||
| 42 | (rust-test--wait-process-exit) | ||
| 43 | (should (rust-test--find-string "***run not interactive"))))) | ||
| 44 | |||
| 45 | (ert-deftest rust-test-run-interactive () | ||
| 46 | (skip-unless (executable-find rust-cargo-bin)) | ||
| 47 | (setq rust-cargo-default-arguments "interactive") | ||
| 48 | (rust-test--with-main-file-buffer | ||
| 49 | ;; '(4) is default value when called interactively with universal argument | ||
| 50 | (with-current-buffer (rust-run '(4)) | ||
| 51 | (rust-test--send-process-string "1234\n") | ||
| 52 | (rust-test--wait-process-exit) | ||
| 53 | (should (rust-test--find-string "***run interactive: 1234"))))) | ||
