-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): ensure that binary is built before the test runs (#11)
The `app.rs` test requires that the `binsider` binary has been built. By moving the test into the `tests` directory, `cargo` will ensure that the binary has been built before the test can be run.
- Loading branch information
1 parent
3c98161
commit efb73b1
Showing
2 changed files
with
46 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use binsider::{app::Analyzer, error::Result, file::FileInfo, prelude::Event}; | ||
use std::{fs, path::PathBuf, sync::mpsc}; | ||
|
||
fn get_test_path() -> PathBuf { | ||
PathBuf::from(env!("CARGO_BIN_EXE_binsider")) | ||
} | ||
|
||
fn get_test_bytes() -> Result<Vec<u8>> { | ||
let debug_binary = get_test_path(); | ||
Ok(fs::read(debug_binary)?) | ||
} | ||
|
||
#[test] | ||
fn test_init() -> Result<()> { | ||
Analyzer::new( | ||
FileInfo::new( | ||
get_test_path().to_str().expect("failed to get test path"), | ||
get_test_bytes()?.as_slice(), | ||
)?, | ||
4, | ||
vec![], | ||
) | ||
.map(|_| ()) | ||
} | ||
|
||
#[test] | ||
fn test_extract_strings() -> Result<()> { | ||
let test_bytes = get_test_bytes()?; | ||
let test_path = get_test_path(); | ||
let mut analyzer = Analyzer::new( | ||
FileInfo::new( | ||
test_path.to_str().expect("failed to get test path"), | ||
test_bytes.as_slice(), | ||
)?, | ||
4, | ||
vec![], | ||
)?; | ||
let (tx, rx) = mpsc::channel(); | ||
analyzer.extract_strings(tx); | ||
if let Event::FileStrings(strings) = rx.recv()? { | ||
assert!(strings?.iter().map(|(s, _)| s).any(|v| v == ".debug_str")); | ||
} else { | ||
panic!("strings did not succeed"); | ||
} | ||
Ok(()) | ||
} |