diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0dd28074..8413a3e5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -27,11 +27,6 @@ jobs: toolchain: stable override: true - - name: Coverage - uses: actions-rs/tarpaulin@v0.1 - with: - args: -- --test-threads 1 - - name: Test uses: actions-rs/cargo@v1 continue-on-error: false @@ -39,6 +34,11 @@ jobs: command: test args: -- --test-threads 1 + - name: Coverage + uses: actions-rs/tarpaulin@v0.1 + with: + args: -- --test-threads 1 + - name: Upload to codecov.io uses: codecov/codecov-action@v1.0.6 with: @@ -77,4 +77,4 @@ jobs: continue-on-error: false with: command: clippy - args: -- -D warnings \ No newline at end of file + args: -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 9bcdf4c2..6020fd5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ config = "^0" itertools = "^0" serde_derive = "^1" serde = "^1" -tempdir = "^0" +tempfile = "^3" semver = "^0" shell-words = "^1" which = "^4" @@ -34,7 +34,6 @@ clap = { version = "^2", optional = true } [dev-dependencies] assert_cmd = "1.0.3" predicates = "1" -temp_testdir = "0.2.3" rand = "0.7.3" [features] diff --git a/src/git/hook.rs b/src/git/hook.rs index 5276e76d..af67a437 100644 --- a/src/git/hook.rs +++ b/src/git/hook.rs @@ -68,12 +68,12 @@ mod tests { use std::ops::Not; use std::path::PathBuf; use std::process::Command; - use temp_testdir::TempDir; + use tempfile::TempDir; #[test] fn add_pre_commit_hook() -> Result<()> { - let temp = TempDir::default(); - let temp = temp.to_path_buf(); + let temp = TempDir::new()?; + let temp = temp.path().to_path_buf(); env::set_current_dir(&temp)?; Command::new("git").arg("init").output()?; @@ -89,8 +89,8 @@ mod tests { #[test] fn add_pre_push_hook() -> Result<()> { - let temp = TempDir::default(); - let temp = temp.to_path_buf(); + let tmp = TempDir::new()?; + let temp = tmp.path().to_path_buf(); env::set_current_dir(&temp)?; Command::new("git").arg("init").output()?; @@ -108,9 +108,9 @@ mod tests { #[test] fn add_all() -> Result<()> { - let temp = TempDir::default(); - let temp = temp.to_path_buf(); - env::set_current_dir(&temp)?; + let tmp = TempDir::new()?; + let tmp = tmp.path().to_path_buf(); + env::set_current_dir(&tmp)?; Command::new("git").arg("init").output()?; @@ -128,9 +128,9 @@ mod tests { fn should_have_perm_755_on_unix() -> Result<()> { use std::os::unix::fs::PermissionsExt; - let temp = TempDir::default(); - let temp = temp.to_path_buf(); - env::set_current_dir(&temp)?; + let tmp = TempDir::new()?; + let tmp = tmp.path().to_path_buf(); + env::set_current_dir(&tmp)?; Command::new("git").arg("init").output()?; diff --git a/src/git/repository.rs b/src/git/repository.rs index 85cd424d..ac2a1d6c 100644 --- a/src/git/repository.rs +++ b/src/git/repository.rs @@ -244,13 +244,13 @@ mod test { use anyhow::Result; use std::ops::Not; use std::process::{Command, Stdio}; - use temp_testdir::TempDir; + use tempfile::TempDir; #[test] fn init_repo() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let repo = Repository::init(&temp_testdir.join("test_repo")); + let repo = Repository::init(&tmp.path().join("test_repo")); assert!(repo.is_ok()); Ok(()) @@ -258,9 +258,9 @@ mod test { #[test] fn create_commit_ok() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -271,9 +271,9 @@ mod test { #[test] fn not_create_empty_commit() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; assert!(repo.commit("feat: a test commit").is_err()); @@ -282,9 +282,9 @@ mod test { #[test] fn not_create_empty_commit_with_unstaged_changed() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; @@ -294,9 +294,9 @@ mod test { #[test] fn get_repo_working_dir_some() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; let dir = &path.join("dir"); std::fs::create_dir(dir)?; @@ -308,9 +308,9 @@ mod test { #[test] fn get_diff_some() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -321,9 +321,9 @@ mod test { #[test] fn get_diff_none() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; @@ -333,9 +333,9 @@ mod test { #[test] fn get_diff_include_untracked_some() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; @@ -345,9 +345,9 @@ mod test { #[test] fn get_diff_include_untracked_none() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; assert!(repo.get_diff(true).is_none()); @@ -357,10 +357,10 @@ mod test { // see: https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server #[test] fn open_bare_err() -> Result<()> { - let temp_testdir = TempDir::default(); - std::env::set_current_dir(&temp_testdir)?; + let tmp = TempDir::new()?; + std::env::set_current_dir(&tmp)?; - let tmp = &temp_testdir.to_str().unwrap(); + let tmp = &tmp.path().to_str().unwrap(); Command::new("git") .arg("init") @@ -377,9 +377,9 @@ mod test { #[test] fn get_repo_statuses_empty() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; let statuses = repo.get_statuses()?; @@ -390,9 +390,9 @@ mod test { #[test] fn get_repo_statuses_not_empty() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; @@ -404,9 +404,9 @@ mod test { #[test] fn get_repo_head_oid_ok() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -421,9 +421,9 @@ mod test { #[test] fn get_repo_head_oid_err() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; let oid = repo.get_head_commit_oid(); @@ -434,9 +434,9 @@ mod test { #[test] fn get_repo_head_obj_ok() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -451,9 +451,9 @@ mod test { #[test] fn get_repo_head_obj_err() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -466,9 +466,9 @@ mod test { #[test] fn resolve_lightweight_tag_ok() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -483,9 +483,9 @@ mod test { #[test] fn resolve_lightweight_tag_err() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -500,9 +500,9 @@ mod test { #[test] fn get_latest_tag_ok() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -523,9 +523,9 @@ mod test { #[test] fn get_latest_tag_err() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -539,9 +539,9 @@ mod test { #[test] fn get_latest_tag_oid_ok() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -556,9 +556,9 @@ mod test { #[test] fn get_latest_tag_oid_err() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -572,9 +572,9 @@ mod test { #[test] fn get_head_some() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; @@ -588,9 +588,9 @@ mod test { #[test] fn get_head_none() -> Result<()> { - let temp_testdir = TempDir::default(); + let tmp = TempDir::new()?; - let path = temp_testdir.join("test_repo"); + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; std::fs::write(&path.join("file"), "changes")?; repo.add_all()?; diff --git a/src/git/status.rs b/src/git/status.rs index 536fbb46..bca82a5b 100644 --- a/src/git/status.rs +++ b/src/git/status.rs @@ -108,12 +108,12 @@ mod test { use git2::Repository; use git2::StatusOptions; use std::fs; - use temp_testdir::TempDir; + use tempfile::TempDir; #[test] fn should_get_statuses_from_git_statuses() -> Result<()> { - let temp_testdir = TempDir::default(); - let path = temp_testdir.join("test_repo"); + let tmp = TempDir::new()?; + let path = tmp.path().join("test_repo"); let repo = Repository::init(&path)?; fs::write(path.join("file"), "content")?; diff --git a/src/lib.rs b/src/lib.rs index f8b0113b..22cf49bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::process::{exit, Command, Stdio}; use std::{collections::HashMap, str::FromStr}; -use tempdir::TempDir; +use tempfile::TempDir; pub type CommitsMetadata = HashMap; @@ -174,7 +174,7 @@ impl CocoGitto { let head = self.repository.get_head_commit()?; let commits = self.repository.get_commit_range(from, head.id())?; let editor = std::env::var("EDITOR")?; - let dir = TempDir::new("cocogito")?; + let dir = TempDir::new()?; let errored_commits: Vec = commits .iter() diff --git a/tests/coco_commit_test.rs b/tests/coco_commit_test.rs index aaf9f8aa..b901313d 100644 --- a/tests/coco_commit_test.rs +++ b/tests/coco_commit_test.rs @@ -1,7 +1,7 @@ use anyhow::Result; use assert_cmd::prelude::*; use std::process::Command; -use temp_testdir::TempDir; +use tempfile::TempDir; mod helper; @@ -10,10 +10,10 @@ mod helper; fn commit_ok() -> Result<()> { let current_dir = std::env::current_dir()?; let mut command = Command::cargo_bin("coco")?; - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; - std::fs::write(temp_dir.join("test_file"), "content")?; + std::fs::write(temp_dir.path().join("test_file"), "content")?; helper::git_add()?; command @@ -33,10 +33,10 @@ fn commit_ok() -> Result<()> { fn unstaged_changes_commit_err() -> Result<()> { let current_dir = std::env::current_dir()?; let mut command = Command::cargo_bin("coco")?; - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; - std::fs::write(temp_dir.join("test_file"), "content")?; + std::fs::write(temp_dir.path().join("test_file"), "content")?; command .arg("feat") @@ -55,13 +55,13 @@ fn unstaged_changes_commit_err() -> Result<()> { fn untracked_changes_commit_ok() -> Result<()> { let current_dir = std::env::current_dir()?; let mut command = Command::cargo_bin("coco")?; - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; - std::fs::write(temp_dir.join("staged"), "content")?; + std::fs::write(temp_dir.path().join("staged"), "content")?; helper::git_add()?; - std::fs::write(temp_dir.join("untracked"), "content")?; + std::fs::write(temp_dir.path().join("untracked"), "content")?; command .arg("feat") @@ -80,9 +80,9 @@ fn untracked_changes_commit_ok() -> Result<()> { fn empty_commit_err() -> Result<()> { let current_dir = std::env::current_dir()?; let mut command = Command::cargo_bin("coco")?; - let temp_dir = TempDir::default(); + let tmp = TempDir::new()?; - std::env::set_current_dir(&temp_dir.to_path_buf())?; + std::env::set_current_dir(&tmp.path().to_path_buf())?; helper::git_init(".")?; command diff --git a/tests/cog_bump_test.rs b/tests/cog_bump_test.rs index 96f572ae..f034fa7e 100644 --- a/tests/cog_bump_test.rs +++ b/tests/cog_bump_test.rs @@ -1,8 +1,7 @@ use anyhow::Result; use assert_cmd::prelude::*; use std::process::Command; -use temp_testdir::TempDir; - +use tempfile::TempDir; mod helper; #[test] @@ -11,7 +10,7 @@ fn auto_bump_from_start_ok() -> Result<()> { let current_dir = std::env::current_dir()?; let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--auto"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -19,7 +18,7 @@ fn auto_bump_from_start_ok() -> Result<()> { helper::git_commit("fix: bug fix")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("0.1.0")?; Ok(std::env::set_current_dir(current_dir)?) @@ -32,7 +31,7 @@ fn auto_bump_minor_from_latest_tag() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--auto"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -44,7 +43,7 @@ fn auto_bump_minor_from_latest_tag() -> Result<()> { helper::git_commit("feat: feature 2")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("1.1.0")?; Ok(std::env::set_current_dir(current_dir)?) @@ -57,7 +56,7 @@ fn auto_bump_major_from_latest_tag() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--auto"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -69,7 +68,7 @@ fn auto_bump_major_from_latest_tag() -> Result<()> { helper::git_commit("feat: feature 2")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("2.0.0")?; Ok(std::env::set_current_dir(current_dir)?) @@ -82,7 +81,7 @@ fn auto_bump_patch_from_latest_tag() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--auto"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -94,7 +93,7 @@ fn auto_bump_patch_from_latest_tag() -> Result<()> { helper::git_commit("fix: fix 2")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("1.0.1")?; Ok(std::env::set_current_dir(current_dir)?) @@ -107,7 +106,7 @@ fn auto_bump_respect_semver_sorting() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--auto"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -120,7 +119,7 @@ fn auto_bump_respect_semver_sorting() -> Result<()> { helper::git_commit("fix: fix 2")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("0.10.1")?; Ok(std::env::set_current_dir(current_dir)?) @@ -133,7 +132,7 @@ fn minor_bump() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--minor"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -141,7 +140,7 @@ fn minor_bump() -> Result<()> { helper::git_commit("feat: feature")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("1.1.0")?; Ok(std::env::set_current_dir(current_dir)?) @@ -154,7 +153,7 @@ fn major_bump() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--major"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -162,7 +161,7 @@ fn major_bump() -> Result<()> { helper::git_commit("feat: feature")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("2.0.0")?; Ok(std::env::set_current_dir(current_dir)?) @@ -175,7 +174,7 @@ fn patch_bump() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--patch"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -183,7 +182,7 @@ fn patch_bump() -> Result<()> { helper::git_commit("feat: feature")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("1.0.1")?; Ok(std::env::set_current_dir(current_dir)?) @@ -196,7 +195,7 @@ fn pre_release_bump() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--major").arg("--pre").arg("alpha"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; helper::git_init(".")?; helper::git_commit("chore: init")?; @@ -204,7 +203,7 @@ fn pre_release_bump() -> Result<()> { helper::git_commit("feat: feature")?; command.assert().success(); - assert!(temp_dir.join("CHANGELOG.md").exists()); + assert!(temp_dir.path().join("CHANGELOG.md").exists()); helper::assert_tag("2.0.0-alpha")?; Ok(std::env::set_current_dir(current_dir)?) @@ -218,7 +217,7 @@ fn bump_with_hook() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("bump").arg("--major"); - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; std::fs::write("cog.toml", r#"pre_bump_hooks = ["touch {{version}}"]"#)?; @@ -229,7 +228,7 @@ fn bump_with_hook() -> Result<()> { helper::git_commit("feat: feature")?; command.assert().success(); - assert!(temp_dir.join("2.0.0").exists()); + assert!(temp_dir.path().join("2.0.0").exists()); helper::assert_tag("2.0.0")?; Ok(std::env::set_current_dir(current_dir)?) diff --git a/tests/cog_init_test_it.rs b/tests/cog_init_test_it.rs index 011b1e2b..6cba918e 100644 --- a/tests/cog_init_test_it.rs +++ b/tests/cog_init_test_it.rs @@ -3,7 +3,7 @@ use assert_cmd::prelude::*; use cocogitto::CONFIG_PATH; use helper::*; use std::process::Command; -use temp_testdir::TempDir; +use tempfile::TempDir; mod helper; @@ -16,8 +16,8 @@ fn init_empty_repo_in_target_dir() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("init").arg("test_repo"); - let temp_dir = TempDir::default(); - std::env::set_current_dir(&temp_dir)?; + let temp_dir = TempDir::new()?; + std::env::set_current_dir(&temp_dir.path())?; command.assert().success(); Ok(std::env::set_current_dir(current_dir)?) @@ -31,10 +31,10 @@ fn init_existing_repo() -> Result<()> { command.arg("init").arg("test_repo_existing"); // Create repo with commits - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; std::env::set_current_dir(&temp_dir)?; git_init("test_repo_existing")?; - std::env::set_current_dir(temp_dir.join("test_repo_existing"))?; + std::env::set_current_dir(temp_dir.path().join("test_repo_existing"))?; helper::git_commit("chore: test commit")?; @@ -46,7 +46,7 @@ fn init_existing_repo() -> Result<()> { #[cfg(not(tarpaulin))] fn fail_if_config_exist() -> Result<()> { let current_dir = std::env::current_dir()?; - let temp_dir = TempDir::default(); + let temp_dir = TempDir::new()?; let mut command = Command::cargo_bin("cog")?; command.arg("init").arg("test_repo_existing"); @@ -55,7 +55,7 @@ fn fail_if_config_exist() -> Result<()> { std::env::set_current_dir(&temp_dir)?; helper::git_init("test_repo_existing")?; std::fs::write( - &temp_dir.join("test_repo_existing").join(CONFIG_PATH), + &temp_dir.path().join("test_repo_existing").join(CONFIG_PATH), "[hooks]", )?; helper::git_commit("chore: test commit")?; @@ -72,8 +72,8 @@ fn init_current_dir_with_no_arg() -> Result<()> { let mut command = Command::cargo_bin("cog")?; command.arg("init"); - let temp_dir = TempDir::default(); - let path = temp_dir.join("test_repo_no_args"); + let temp_dir = TempDir::new()?; + let path = temp_dir.path().join("test_repo_no_args"); std::fs::create_dir(&path)?; std::env::set_current_dir(&path)?; diff --git a/tests/git_test.rs b/tests/git_test.rs index 43463757..ee5717ad 100644 --- a/tests/git_test.rs +++ b/tests/git_test.rs @@ -1,14 +1,13 @@ use anyhow::Result; use cocogitto::CocoGitto; use helper::*; -use temp_testdir::TempDir; - +use tempfile::TempDir; mod helper; #[test] fn open_repo_ok() -> Result<()> { - let tempdir = TempDir::default(); - std::env::set_current_dir(&tempdir)?; + let tempdir = TempDir::new()?; + std::env::set_current_dir(&tempdir.path())?; git_init("open_repo_ok")?; std::env::set_current_dir(std::env::current_dir()?.join("open_repo_ok"))?; create_empty_config()?; @@ -21,9 +20,9 @@ fn open_repo_ok() -> Result<()> { #[test] fn open_repo_err() -> Result<()> { - let path = TempDir::default(); - std::env::set_current_dir(&path)?; - std::fs::create_dir(&path.join("not_a_repo"))?; + let tmp = TempDir::new()?; + std::env::set_current_dir(&tmp)?; + std::fs::create_dir(&tmp.path().join("not_a_repo"))?; create_empty_config()?; let gitto = CocoGitto::get(); @@ -34,10 +33,10 @@ fn open_repo_err() -> Result<()> { #[test] fn check_commit_history_ok() -> Result<()> { - let tempdir = TempDir::default(); - std::env::set_current_dir(&tempdir)?; + let tmp = TempDir::new()?; + std::env::set_current_dir(&tmp)?; git_init("commit_history_ok")?; - std::env::set_current_dir(&tempdir.join("commit_history_ok"))?; + std::env::set_current_dir(&tmp.path().join("commit_history_ok"))?; create_empty_config()?; git_commit("feat: a valid commit")?; @@ -51,10 +50,10 @@ fn check_commit_history_ok() -> Result<()> { #[test] fn check_commit_history_err() -> Result<()> { - let tempdir = TempDir::default(); - std::env::set_current_dir(&tempdir)?; + let tmp = TempDir::new()?; + std::env::set_current_dir(&tmp)?; git_init("commit_history_err")?; - std::env::set_current_dir(&tempdir.join("commit_history_err"))?; + std::env::set_current_dir(&tmp.path().join("commit_history_err"))?; create_empty_config()?; git_commit("feat: a valid commit")?;