Skip to content

Commit

Permalink
Chore: improved status command output
Browse files Browse the repository at this point in the history
  • Loading branch information
tingerrr committed Jan 20, 2024
1 parent c2301d5 commit 53775ec
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 32 deletions.
33 changes: 1 addition & 32 deletions crates/typst-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,38 +341,7 @@ mod cmd {
project.discover_tests()?;
project.load_template()?;

if let Some(manifest) = project.manifest() {
reporter.raw(|w| {
writeln!(
w,
"Package: {}:{}",
manifest.package.name, manifest.package.version
)
})?;

// TODO: list [tool.typst-test] settings
}

reporter.raw(|w| {
writeln!(
w,
"Template: {}",
if project.template().is_some() {
"found"
} else {
"not found"
}
)
})?;

if project.tests().is_empty() {
reporter.raw(|w| writeln!(w, "Tests: none"))?;
} else {
reporter.raw(|w| writeln!(w, "Tests:"))?;
for name in project.tests().keys() {
reporter.raw(|w| writeln!(w, " {}", name))?;
}
}
reporter.project(project)?;

Ok(CliResult::Ok)
}
Expand Down
68 changes: 68 additions & 0 deletions crates/typst-test/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use std::io;
use termcolor::{Color, ColorSpec, WriteColor};

use crate::project::test::{CompareFailure, Test, TestFailure, UpdateFailure};
use crate::project::Project;

pub const MAX_PADDING: usize = 20;
pub const MAX_TEST_LIST: usize = 10;

fn write_bold_colored<W: WriteColor + ?Sized>(
w: &mut W,
Expand Down Expand Up @@ -210,4 +212,70 @@ impl Reporter {
},
)
}

pub fn project(&mut self, project: &Project) -> io::Result<()> {
if let Some(manifest) = project.manifest() {
self.raw(|w| {
write!(w, " Project ┌ ")?;
write_bold_colored(w, &manifest.package.name.to_string(), Color::Cyan)?;
write!(w, ":")?;
write_bold_colored(w, &manifest.package.version.to_string(), Color::Cyan)?;
writeln!(w)
})?;

// TODO: list [tool.typst-test] settings
} else {
self.raw(|w| {
write!(w, " Project ┌ ")?;
write_bold_colored(w, "none", Color::Yellow)?;
writeln!(w)
})?;
}

self.raw(|w| {
write!(w, "Template ├ ")?;
if project.template().is_some() {
write_bold_colored(w, "found", Color::Green)?;
} else {
write_bold_colored(w, "not found", Color::Yellow)?;
write!(
w,
" (looked at {:?})",
project.tests_root_dir().join("template.typ")
)?;
}
writeln!(w)
})?;

let tests = project.tests();
if tests.is_empty() {
self.raw(|w| {
write!(w, " Tests └ ")?;
write_bold_colored(w, "none", Color::Cyan)
})?;
} else if tests.len() <= MAX_TEST_LIST {
self.raw(|w| {
write!(w, " Tests ├ ")?;
write_bold_colored(w, &tests.len().to_string(), Color::Cyan)?;
writeln!(w)?;
for (idx, name) in project.tests().keys().enumerate() {
if idx == tests.len() - 1 {
writeln!(w, " └ {}", name)?;
} else {
writeln!(w, " │ {}", name)?;
}
}

Ok(())
})?;
} else {
self.raw(|w| {
write!(w, " Tests └ ")?;
write_bold_colored(w, &tests.len().to_string(), Color::Cyan)?;
writeln!(w)
})?;
}

Ok(())
}
}

0 comments on commit 53775ec

Please sign in to comment.