mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
trying rust expect
This commit is contained in:
parent
2c88674d97
commit
40ba121148
7 changed files with 58 additions and 36 deletions
|
@ -40,7 +40,12 @@ jobs:
|
||||||
run: cd roc_nightly && ./roc examples/platform-switching/rocLovesC.roc
|
run: cd roc_nightly && ./roc examples/platform-switching/rocLovesC.roc
|
||||||
|
|
||||||
- name: test repl
|
- 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
1
.github/workflows/test_nightly_many_os.yml
vendored
1
.github/workflows/test_nightly_many_os.yml
vendored
|
@ -23,7 +23,6 @@ jobs:
|
||||||
if: startsWith(matrix.os, 'ubuntu')
|
if: startsWith(matrix.os, 'ubuntu')
|
||||||
run: |
|
run: |
|
||||||
curl -fOL https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linux_x86_64-latest.tar.gz
|
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)
|
- name: get the latest release archive for macos (x86_64)
|
||||||
|
|
|
@ -30,6 +30,7 @@ members = [
|
||||||
|
|
||||||
exclude = [
|
exclude = [
|
||||||
"ci/benchmarks/bench-runner",
|
"ci/benchmarks/bench-runner",
|
||||||
|
"ci/repl_basic_test",
|
||||||
# Examples sometimes have Rust hosts in their platforms. The compiler should ignore those.
|
# Examples sometimes have Rust hosts in their platforms. The compiler should ignore those.
|
||||||
"crates/cli_testing_examples",
|
"crates/cli_testing_examples",
|
||||||
"examples",
|
"examples",
|
||||||
|
|
|
@ -56,6 +56,11 @@ fi
|
||||||
./roc examples/platform-switching/rocLovesC.roc
|
./roc examples/platform-switching/rocLovesC.roc
|
||||||
|
|
||||||
# test repl
|
# 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 ..
|
cd ..
|
||||||
|
|
9
ci/repl_basic_test/Cargo.toml
Normal file
9
ci/repl_basic_test/Cargo.toml
Normal 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"
|
36
ci/repl_basic_test/src/main.rs
Normal file
36
ci/repl_basic_test/src/main.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
Loading…
Add table
Add a link
Reference in a new issue