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