use std::fs::{copy, read_to_string};
use std::path::Path;
use snapbox::assert_eq_path;
use snapbox::cmd::{cargo_bin, Command};
use git_repo_helpers::*;
mod git_repo_helpers;
#[test]
fn git_release() {
let temp_dir = tempfile::tempdir().unwrap();
let temp_path = temp_dir.path();
let source_path = Path::new("tests/git_release");
init(temp_path);
commit(temp_path, "feat: Existing feature");
tag(temp_path, "v1.0.0");
commit(temp_path, "feat: New feature");
for file in ["knope.toml", "CHANGELOG.md", "Cargo.toml"] {
copy(source_path.join(file), temp_path.join(file)).unwrap();
}
let dry_run_assert = Command::new(cargo_bin!("knope"))
.arg("release")
.arg("--dry-run")
.current_dir(temp_dir.path())
.assert();
let actual_assert = Command::new(cargo_bin!("knope"))
.arg("release")
.current_dir(temp_dir.path())
.assert();
dry_run_assert
.success()
.stdout_eq_path(source_path.join("dry_run_output.txt"));
actual_assert
.success()
.stdout_matches_path(source_path.join("output.txt"));
assert_eq_path(
source_path.join("EXPECTED_CHANGELOG.md"),
read_to_string(temp_path.join("CHANGELOG.md")).unwrap(),
);
assert_eq_path(
source_path.join("Expected_Cargo.toml"),
read_to_string(temp_path.join("Cargo.toml")).unwrap(),
);
let tag = describe(temp_path, None);
assert_eq!(tag, "v1.1.0");
}
#[test]
fn multiple_packages() {
let temp_dir = tempfile::tempdir().unwrap();
let temp_path = temp_dir.path();
let source_path = Path::new("tests/git_release/multiple_packages");
init(temp_path);
commit(temp_path, "feat: Existing feature");
tag(temp_path, "first/v1.2.3");
tag(temp_path, "second/v0.4.6");
commit(temp_path, "feat!: New breaking feature");
for file in [
"knope.toml",
"FIRST_CHANGELOG.md",
"Cargo.toml",
"pyproject.toml",
"SECOND_CHANGELOG.md",
"package.json",
] {
copy(source_path.join(file), temp_path.join(file)).unwrap();
}
let dry_run_assert = Command::new(cargo_bin!("knope"))
.arg("release")
.arg("--dry-run")
.current_dir(temp_dir.path())
.assert();
let actual_assert = Command::new(cargo_bin!("knope"))
.arg("release")
.current_dir(temp_dir.path())
.assert();
dry_run_assert
.success()
.stdout_eq_path(source_path.join("dry_run_output.txt"));
actual_assert
.success()
.stdout_matches_path(source_path.join("output.txt"));
for file in [
"FIRST_CHANGELOG.md",
"SECOND_CHANGELOG.md",
"Cargo.toml",
"pyproject.toml",
"package.json",
] {
assert_eq_path(
source_path.join(format!("EXPECTED_{}", file)),
read_to_string(temp_path.join(file)).unwrap(),
);
}
assert_eq!(describe(temp_path, Some("first/*")), "first/v2.0.0");
assert_eq!(describe(temp_path, Some("second/*")), "second/v0.5.0");
}