Skip to content

Commit

Permalink
Merge pull request #37 from VolumeGraphics/add-opener-cli
Browse files Browse the repository at this point in the history
0.3.2 some fixes
  • Loading branch information
ChrisRega committed Jun 27, 2023
2 parents e52cc11 + 3a6dd16 commit 97c747d
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "A flexible rule-based file and folder comparison tool and crate i
repository = "https://github.com/VolumeGraphics/havocompare"
homepage = "https://github.com/VolumeGraphics/havocompare"
documentation = "https://docs.rs/havocompare"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
license = "MIT"
authors = ["Volume Graphics GmbH"]
Expand Down Expand Up @@ -34,7 +34,7 @@ serde_json = "1.0"
glob = "0.3"
test-log = {version="0.2", features=["trace"]}
strsim = "0.10"
itertools = "0.10"
itertools = "0.11"
tera = "1.17"
sha2 = "0.10"
data-encoding = "2.3"
Expand All @@ -45,6 +45,8 @@ rayon = "1.6"
enable-ansi-support = "0.2"
tempfile = "3.3"
fs_extra = "1.3"
opener = "0.6"
anyhow = "1.0"

[dev-dependencies]
env_logger = "0.10"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ rules:

## Changelog

### 0.3.2
- Allow direct opening of reports after comparison with `--open`
- Parsing failures when running `compare` are now propagated to terminal

### 0.3.1
- Fix swapped actual and nominal for hash and text-compares

Expand Down
27 changes: 25 additions & 2 deletions src/csv/preprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,29 @@ mod tests {
.unwrap()
}

fn setup_table_two(delimiters: Option<Delimiters>) -> Table {
let delimiters = delimiters.unwrap_or_default();
Table::from_reader(
File::open("tests/csv/data/defects_headers.csv").unwrap(),
&delimiters,
)
.unwrap()
}

#[test]
fn test_extract_headers_two() {
let mut table = setup_table_two(None);
extract_headers(&mut table).unwrap();
assert_eq!(
table.columns.first().unwrap().header.as_deref().unwrap(),
"Entry"
);
assert_eq!(
table.columns.last().unwrap().header.as_deref().unwrap(),
"Radius"
);
}

#[test]
fn test_extract_headers() {
let mut table = setup_table(None);
Expand Down Expand Up @@ -260,7 +283,7 @@ mod tests {
.unwrap()
.rows
.iter()
.all(|v| *v == csv::Value::deleted()));
.all(|v| *v == Value::deleted()));
}

#[test]
Expand All @@ -278,7 +301,7 @@ mod tests {
.unwrap()
.rows
.iter()
.all(|v| *v == csv::Value::deleted()));
.all(|v| *v == Value::deleted()));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/csv/tokenizer/guess_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) fn guess_format_from_reader<R: Read + Seek>(

let bufreader = BufReader::new(&mut input);
debug!("Guessing format from reader...");
for line in bufreader.lines().filter_map(|l| l.ok()) {
for line in bufreader.lines().map_while(Result::ok) {
debug!("Guessing format from line: '{}'", line.as_str());
format = guess_format_from_line(line.as_str(), format.0)?;
debug!("Current format: {:?}", format);
Expand Down
2 changes: 1 addition & 1 deletion src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn compare_files<P: AsRef<Path>>(
.lines()
.enumerate()
.filter_map(|l| l.1.ok().map(|a| (l.0, a)))
.zip(nominal.lines().filter_map(|l| l.ok()))
.zip(nominal.lines().map_while(Result::ok))
.filter(|((_, a), n)|
exclusion_list.iter().all(|exc| !exc.is_match(a)) && exclusion_list.iter().all(|exc| !exc.is_match(n))
)
Expand Down
29 changes: 20 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::path::Path;
use anyhow::anyhow;
use clap::Parser;
use havocompare::{compare_folders, get_schema, validate_config};
use tracing::Level;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;

const DEFAULT_REPORT_FOLDER: &str = "report";
Expand All @@ -18,6 +20,9 @@ enum Commands {
/// Optional: Folder to store the report to, if not set the default location will be chosen.
#[arg(short, long = "report_path", default_value_t = DEFAULT_REPORT_FOLDER.to_string())]
report_config: String,
/// Open the report immediately after comparison
#[arg(short, long)]
open: bool
},

/// Export the JsonSchema for the config files
Expand All @@ -38,7 +43,7 @@ struct Arguments {
command: Commands,
}

fn main() {
fn main() -> Result<(), vg_errortools::MainError> {
let args = Arguments::parse();
let level = if args.verbose {
Level::DEBUG
Expand All @@ -59,28 +64,34 @@ fn main() {
"{}",
get_schema().expect("Error occurred writing json schema")
);
std::process::exit(0);
Ok(())
}
Commands::Compare {
compare_config,
nominal,
actual,
report_config,
open
} => {
let report_path = Path::new(report_config.as_str());
let result =
compare_folders(nominal, actual, compare_config, report_config).unwrap_or(false);
compare_folders(nominal, actual, compare_config, report_path)?;
if open {
info!("Opening report");
opener::open(report_path.join("index.html")).expect("Could not open report!");
}
if result {
std::process::exit(0);
Ok(())
} else {
std::process::exit(1);
Err(anyhow!("Comparison failed!").into())
}
}
Commands::Validate { compare_config } => {
if validate_config(compare_config) {
std::process::exit(0);
Ok(())
} else {
std::process::exit(1);
Err(anyhow!("Validation failed!").into())
}
}
};
}
}
50 changes: 50 additions & 0 deletions tests/csv/data/defects_headers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Entry,Radius
1,0.00139
2,0.00711
3,0.00829
4,0.00774
5,0.00739
6,0.00882
7,0.00955
8,0.00265
9,0.00161
10,0.00275
11,0.00716
12,0.00579
13,0.00444
14,0.00938
15,0.00734
16,0.00352
17,0.00867
18,0.00105
19,0.00375
20,0.00692
21,0.00167
22,0.0055
23,0.00236
24,0.00775
25,0.00044
26,0.00441
27,0.00671
28,0.00529
29,0.00622
30,0.00153
31,0.00988
32,0.00762
33,0.00864
34,0.00818
35,0.00536
36,0.00603
37,0.007
38,0.00491
39,0.00868
40,0.00861
41,0.00766
42,0.00584
43,0.0044
44,0.0021
45,0.00523
46,0.00174
47,0.00562
48,0.0039
49,0.00279

0 comments on commit 97c747d

Please sign in to comment.