Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devttys0 committed Nov 30, 2024
1 parent a609599 commit 27eb641
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/binwalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ impl Binwalk {
///
/// ```
/// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_binwalk_rs_624_0() -> Result<binwalk::Binwalk, binwalk::BinwalkError> {
/// use binwalk::Binwalk;
/// use binwalk::{Binwalk, common};
///
/// let target_path = std::path::Path::new("tests")
/// .join("inputs")
Expand All @@ -688,6 +688,8 @@ impl Binwalk {
/// .display()
/// .to_string();
///
/// let file_data = common::read_file(&target_path, false).expect("Failed to read file data");
///
/// # std::fs::remove_dir_all(&extraction_directory);
/// let binwalker = Binwalk::configure(Some(target_path),
/// Some(extraction_directory.clone()),
Expand All @@ -696,7 +698,7 @@ impl Binwalk {
/// None,
/// false)?;
///
/// let analysis_results = binwalker.analyze(&binwalker.base_target_file, true);
/// let analysis_results = binwalker.analyze(&file_data, &binwalker.base_target_file, true);
///
/// assert_eq!(analysis_results.file_map.len(), 1);
/// assert_eq!(analysis_results.extractions.len(), 1);
Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::io::Read;
/// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_common_rs_11_0() -> Result<(), Box<dyn std::error::Error>> {
/// use binwalk::common::read_file;
///
/// let file_data = read_file("/etc/passwd")?;
/// let file_data = read_file("/etc/passwd", false)?;
/// assert!(file_data.len() > 0);
/// # Ok(())
/// # } _doctest_main_src_common_rs_11_0(); }
Expand Down
7 changes: 5 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use binwalk::{AnalysisResults, Binwalk};
use binwalk::{common, AnalysisResults, Binwalk};

/// Convenience function for running an integration test against the specified file, with the provided signature filter.
/// Assumes that there will be one signature result and one extraction result at file offset 0.
Expand Down Expand Up @@ -55,6 +55,9 @@ pub fn run_binwalk(signature_filter: &str, file_name: &str) -> AnalysisResults {
// Delete the output directory, if it exists
let _ = std::fs::remove_dir_all(&output_directory);

// Read in file data
let file_data = common::read_file(&file_path, false).expect("Failed to read test file");

// Configure binwalk
let binwalker = Binwalk::configure(
Some(file_path),
Expand All @@ -67,7 +70,7 @@ pub fn run_binwalk(signature_filter: &str, file_name: &str) -> AnalysisResults {
.expect("Binwalk initialization failed");

// Run analysis
let results = binwalker.analyze(&binwalker.base_target_file, true);
let results = binwalker.analyze(&file_data, &binwalker.base_target_file, true);

// Clean up the output directory
let _ = std::fs::remove_dir_all(output_directory);
Expand Down

0 comments on commit 27eb641

Please sign in to comment.