-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #544 from isvilen/run-interactive
Support running interactive programs
- Loading branch information
Showing
6 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
*-autoloads.el | ||
/rust-mode-pkg.el | ||
.eask | ||
/dist | ||
/dist | ||
test-project/Cargo.lock | ||
test-project/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
;;; rust-cargo-tests.el --- ERT tests for rust-cargo.el -*- lexical-binding: t; -*- | ||
(require 'rust-cargo) | ||
(require 'ert) | ||
|
||
(defun rust-test--wait-process-exit () | ||
"Wait for comint process for current buffer to exit." | ||
(let ((proc (get-buffer-process (current-buffer)))) | ||
(while (not (eq (process-status proc) 'exit)) | ||
(sit-for 0.2)))) | ||
|
||
(defun rust-test--send-process-string (string) | ||
"Send STRING to comint process for current buffer." | ||
(let ((proc (get-buffer-process (current-buffer)))) | ||
(comint-send-string proc string))) | ||
|
||
(defmacro rust-test--with-main-file-buffer (expr) | ||
`(let* ((test-dir (expand-file-name "test-project/" default-directory)) | ||
(main-file (expand-file-name "src/main.rs" test-dir))) | ||
(save-current-buffer | ||
(find-file main-file) | ||
,expr))) | ||
|
||
(defun rust-test--find-string (string) | ||
"Find STRING in current buffer." | ||
(goto-char (point-min)) | ||
(not (null (search-forward string nil t)))) | ||
|
||
|
||
(ert-deftest rust-test-compile () | ||
(skip-unless (executable-find rust-cargo-bin)) | ||
(setq rust-cargo-default-arguments "") | ||
(rust-test--with-main-file-buffer | ||
(with-current-buffer (rust-compile) | ||
(rust-test--wait-process-exit) | ||
(should (rust-test--find-string "Compilation finished"))))) | ||
|
||
(ert-deftest rust-test-run () | ||
(skip-unless (executable-find rust-cargo-bin)) | ||
(setq rust-cargo-default-arguments "") | ||
(rust-test--with-main-file-buffer | ||
(with-current-buffer (rust-run) | ||
(rust-test--wait-process-exit) | ||
(should (rust-test--find-string "***run not interactive"))))) | ||
|
||
(ert-deftest rust-test-run-interactive () | ||
(skip-unless (executable-find rust-cargo-bin)) | ||
(setq rust-cargo-default-arguments "interactive") | ||
(rust-test--with-main-file-buffer | ||
;; '(4) is default value when called interactively with universal argument | ||
(with-current-buffer (rust-run '(4)) | ||
(rust-test--send-process-string "1234\n") | ||
(rust-test--wait-process-exit) | ||
(should (rust-test--find-string "***run interactive: 1234"))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::{env, io}; | ||
|
||
fn main() { | ||
let mut args = env::args(); | ||
|
||
if args.len() == 1 { | ||
println!("***run not interactive"); | ||
} else { | ||
match args.nth(1).unwrap().as_str() { | ||
"interactive" => { | ||
let mut line = String::new(); | ||
|
||
io::stdin() | ||
.read_line(&mut line) | ||
.expect("Failed to read line"); | ||
|
||
println!("***run interactive: {line}"); | ||
} | ||
|
||
_ => { | ||
panic!("unexpected argument"); | ||
} | ||
} | ||
} | ||
} |