#diff #compare #csv #image #difference

bin+lib havocompare

A flexible rule-based file and folder comparison tool and crate including nice html reporting. Compares CSVs, JSON, text files, pdf-texts and images.

23 unstable releases (4 breaking)

0.5.1 Nov 12, 2023
0.5.0-RC2 Oct 10, 2023
0.4.0 Jul 31, 2023
0.3.0-beta1 Mar 20, 2023
0.1.4-RC2 Nov 25, 2022

#77 in Filesystem

Download history 432/week @ 2023-08-17 456/week @ 2023-08-24 428/week @ 2023-08-31 470/week @ 2023-09-07 510/week @ 2023-09-14 316/week @ 2023-09-21 361/week @ 2023-09-28 459/week @ 2023-10-05 404/week @ 2023-10-12 592/week @ 2023-10-19 636/week @ 2023-10-26 560/week @ 2023-11-02 499/week @ 2023-11-09 375/week @ 2023-11-16 494/week @ 2023-11-23 534/week @ 2023-11-30

2,012 downloads per month

MIT license


Havocompare - a folder comparison utility

Crates.io Documentation CI Coverage Status License




0. Install havocompare

You have rust? cool! try: cargo install havocompare

You just want a binary: Check our binary downloads on github-pages

1. Create a config file

Havocompare was developed with a few design goals in mind. We wanted a human-readable and easily composable configuration file format. After a few tries we ended up with the current format, which is a list of rules inside a yaml file. See the following example config.yaml:

  - name: "Numerical results csv"
    # you can have multiple includes and excludes
      - "**/export_*.csv"
    # excludes are optional
      - "**/export_1337.csv"
        - Relative: 0.1
        - Absolute: 1.0

It creates a new rule named rule including all files matching "export_*.csv" in all sub-folders but exclude "export_1337.csv". String cells will be checked for perfect identity, numbers (including numbers with units) will be checked for a relative deviation smaller than 0.1 AND absolute deviation smaller than 1.0.

Comparison rules

  • Relative means validity is checked like: |nominal - actual| / |nominal| < tolerance
  • Absolute means validity is checked like: |nominal - actual| < tolerance
  • "nan" and "nan" is equal
  • 0 difference with 0 nominal value is valid for any relative difference

2. Run the compare

Running the comparison is super easy, just supply nominal, actual and the config: ./havocompare compare nominal_dir actual_dir config.yaml The report of the comparison will be written inside the ./report folder. Differences will also be printed to the terminal. Furthermore, if differences are found, the return code will be 1, if no differences are found, it will be 0 making integration of havocompare into a CI system rather easy.

Details on the config

Validation Scheme

Writing a valid configuration file can be error-prone without auto-completion. We suggest using json schema to validate your yaml and even enable auto-completion in IDEs like pycharm. To generate the schema you can call: ./havocompare schema > config_scheme.json and import the resulting scheme into your IDE.

Comparison options


The comparison_modes option is required and of type 'list'. It can comprise either a relative numerical ('Relative') maximum deviation or a maximum deviation ('Absolute'). You can specify the decimal separator and the field separator. If you don't specify, havocompare will try to guess it from each csv file. Note: If delimiters are not specified, even different delimiters between nominal and actual are accepted as long as all deviations are in bounds. To ignore specific cells, you can specify an exclusion regex.

The preprocessing steps are done after the file is parsed using the given delimiters (or guessing) but before anything else. Processing order is as written in the list. In the below example, headers will be extracted from the csv-input file, then a column with the title "Column to delete" will be deleted. If any of the preprocessing steps fail, havocompare will exit with an error immediately so use them carefully.

See the following example with all optional parameters set:

  - name: "CSV - Demo all options"
    # what files to include - use as many as make sense to reduce duplication in your rules
      - "**/*.csv"
    # optional: of all included files, remove the ones matching any exclude pattern
      - "**/ignored.csv"
      # delimiters are optional, if not given, they will be auto-detected.
      # auto-detection allows different delimiters for nominal and actual
      decimal_separator: '.'
      field_delimiter:  ';'
      # can have Absolute or Relative or both
        - Absolute: 1.0
        - Relative: 0.1
      # optional: exclude fields matching the regex from comparison
      exclude_field_regex: "Excluded"
      # optional: preprocessing of the csv files
        # extracts the headers to the header-fields, makes reports more legible and allows for further processing "ByName".
        # While it may fail, there's no penalty for it, as long as you don't rely on it.
        - ExtractHeaders
        # Sort the table by column 0, beware that the column must only contain numbers / quantities
        - SortByColumnNumber: 0
        # Delete a column by name, needs `ExtractHeaders` first - delete sets all values to 'DELETED'
        - DeleteColumnByName: "Vertex_Position_Y"
        - DeleteColumnByNumber: 1
        # Sorts are stable, so a second sort will keep the first sort as sub-order.
        - SortByColumnName: "Vertex_Position_X"
        # Deletes the first row by setting all values to 'DELETED' - meaning that numbering stays constant 
        - DeleteRowByNumber: 0
        # Deletes rows having any element matching the given regex (may delete different lines in nom / act)!
        - DeleteRowByRegex: "Vertex_Count"
        # Deletes the cell (column, row) by setting the value to 'DELETED'
        - DeleteCellByNumber:
            column: 0
            row: 0
        # Deletes the cell (column name, row) by setting the value to 'DELETED'. This needs `ExtractHeaders`
        - DeleteCellByName:
            column: "Column to delete"
            row: 0

Image comparison

Image comparison is done using the image compare crate's hybrid comparison which does MSSIM on the luma and RMS on the color information. Only a threshold can be specified:

  - name: "JPG comparison"
      - "**/*.jpg"
    # exclude can of course also be specified!
      # threshold is between 0.0 for total difference, 0.5 for very dissimilar and 1.0 for perfect mach
      # Usually you want to test with values between 0.90 and 0.97
      threshold: 0.9

Plain text comparison

For plain text comparison the file is read and compared line by line. For each line the normalized Damerau-Levenshtein distance from the strsim crate is used. You can ignore single lines which you know are different by specifying an arbitrary number of ignored lines:

  - name: "HTML-Compare strict"
      - "**/*_changed.html"
      - "**/*.html"
      # Normalized Damerau-Levenshtein distance
      threshold: 1.0
      # All lines matching any regex below will be ignored
        - "stylesheet"
        - "next_ignore"
        - "[A-Z]*[0-9]"

PDF text comparison

For PDF text comparison the text will be extracted and written to temporary files. The files will then be compared using the Plain text comparison:

  - name: "PDF-Text-Compare"
      - "**/*_changed.pdf"
      - "**/*.pdf"
      # Normalized Damerau-Levenshtein distance
      threshold: 1.0
      # All lines matching any regex below will be ignored
        - "stylesheet"
        - "next_ignore"
        - "[A-Z]*[0-9]"

Hash comparison

For binary files which cannot otherwise be checked we can also do a simple hash comparison. Currently, we only support SHA-256 but more checks can be added easily.

  - name: "Hash comparison strict"
      - "**/*.bin"
      # Currently we only have Sha256
      function: Sha256

File metadata comparison

For the cases where the pure existence or some metadata are already enough.

  - name: "Metadata comparison"
      - "**/*.bin"
      # nom/act file paths must not contain whitespace
      forbid_name_regex: "[\\s]"
      # files must have their modification timestamp within 3600 seconds
      modification_date_tolerance_secs: 3600
      # files sizes must be within 1 kb 
      file_size_tolerance_bytes: 1024

Run external comparison tool

In case you want to run an external comparison tool, you can use this option

  - name: "External checker"
      - "*.pdf"
      # this config will call `/usr/bin/pdf-diff --only-images nominal.pdf actual.pdf`
      # return code will decide on comparison result
      executable: "/usr/bin/pdf-diff"
      # optional: add as many extra params as 
        - "--only-images"

JSON comparison

Compares JSON files for different keys in both files and mismatches in values. ignore_keys elements will be ignored, full regex matching on only the key names / paths is supported. The values are not affected by this.

- name: "Compare JSON files"
  - "**/*.json"
      # drop "ignore_this_key" and "ignore_this_keys" with this regex :)
      - "ignore_this_key(s?)"



  • Fix potential crash in JSON checking


  • Add JSON checking


  • Separate reporting logic from comparison logic
  • Implement a machine-readable JSON reporting


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


  • Fix swapped actual and nominal for hash and text-compares


  • Allow RGBA image comparison
  • Add file metadata comparison
  • Add external checking
  • Add and adjust reports for file metadata comparison and external checking
  • Add csv header comparison. Previously, the report only marks the differences but not returning any error.
  • Added config yaml validation command to check whether file can be loaded or not


  • add check for row lines of both compared csv files, and throw error if they are unequal
  • Add deletion by cell
  • Simplify report sub-folders creation: sub-folders are now created temporarily in the temp folder instead of in the current working folder
  • Change report row numbering to always start with 0, so row deletion is more understandable
  • fix floating point value comparison of non-displayable diff values


  • bump pdf-extract crate to 0.6.4 to fix "'attempted to leave type linked_hash_map::Node<alloc::vec::Vec<u8>, object::Object> uninitialized'"


  • Include files which has error and can't be compared to the report
  • Fixed a bug which caused the program exited early out of rules-loop, and not processing all


  • Deletion of columns will no longer really delete them but replace every value with "DELETED"
  • Expose config struct to library API
  • Fixed a bug regarding wrong handling of multiple empty lines
  • Reworked CSV reporting to have an interleaved and more compact view
    • Display the relative path of compared files instead of file name in the report index.html
    • Made header-extraction fallible but uncritical - can now always be enabled
  • Wrote a completely new csv parser:
    • Respects escaping with ''
    • Allows string-literals containing unescaped field separators (field1, "field2, but as literal", field3)
    • Allows multi-line string literals with quotes
  • CSVs with non-rectangular format will now fail


  • Add multiple includes and excludes - warning, this will break rules-files from 0.1.3 and earlier
  • Remove all unwrap and expect in the library code in favor of correct error propagation
  • Add preprocessing options for CSV files
  • Refined readme.md
  • fix unique key creation in the report generation
  • Add PDF-Text compare


  • Add optional cli argument to configure the folder to store the report


  • Add SHA-256 comparison mode
  • Fix BOM on windows for CSV comparison


  • Better error message on folder not found
  • Better test coverage
  • Fix colors on Windows terminal
  • Extend CI to Windows and mac


~700K SLoC