More flexible verbosity, improve verbose test
This commit is contained in:
parent
798a120926
commit
0452f35a3c
3 changed files with 31 additions and 33 deletions
23
src/lib.rs
23
src/lib.rs
|
|
@ -31,7 +31,7 @@ use crate::evaluate::Evaluator;
|
|||
use crate::png::PngData;
|
||||
use crate::png::PngImage;
|
||||
use crate::reduction::*;
|
||||
use log::{debug, info, warn};
|
||||
use log::{debug, info, trace, warn};
|
||||
use rayon::prelude::*;
|
||||
use std::fmt;
|
||||
use std::fs::{copy, File, Metadata};
|
||||
|
|
@ -330,7 +330,7 @@ pub fn optimize(input: &InFile, output: &OutFile, opts: &Options) -> PngResult<(
|
|||
))
|
||||
})
|
||||
.map(Some)?;
|
||||
debug!("preserving metadata: {:?}", opt_metadata_preserved);
|
||||
trace!("preserving metadata: {:?}", opt_metadata_preserved);
|
||||
} else {
|
||||
opt_metadata_preserved = None;
|
||||
}
|
||||
|
|
@ -532,7 +532,7 @@ fn optimize_png(
|
|||
}
|
||||
|
||||
if !filters.is_empty() {
|
||||
debug!("Evaluating: {} filters", filters.len());
|
||||
trace!("Evaluating: {} filters", filters.len());
|
||||
let eval = Evaluator::new(deadline, filters, eval_compression, opts.optimize_alpha);
|
||||
if eval_filter.is_some() {
|
||||
eval.set_best_size(png.idat_data.len());
|
||||
|
|
@ -746,16 +746,20 @@ fn perform_trial(
|
|||
match new_idat {
|
||||
Ok(n) => {
|
||||
let bytes = n.len();
|
||||
debug!(
|
||||
trace!(
|
||||
" zc = {} f = {} {} bytes",
|
||||
trial.compression, trial.filter, bytes
|
||||
trial.compression,
|
||||
trial.filter,
|
||||
bytes
|
||||
);
|
||||
Some((trial, n))
|
||||
}
|
||||
Err(PngError::DeflatedDataTooLong(bytes)) => {
|
||||
debug!(
|
||||
trace!(
|
||||
" zc = {} f = {} >{} bytes",
|
||||
trial.compression, trial.filter, bytes,
|
||||
trial.compression,
|
||||
trial.filter,
|
||||
bytes,
|
||||
);
|
||||
None
|
||||
}
|
||||
|
|
@ -1032,9 +1036,10 @@ fn copy_times(_: &Metadata, _: &Path) -> PngResult<()> {
|
|||
fn copy_times(input_path_meta: &Metadata, out_path: &Path) -> PngResult<()> {
|
||||
let atime = filetime::FileTime::from_last_access_time(input_path_meta);
|
||||
let mtime = filetime::FileTime::from_last_modification_time(input_path_meta);
|
||||
debug!(
|
||||
trace!(
|
||||
"attempting to set file times: atime: {:?}, mtime: {:?}",
|
||||
atime, mtime
|
||||
atime,
|
||||
mtime
|
||||
);
|
||||
filetime::set_file_times(out_path, atime, mtime).map_err(|err_io| {
|
||||
PngError::new(&format!(
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#![warn(clippy::range_plus_one)]
|
||||
#![allow(clippy::cognitive_complexity)]
|
||||
|
||||
use clap::{AppSettings, Arg, ArgMatches, Command};
|
||||
use clap::{AppSettings, Arg, ArgAction, ArgMatches, Command};
|
||||
use indexmap::IndexSet;
|
||||
use log::{error, warn};
|
||||
use oxipng::Deflaters;
|
||||
|
|
@ -154,9 +154,10 @@ fn main() {
|
|||
)
|
||||
.arg(
|
||||
Arg::new("verbose")
|
||||
.help("Run in verbose mode")
|
||||
.help("Run in verbose mode (use multiple times to increase verbosity)")
|
||||
.short('v')
|
||||
.long("verbose")
|
||||
.action(ArgAction::Count)
|
||||
.conflicts_with("quiet"),
|
||||
)
|
||||
.arg(
|
||||
|
|
@ -381,7 +382,7 @@ fn parse_opts_into_struct(
|
|||
stderrlog::new()
|
||||
.module(module_path!())
|
||||
.quiet(matches.is_present("quiet"))
|
||||
.verbosity(if matches.is_present("verbose") { 3 } else { 2 })
|
||||
.verbosity(matches.get_count("verbose") as usize + 2)
|
||||
.show_level(false)
|
||||
.init()
|
||||
.unwrap();
|
||||
|
|
|
|||
|
|
@ -180,34 +180,26 @@ fn verbose_mode() {
|
|||
});
|
||||
|
||||
let logs: Vec<_> = receiver.into_iter().collect();
|
||||
println!("logs={:?}", logs);
|
||||
assert_eq!(logs.len(), 9);
|
||||
let expected_logs = [
|
||||
let expected_prefixes = [
|
||||
" 500x400 pixels, PNG format",
|
||||
" 3x8 bits/pixel, RGB (non-interlaced)",
|
||||
" IDAT size = 113794 bytes",
|
||||
" File size = 114708 bytes",
|
||||
"Trying: 1 filters",
|
||||
" zc = 11 f = None 149409 bytes",
|
||||
"Found better combination:",
|
||||
" zc = 11 f = None 149409 bytes",
|
||||
" IDAT size = 149409 bytes",
|
||||
" zc = 11 f = None ",
|
||||
" IDAT size = ",
|
||||
];
|
||||
for (idx, expected_log) in expected_logs.into_iter().enumerate() {
|
||||
if let Some(log) = logs.get(idx) {
|
||||
if !log.starts_with(expected_log) {
|
||||
panic!(
|
||||
"logs[{}] = {:?} doesn't start with {:?}",
|
||||
idx, log, expected_log
|
||||
);
|
||||
}
|
||||
} else {
|
||||
panic!(
|
||||
"Expected to find {} log entries, but got {}",
|
||||
expected_logs.len(),
|
||||
logs.len()
|
||||
);
|
||||
}
|
||||
assert_eq!(logs.len(), expected_prefixes.len());
|
||||
for (i, log) in logs.into_iter().enumerate() {
|
||||
let expected_prefix = expected_prefixes[i];
|
||||
assert!(
|
||||
log.starts_with(&expected_prefix),
|
||||
"logs[{}] = {:?} doesn't start with {:?}",
|
||||
i,
|
||||
log,
|
||||
expected_prefix
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue