Skip to content

Commit

Permalink
feat: add a test for dry_run option
Browse files Browse the repository at this point in the history
  • Loading branch information
darlaam authored and oknozor committed Apr 13, 2022
1 parent ad46106 commit c9437bb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl CocoGitto {
};

if dry_run {
println!("{}", version_str);
print!("{}", version_str);
return Ok(());
}

Expand Down
24 changes: 24 additions & 0 deletions tests/cog_tests/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ fn auto_bump_minor_from_latest_tag() -> Result<()> {
Ok(())
}

#[sealed_test]
fn auto_bump_dry_run_from_latest_tag() -> Result<()> {
git_init()?;
git_commit("chore: init")?;
git_commit("feat(taef): feature")?;
git_commit("fix: bug fix")?;
git_tag("1.0.0")?;
git_commit("feat(taef): feature")?;
git_commit("feat: feature 1")?;
git_commit("feat: feature 2")?;

Command::cargo_bin("cog")?
.arg("bump")
.arg("--auto")
.arg("--dry-run")
.assert()
.success()
.stdout("1.1.0");

assert_that!(Path::new("CHANGELOG.md")).does_not_exist();
assert_tag_does_not_exist("1.1.0")?;
Ok(())
}

#[sealed_test]
fn auto_bump_major_from_latest_tag() -> Result<()> {
git_init()?;
Expand Down
7 changes: 7 additions & 0 deletions tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ pub fn assert_tag_exists(tag: &str) -> Result<()> {
Ok(())
}

pub fn assert_tag_does_not_exist(tag: &str) -> Result<()> {
let tags = run_fun!(git --no-pager tag)?;
let tags: Vec<&str> = tags.split('\n').collect();
assert_that!(tags).does_not_contain(&tag);
Ok(())
}

pub fn assert_latest_tag(tag: &str) -> Result<()> {
let tags = run_fun!(git --no-pager tag)?;
let tags: Vec<&str> = tags.split('\n').collect();
Expand Down

0 comments on commit c9437bb

Please sign in to comment.