Skip to content

Commit

Permalink
Use assert2 to avoid unwrap in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
de-vri-es committed Nov 15, 2023
1 parent 589cb83 commit efd3d97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions git-version-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ proc-macro = true
quote = "1.0"
proc-macro2 = "1.0"
syn = "2.0"

[dev-dependencies]
assert2 = "0.3.11"
9 changes: 5 additions & 4 deletions git-version-macro/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ pub fn git_dir_cwd() -> std::io::Result<PathBuf> {
#[test]
fn test_git_dir() {
use std::path::Path;
use assert2::{assert, let_assert};

assert_eq!(
git_dir_cwd().unwrap().canonicalize().unwrap(),
Path::new(env!("CARGO_MANIFEST_DIR")).join("../.git").canonicalize().unwrap()
);
let_assert!(Ok(git_dir) = git_dir_cwd());
let_assert!(Ok(git_dir) = git_dir.canonicalize());
let_assert!(Ok(expected) = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.git").canonicalize());
assert!(git_dir == expected);
}

/// Check if a command ran successfully, and if not, return a verbose error.
Expand Down

0 comments on commit efd3d97

Please sign in to comment.