Skip to content

Commit

Permalink
Merge pull request #3 from Kobzol/ci-os
Browse files Browse the repository at this point in the history
Run CI on Windows and macOS too
  • Loading branch information
Kobzol authored Mar 10, 2024
2 parents 25beb93 + 8ae05c4 commit 82e157a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 59 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ on:
jobs:
test:
name: Test
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust-version: [ stable, beta, nightly ]
include:
- rust-version: stable
os: ubuntu-latest
- rust-version: beta
os: ubuntu-latest
- rust-version: nightly
os: ubuntu-latest
- rust-version: stable
os: windows-latest
- rust-version: stable
os: macos-12
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ toml_edit = "0.22.6"
[dev-dependencies]
tempfile = "3.10.1"
insta = "1.35.1"

[target.'cfg(target_os = "linux")'.dev-dependencies]
rexpect = "0.5.0"

[profile.dev]
Expand Down
1 change: 1 addition & 0 deletions tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod apply;
#[cfg(target_os = "linux")]
mod dialog;
mod utils;
64 changes: 7 additions & 57 deletions tests/integration/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Output, Stdio};

use rexpect::session::{spawn_command, PtySession};
use tempfile::TempDir;

#[cfg(target_os = "linux")]
mod terminal;

pub struct CargoProject {
_name: String,
pub dir: PathBuf,
Expand Down Expand Up @@ -99,9 +101,10 @@ pub struct Cmd {
}

impl Cmd {
pub fn start_terminal(self) -> anyhow::Result<Terminal> {
let session = spawn_command(self.create_std_cmd(false), Some(1000))?;
Ok(Terminal { session })
#[cfg(target_os = "linux")]
pub fn start_terminal(self) -> anyhow::Result<terminal::Terminal> {
let session = rexpect::session::spawn_command(self.create_std_cmd(false), Some(1000))?;
Ok(terminal::Terminal { session })
}

pub fn run(self) -> anyhow::Result<Output> {
Expand Down Expand Up @@ -151,59 +154,6 @@ impl Cmd {
}
}

pub struct Terminal {
pub session: PtySession,
}

impl Terminal {
pub fn expect(&mut self, text: &str) -> anyhow::Result<()> {
self.session.exp_string(text)?;
Ok(())
}

pub fn line(&mut self, text: &str) -> anyhow::Result<()> {
self.session.send_line(text)?;
Ok(())
}

pub fn key_enter(&mut self) -> anyhow::Result<()> {
self.session.send_line("")?;
Ok(())
}

pub fn key_down(&mut self) -> anyhow::Result<()> {
// Arrow down, detected through `showkey -a`
self.session.send("\x1b\x5b\x42")?;
self.session.flush()?;
Ok(())
}

/// Find a line that begings by `> {prefix}` by going through a list using the down arrow key.
pub fn select_line(&mut self, prefix: &str) -> anyhow::Result<()> {
let max_tries = 20;
for _ in 0..max_tries {
if self
.session
.exp_regex(&format!("\n>\\s*{prefix}.*"))
.is_ok()
{
return self.key_enter();
}
self.key_down()?;
}
eprintln!("Could not find line beginning with {prefix} in {max_tries} tries.");
// Print terminal output
self.session
.exp_string(&format!("<missing {prefix} in list>"))?;
unreachable!();
}

pub fn wait(self) -> anyhow::Result<()> {
self.session.process.wait()?;
Ok(())
}
}

pub trait OutputExt {
fn assert_ok(self) -> Self;

Expand Down
54 changes: 54 additions & 0 deletions tests/integration/utils/terminal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use rexpect::session::PtySession;

pub struct Terminal {
pub session: PtySession,
}

impl Terminal {
pub fn expect(&mut self, text: &str) -> anyhow::Result<()> {
self.session.exp_string(text)?;
Ok(())
}

pub fn line(&mut self, text: &str) -> anyhow::Result<()> {
self.session.send_line(text)?;
Ok(())
}

pub fn key_enter(&mut self) -> anyhow::Result<()> {
self.session.send_line("")?;
Ok(())
}

pub fn key_down(&mut self) -> anyhow::Result<()> {
// Arrow down, detected through `showkey -a`
self.session.send("\x1b\x5b\x42")?;
self.session.flush()?;
Ok(())
}

/// Find a line that begings by `> {prefix}` by going through a list using the down arrow key.
pub fn select_line(&mut self, prefix: &str) -> anyhow::Result<()> {
let max_tries = 20;
for _ in 0..max_tries {
if self
.session
.exp_regex(&format!("\n>\\s*{prefix}.*"))
.is_ok()
{
return self.key_enter();
}
self.key_down()?;
}
eprintln!("Could not find line beginning with {prefix} in {max_tries} tries.");
// Print terminal output
self.session
.exp_string(&format!("<missing {prefix} in list>"))?;
unreachable!();
}

pub fn wait(self) -> anyhow::Result<()> {
self.session.process.wait()?;
Ok(())
}
}

0 comments on commit 82e157a

Please sign in to comment.