Skip to content

Add snapshot test using insta #2411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ which = "7.0"

[dev-dependencies]
env_logger = "0.11"
git2-testing = { path = "./git2-testing" }
insta = { version = "1.41.0", features = ["filters"] }
pretty_assertions = "1.4"
tempfile = "3"

Expand Down
16 changes: 13 additions & 3 deletions git2-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ pub fn repo_init_empty() -> (TempDir, Repository) {
(td, repo)
}

/// initialize test repo in temp path with an empty first commit
pub fn repo_init() -> (TempDir, Repository) {
/// initialize test repo in temp path with given suffix and an empty first commit
pub fn repo_init_suffix<T: AsRef<std::ffi::OsStr>>(
suffix: Option<T>,
) -> (TempDir, Repository) {
init_log();

sandbox_config_files();

let td = TempDir::new().unwrap();
let td = match suffix {
Some(suffix) => TempDir::with_suffix(suffix).unwrap(),
None => TempDir::new().unwrap(),
};
let repo = Repository::init(td.path()).unwrap();
{
let mut config = repo.config().unwrap();
Expand All @@ -43,6 +48,11 @@ pub fn repo_init() -> (TempDir, Repository) {
(td, repo)
}

/// initialize test repo in temp path with an empty first commit
pub fn repo_init() -> (TempDir, Repository) {
repo_init_suffix::<&std::ffi::OsStr>(None)
}

// init log
fn init_log() {
let _ = env_logger::builder()
Expand Down
Loading
Loading