|
22 | 22 | NotAllowed,
|
23 | 23 | NoVersionSpecifiedError,
|
24 | 24 | )
|
25 | | -from tests.utils import create_file_and_commit |
| 25 | +from tests.utils import create_file_and_commit, create_tag |
26 | 26 |
|
27 | 27 |
|
28 | 28 | @pytest.mark.parametrize(
|
@@ -151,6 +151,31 @@ def test_bump_major_increment(commit_msg, mocker):
|
151 | 151 | assert tag_exists is True
|
152 | 152 |
|
153 | 153 |
|
| 154 | +@pytest.mark.usefixtures("tmp_commitizen_project") |
| 155 | +@pytest.mark.parametrize( |
| 156 | + "commit_msg", |
| 157 | + ( |
| 158 | + "feat: new user interface\n\nBREAKING CHANGE: age is no longer supported", |
| 159 | + "feat!: new user interface\n\nBREAKING CHANGE: age is no longer supported", |
| 160 | + "feat!: new user interface", |
| 161 | + "feat(user): new user interface\n\nBREAKING CHANGE: age is no longer supported", |
| 162 | + "feat(user)!: new user interface\n\nBREAKING CHANGE: age is no longer supported", |
| 163 | + "feat(user)!: new user interface", |
| 164 | + "BREAKING CHANGE: age is no longer supported", |
| 165 | + "BREAKING-CHANGE: age is no longer supported", |
| 166 | + ), |
| 167 | +) |
| 168 | +def test_bump_major_increment_major_version_zero(commit_msg, mocker): |
| 169 | + create_file_and_commit(commit_msg) |
| 170 | + |
| 171 | + testargs = ["cz", "bump", "--yes", "--major-version-zero"] |
| 172 | + mocker.patch.object(sys, "argv", testargs) |
| 173 | + cli.main() |
| 174 | + |
| 175 | + tag_exists = git.tag_exist("0.2.0") |
| 176 | + assert tag_exists is True |
| 177 | + |
| 178 | + |
154 | 179 | @pytest.mark.usefixtures("tmp_commitizen_project")
|
155 | 180 | @pytest.mark.parametrize(
|
156 | 181 | "commit_msg,increment,expected_tag",
|
@@ -320,6 +345,34 @@ def test_bump_when_version_inconsistent_in_version_files(
|
320 | 345 | assert partial_expected_error_message in str(excinfo.value)
|
321 | 346 |
|
322 | 347 |
|
| 348 | +def test_bump_major_version_zero_when_major_is_not_zero(mocker, tmp_commitizen_project): |
| 349 | + tmp_version_file = tmp_commitizen_project.join("__version__.py") |
| 350 | + tmp_version_file.write("1.0.0") |
| 351 | + tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") |
| 352 | + tmp_commitizen_cfg_file.write( |
| 353 | + f"[tool.commitizen]\n" |
| 354 | + 'version="1.0.0"\n' |
| 355 | + f'version_files = ["{str(tmp_version_file)}"]' |
| 356 | + ) |
| 357 | + tmp_changelog_file = tmp_commitizen_project.join("CHANGELOG.md") |
| 358 | + tmp_changelog_file.write("## v1.0.0") |
| 359 | + |
| 360 | + create_file_and_commit("feat(user): new file") |
| 361 | + create_tag("v1.0.0") |
| 362 | + create_file_and_commit("feat(user)!: new file") |
| 363 | + |
| 364 | + testargs = ["cz", "bump", "--yes", "--major-version-zero"] |
| 365 | + mocker.patch.object(sys, "argv", testargs) |
| 366 | + |
| 367 | + with pytest.raises(NotAllowed) as excinfo: |
| 368 | + cli.main() |
| 369 | + |
| 370 | + expected_error_message = ( |
| 371 | + "--major-version-zero is meaningless for current version 1.0.0" |
| 372 | + ) |
| 373 | + assert expected_error_message in str(excinfo.value) |
| 374 | + |
| 375 | + |
323 | 376 | def test_bump_files_only(mocker, tmp_commitizen_project):
|
324 | 377 | tmp_version_file = tmp_commitizen_project.join("__version__.py")
|
325 | 378 | tmp_version_file.write("0.1.0")
|
@@ -683,3 +736,20 @@ def test_bump_manual_version(mocker, manual_version):
|
683 | 736 | cli.main()
|
684 | 737 | tag_exists = git.tag_exist(manual_version)
|
685 | 738 | assert tag_exists is True
|
| 739 | + |
| 740 | + |
| 741 | +@pytest.mark.usefixtures("tmp_commitizen_project") |
| 742 | +def test_bump_manual_version_disallows_major_version_zero(mocker): |
| 743 | + create_file_and_commit("feat: new file") |
| 744 | + |
| 745 | + manual_version = "0.2.0" |
| 746 | + testargs = ["cz", "bump", "--yes", "--major-version-zero", manual_version] |
| 747 | + mocker.patch.object(sys, "argv", testargs) |
| 748 | + |
| 749 | + with pytest.raises(NotAllowed) as excinfo: |
| 750 | + cli.main() |
| 751 | + |
| 752 | + expected_error_message = ( |
| 753 | + "--major-version-zero cannot be combined with MANUAL_VERSION" |
| 754 | + ) |
| 755 | + assert expected_error_message in str(excinfo.value) |
0 commit comments