This commit is contained in:
Dheepak Krishnamurthy 2023-09-25 08:07:19 -04:00
parent 9b7b83607a
commit e136c23959
3 changed files with 26 additions and 4 deletions

2
.envrc
View file

@ -3,5 +3,3 @@ export TASKDATA=`pwd`/tests/data/.task
export TASKWARRIOR_TUI_CONFIG=`pwd`/tests/data/.config
export TASKWARRIOR_TUI_DATA=`pwd`/tests/data/.data
export TASKWARRIOR_TUI_LOG_LEVEL=debug
export RUST_LOG=debug
export RUST_BACKTRACE=full

View file

@ -1,4 +1,6 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]
use std::process::{Command, Output};
use clap_complete::{

View file

@ -31,6 +31,11 @@ impl TaskReport {
Self::default()
}
pub fn report(mut self, report: String) -> Self {
self.report = report;
self
}
pub fn refresh(&mut self) -> Result<()> {
self.last_export = Some(std::time::SystemTime::now());
Ok(())
@ -78,10 +83,13 @@ impl TaskReport {
let error = String::from_utf8_lossy(&output.stderr);
if output.status.success() {
if let Ok(imported) = import(data.as_bytes()) {
self.tasks = imported;
let imported = import(data.as_bytes());
if imported.is_ok() {
self.tasks = imported?;
log::info!("Imported {} tasks", self.tasks.len());
self.send_command(Command::ShowTaskReport)?;
} else {
imported?;
}
} else {
self.send_command(Command::Error(format!("Unable to parse output of `{:?}`:\n`{:?}`", task, data)))?;
@ -113,3 +121,17 @@ impl Component for TaskReport {
Ok(())
}
}
mod tests {
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_export() -> Result<()> {
let mut tr = TaskReport::new().report("next".into());
tr.task_export()?;
assert_eq!(tr.tasks.len(), 33);
Ok(())
}
}