trying rust expect

This commit is contained in:
Anton-4 2023-09-19 16:14:27 +02:00
parent 2c88674d97
commit 40ba121148
No known key found for this signature in database
GPG Key ID: 0971D718C0A9B937
7 changed files with 58 additions and 36 deletions

View File

@ -40,7 +40,12 @@ jobs:
run: cd roc_nightly && ./roc examples/platform-switching/rocLovesC.roc
- name: test repl
run: cd roc_nightly && expect ../ci/repl_test.exp
run: |
cd ci/repl_basic_test
cargo build --release
cp /target/release/repl_basic_test ../../roc_nightly
cd ../../roc_nightly
./repl_basic_test

View File

@ -23,7 +23,6 @@ jobs:
if: startsWith(matrix.os, 'ubuntu')
run: |
curl -fOL https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linux_x86_64-latest.tar.gz
sudo apt install -y expect
- name: get the latest release archive for macos (x86_64)

View File

@ -30,6 +30,7 @@ members = [
exclude = [
"ci/benchmarks/bench-runner",
"ci/repl_basic_test",
# Examples sometimes have Rust hosts in their platforms. The compiler should ignore those.
"crates/cli_testing_examples",
"examples",

View File

@ -56,6 +56,11 @@ fi
./roc examples/platform-switching/rocLovesC.roc
# test repl
expect ../ci/repl_test.exp
cd ../ci/repl_basic_test
cargo build --release
cp /target/release/repl_basic_test ../../roc_nightly
cd ../../roc_nightly
./repl_basic_test
cd ..

View File

@ -0,0 +1,9 @@
[package]
name = "repl_basic_test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rexpect = "0.5.0"

View File

@ -0,0 +1,36 @@
use rexpect::error::Error;
use rexpect::session::PtyReplSession;
use rexpect::spawn;
use std::thread;
use std::time::Duration;
fn roc_repl_session() -> Result<PtyReplSession, Error> {
let roc_repl = PtyReplSession {
echo_on: false,
prompt: "\u{1b}[0K\u{1b}[34m»\u{1b}[0m ".to_string(),
pty_session: spawn("./roc repl", Some(7000))?,
quit_command: None,
};
thread::sleep(Duration::from_secs(1));
Ok(roc_repl)
}
fn main() -> Result<(), Error> {
let mut repl = roc_repl_session()?;
repl.exp_regex(".*roc repl.*")?;
repl.send_line("1+1")?;
thread::sleep(Duration::from_secs(1));
match repl.exp_regex(r".*2\u{1b}\[35m : \u{1b}\[0mNum *.*") {
Ok((a, b)) => {
println!("Expected output received.");
return Ok(());
}
Err(_) => {
eprintln!("\nError: output was different from expected value.");
std::process::exit(1);
}
}
}

View File

@ -1,33 +0,0 @@
#!/usr/bin/expect
# uncomment line below for debugging
exp_internal 1
set timeout 7
spawn ./roc repl
sleep 1
expect -exact "\r
The rockin \u001b\[34mroc repl\u001b\[0m\r
\u001b\[35m────────────────────────\u001b\[0m\r
\r
Enter an expression, or :help, or :q to quit.\r
\r
\u001b\[?2004h\r\u001b\[0K\u001b\[34m»\u001b\[0m \r\u001b\[2C" {
send -- "1+1\r"
sleep 1
expect -exact "\r
\r
2\u001b\[35m : \u001b\[0mNum * \u001b\[32m # val1\u001b\[0m\r
\r
\u001b\[?2004h\r\u001b\[0K\u001b\[34m»\u001b\[0m \r\u001b\[2C" {
exit 0
}
}
puts stderr "\nError: output was different from expected value."
exit 1