Skip to content

Commit

Permalink
Test imdl torrent verify output
Browse files Browse the repository at this point in the history
- Test all individual `FileError` variants
- Test terminal colors
- Test multiple and single file torrents

type: testing
  • Loading branch information
casey committed Apr 8, 2020
1 parent 2ea5e0b commit 0033e83
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 35 deletions.
41 changes: 41 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ version = "0.3.0"
features = ["default", "wrap_help"]

[dev-dependencies]
indoc = "0.3.4"
temptree = "0.0.0"

[workspace]
Expand Down
2 changes: 0 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ impl Env {
)
.ok();

error.print_body(self).ok();

if let Some(lint) = error.lint() {
writeln!(
&mut self.err,
Expand Down
10 changes: 1 addition & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub(crate) enum Error {
))]
Unstable { feature: &'static str },
#[snafu(display("Torrent verification failed."))]
Verify { status: Status },
Verify,
}

impl Error {
Expand All @@ -137,14 +137,6 @@ impl Error {
message: message.into(),
}
}

pub(crate) fn print_body(&self, env: &mut Env) -> Result<()> {
if let Self::Verify { status } = self {
status.print_body(env)?;
}

Ok(())
}
}

impl From<clap::Error> for Error {
Expand Down
4 changes: 2 additions & 2 deletions src/file_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ impl Display for FileError {
Self::Io(io_error) => write!(f, "{}", io_error),
Self::Missing => write!(f, "File missing"),
Self::Directory => write!(f, "Expected file but found directory"),
Self::Surfeit(difference) => write!(f, "Extra bytes: {}", difference),
Self::Dearth(difference) => write!(f, "Missing bytes: {}", difference),
Self::Surfeit(difference) => write!(f, "{} too long", difference),
Self::Dearth(difference) => write!(f, "{} too short", difference),
Self::Md5 { actual, expected } => write!(
f,
"MD5 checksum mismatch: {} (expected {})",
Expand Down
4 changes: 4 additions & 0 deletions src/output_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl OutputStream {
self.style
}

pub(crate) fn is_styled_term(&self) -> bool {
self.is_styled() && self.is_term()
}

pub(crate) fn style(&self) -> Style {
Style::from_active(self.style)
}
Expand Down
9 changes: 1 addition & 8 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Status {
}
}

pub(crate) fn print_body(&self, env: &mut Env) -> Result<()> {
pub(crate) fn print(&self, env: &mut Env) -> Result<()> {
match self {
Self::Single { error, .. } => {
if let Some(error) = error {
Expand All @@ -70,13 +70,6 @@ impl Status {
error.println(env.err_mut()).context(error::Stderr)?;
}
}

errln!(
env,
"{}/{} files corrupted.",
files.iter().filter(|file| file.is_bad()).count(),
files.len(),
)?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) trait Step {
dim.suffix()
)?;

err!(env, "{}{} ", message.prefix(), self.symbol())?;
err!(env, "{} {}", self.symbol(), message.prefix())?;

self.write_message(env.err_mut()).context(error::Stderr)?;

Expand Down
6 changes: 3 additions & 3 deletions src/subcommand/torrent/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl Create {

CreateStep::Searching.print(env)?;

let spinner = if env.err().is_styled() {
let spinner = if env.err().is_styled_term() {
let style = ProgressStyle::default_spinner()
.template("{spinner:.green} {msg:.bold}…")
.tick_chars(consts::TICK_CHARS);
Expand Down Expand Up @@ -300,7 +300,7 @@ impl Create {

CreateStep::Hashing.print(env)?;

let progress_bar = if env.err().is_styled() {
let progress_bar = if env.err().is_styled_term() {
let style = ProgressStyle::default_bar()
.template(
"{spinner:.green} ⟪{elapsed_precise}⟫ ⟦{bar:40.cyan}⟧ \
Expand Down Expand Up @@ -380,7 +380,7 @@ impl Create {
let status = metainfo.verify(&input, None)?;

if !status.good() {
return Err(Error::Verify { status });
return Err(Error::Verify);
}
}

Expand Down
Loading

0 comments on commit 0033e83

Please sign in to comment.