Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replwrap style run function #69

Open
jcaplan opened this issue Sep 25, 2022 · 2 comments
Open

replwrap style run function #69

jcaplan opened this issue Sep 25, 2022 · 2 comments

Comments

@jcaplan
Copy link

jcaplan commented Sep 25, 2022

It would also be nice to borrow from replwrap and have a method to fold these three lines into one:

    p.send_line("hostname")?;
    let hostname = p.read_line()?;
    p.wait_for_prompt()?; // go sure `hostname` is really done

becomes something like

    let output = p.run("hostname")?;

other things that would help missing from pexpect that I've had to add for run(): take multiple commands to pass a script that you read from the host filesystem either as a vec or by splitting on newlines, sanitizing carriage returns, stripping out colour

@jcaplan
Copy link
Author

jcaplan commented Sep 25, 2022

another thing for a clean repl that's really helpful in driving embedded testing is nice color coded logging on the host. being able to assign each repl a name and getting something back like:

dut> ifconfig
dut<  insert_ifconfig_output_here

where dut< and dut> are coloured differently.
setup something like:

    let mut p = spawn_ssh(ip_addr, username, password)?
                .set_name('dut')
                .repl_log();
    let output = p.run("ifconfig")?;

works great if you're doing tests with multiple targets and/or also running stuff in a terminal on the host machine.

@jcaplan
Copy link
Author

jcaplan commented Sep 25, 2022

without colour/other control character stripping I get a test failure because my bash prompt pollutes the terminal. This is a problem people likely face with pexpect all the time (I know I have) and would be nice if there was a built-in way to deal with it.

test session::tests::test_bash ... FAILED                                              
test session::tests::test_kill_timeout ... ok                                          
test session::tests::test_bash_control_chars ... ok                                    
                                                                                       
failures:                                                                              
                                                                                       
---- session::tests::test_bash stdout ----                                             
thread 'session::tests::test_bash' panicked at 'assertion failed: `(left == right)`    
  left: `"/tmp\r\n"`,                                                                  
 right: `"\u{1b}[?2004l\r/tmp\r\n\u{1b}[?2004h"`', src/session.rs:540:13               
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace          

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant