diff --git a/.github/workflows/test_nightly_macos_apple_silicon.yml b/.github/workflows/test_nightly_macos_apple_silicon.yml index c44ea7b967..7bde8a46d4 100644 --- a/.github/workflows/test_nightly_macos_apple_silicon.yml +++ b/.github/workflows/test_nightly_macos_apple_silicon.yml @@ -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 diff --git a/.github/workflows/test_nightly_many_os.yml b/.github/workflows/test_nightly_many_os.yml index 91e72129e5..b7d15554be 100644 --- a/.github/workflows/test_nightly_many_os.yml +++ b/.github/workflows/test_nightly_many_os.yml @@ -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) diff --git a/Cargo.toml b/Cargo.toml index 177bbe42e1..c7a6acca77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/ci/basic_nightly_test.sh b/ci/basic_nightly_test.sh index 03b61acf1b..a2318c296c 100755 --- a/ci/basic_nightly_test.sh +++ b/ci/basic_nightly_test.sh @@ -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 .. diff --git a/ci/repl_basic_test/Cargo.toml b/ci/repl_basic_test/Cargo.toml new file mode 100644 index 0000000000..3c8f814698 --- /dev/null +++ b/ci/repl_basic_test/Cargo.toml @@ -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" diff --git a/ci/repl_basic_test/src/main.rs b/ci/repl_basic_test/src/main.rs new file mode 100644 index 0000000000..2d64944c64 --- /dev/null +++ b/ci/repl_basic_test/src/main.rs @@ -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 { + 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); + } + } +} \ No newline at end of file diff --git a/ci/repl_test.exp b/ci/repl_test.exp deleted file mode 100644 index 36dd72ae3e..0000000000 --- a/ci/repl_test.exp +++ /dev/null @@ -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 \ No newline at end of file