From 8b26a8a6884ef08aef240fb332fdbf74ed5d206b Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Wed, 27 Apr 2022 16:11:10 -0600 Subject: [PATCH] =?UTF-8?q?feat:=20Fix=20tests=20on=20github=20actions=20?= =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add better panic chore: Use unwrap instead of ? for debugging ♻️ chore: Remove table tests ♻️ chore: Make terminal::size unwrap to default values ♻️ chore: Move reader creation to inside init check ♻️ fix: Change total_tasks in tests 🐛 fix: Change default height 🐛 chore: Print taskwarrior version ♻️ chore: Build taskwarrior from source for tests ♻️ chore: Checkout v2.6.1 of taskwarrior for tests ♻️ chore: Use ? instead of unwrap ♻️ chore: fix tests ♻️ --- .github/workflows/ci.yml | 13 +++++++++++-- src/app.rs | 20 +++++++------------- src/event.rs | 2 +- src/table.rs | 11 ----------- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 245582a..e4b6e18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,13 +31,22 @@ jobs: profile: minimal toolchain: stable override: true - - run: sudo apt-get update && sudo apt-get install -y taskwarrior + - run: sudo apt-get update + - name: Compile taskwarrior + run: | + cd /tmp + git clone https://github.com/GothenburgBitFactory/taskwarrior + cd taskwarrior + git checkout v2.6.1 + cmake -DCMAKE_BUILD_TYPE=release -DENABLE_SYNC=OFF . + make + sudo make install - uses: actions/checkout@v2 with: repository: kdheepak/taskwarrior-testdata path: taskwarrior-testdata - run: | - ulimit -a + task --version - run: | # prepare taskwarrior, initial setup task rc.confirmation=off || echo 0 diff --git a/src/app.rs b/src/app.rs index 5c45751..b7a5609 100644 --- a/src/app.rs +++ b/src/app.rs @@ -245,15 +245,13 @@ impl TaskwarriorTui { .arg("rc.defaultwidth=0") .arg("show") .output() - .context("Unable to run `task show`.") - .unwrap(); + .context("Unable to run `task show`.")?; if !output.status.success() { let output = std::process::Command::new("task") .arg("diagnostics") .output() - .context("Unable to run `task diagnostics`.") - .unwrap(); + .context("Unable to run `task diagnostics`.")?; return Err(anyhow!( "Unable to run `task show`.\n{}\n{}\nPlease check your configuration or open a issue on github.", String::from_utf8_lossy(&output.stdout), @@ -268,12 +266,12 @@ impl TaskwarriorTui { let output = std::process::Command::new("task") .arg("--version") .output() - .context("Unable to run `task --version`") - .unwrap(); + .context("Unable to run `task --version`")?; - let task_version = Versioning::new(String::from_utf8_lossy(&output.stdout).trim()).unwrap(); + let task_version = + Versioning::new(String::from_utf8_lossy(&output.stdout).trim()).context("Unable to get version string")?; - let (w, h) = crossterm::terminal::size()?; + let (w, h) = crossterm::terminal::size().unwrap_or((50, 15)); let tick_rate = if c.uda_tick_rate > 0 { Some(std::time::Duration::from_millis(c.uda_tick_rate)) @@ -3874,11 +3872,7 @@ mod tests { } async fn _test_taskwarrior_tui() { - let app = TaskwarriorTui::new("next", false).await; - if app.is_err() { - return; - } - let app = app.unwrap(); + let app = TaskwarriorTui::new("next", false).await.unwrap(); assert!(app.task_by_index(0).is_none(), "Expected task data to be empty but found {} tasks. Delete contents of {:?} and {:?} and run the tests again.", app.tasks.len(), Path::new(env!("TASKDATA")), Path::new(env!("TASKDATA")).parent().unwrap().join(".config")); diff --git a/src/event.rs b/src/event.rs index 8fb9f0b..b4e80cf 100644 --- a/src/event.rs +++ b/src/event.rs @@ -56,13 +56,13 @@ impl EventLoop { pub fn new(tick_rate: Option, init: bool) -> Self { let (tx, rx) = mpsc::unbounded_channel(); let _tx = tx.clone(); - let mut reader = crossterm::event::EventStream::new(); let should_tick = tick_rate.is_some(); let tick_rate = tick_rate.unwrap_or(std::time::Duration::from_millis(250)); let (abort, mut abort_recv) = mpsc::unbounded_channel(); if init { + let mut reader = crossterm::event::EventStream::new(); tokio::spawn(async move { loop { let delay = tokio::time::sleep(tick_rate); diff --git a/src/table.rs b/src/table.rs index ce885b8..e6e14af 100644 --- a/src/table.rs +++ b/src/table.rs @@ -540,14 +540,3 @@ where StatefulWidget::render(self, area, buf, &mut state); } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - #[should_panic] - fn table_invalid_percentages() { - Table::new([""].iter(), vec![Row::Data([""].iter())].into_iter()).widths(&[Constraint::Percentage(110)]); - } -}