|
34 | 34 | ValidationEngine, |
35 | 35 | ValidationResult, |
36 | 36 | declaration_boxes, |
| 37 | + is_autosquash_subject, |
37 | 38 | is_merge_subject, |
38 | 39 | is_revert_subject, |
39 | 40 | long_body_lines, |
@@ -1597,6 +1598,40 @@ def test_git_revert_subject_is_not_measured(self, subject): |
1597 | 1598 | ValidationResult.SKIP |
1598 | 1599 | ) |
1599 | 1600 |
|
| 1601 | + @pytest.mark.parametrize( |
| 1602 | + "subject", |
| 1603 | + [ |
| 1604 | + "fixup! feat(parser): accept trailing commas in the argument list of a call", |
| 1605 | + "squash! feat(parser): accept trailing commas in the argument list of a call", |
| 1606 | + "amend! feat(parser): accept trailing commas in the argument list of a call", |
| 1607 | + "fixup! fixup! feat(parser): accept trailing commas in the argument list of a call", |
| 1608 | + ], |
| 1609 | + ) |
| 1610 | + def test_git_fixup_subject_is_not_measured(self, subject): |
| 1611 | + """A subject that fit the limit still fits once git puts "fixup! " |
| 1612 | + in front of it: the prefix is git's, and --autosquash folds it away.""" |
| 1613 | + rule = ValidationRule(check="subject_max_length", value=72) |
| 1614 | + validator = SubjectLengthValidator(rule) |
| 1615 | + assert len(subject) > 72 |
| 1616 | + assert validator.validate(ValidationContext(stdin_text=subject)) == ( |
| 1617 | + ValidationResult.SKIP |
| 1618 | + ) |
| 1619 | + |
| 1620 | + @pytest.mark.parametrize( |
| 1621 | + "subject", |
| 1622 | + [ |
| 1623 | + "fixup!! feat(parser): accept trailing commas in the argument list of a call", |
| 1624 | + "Fixup! feat(parser): accept trailing commas in the argument list of a call", |
| 1625 | + ], |
| 1626 | + ) |
| 1627 | + def test_author_fixup_lookalike_is_measured(self, subject): |
| 1628 | + rule = ValidationRule(check="subject_max_length", value=72) |
| 1629 | + validator = SubjectLengthValidator(rule) |
| 1630 | + validator._suppress_output = True |
| 1631 | + assert validator.validate(ValidationContext(stdin_text=subject)) == ( |
| 1632 | + ValidationResult.FAIL |
| 1633 | + ) |
| 1634 | + |
1600 | 1635 | def test_author_revert_prose_is_measured(self): |
1601 | 1636 | rule = ValidationRule(check="subject_max_length", value=80) |
1602 | 1637 | validator = SubjectLengthValidator(rule) |
@@ -1895,6 +1930,27 @@ def test_subject_capitalization_validator_not_capitalized(self): |
1895 | 1930 | result = validator.validate(context) |
1896 | 1931 | assert result == ValidationResult.FAIL |
1897 | 1932 |
|
| 1933 | + @pytest.mark.parametrize( |
| 1934 | + "subject", |
| 1935 | + ["fixup! feat: add x", "squash! add x", "amend! fix: add x"], |
| 1936 | + ) |
| 1937 | + def test_git_fixup_subject_is_not_judged(self, subject): |
| 1938 | + """git writes the lower-case prefix; capitalizing it would stop |
| 1939 | + --autosquash from finding the commit.""" |
| 1940 | + rule = ValidationRule(check="subject_capitalized") |
| 1941 | + validator = SubjectCapitalizationValidator(rule) |
| 1942 | + assert validator.validate(ValidationContext(stdin_text=subject)) == ( |
| 1943 | + ValidationResult.SKIP |
| 1944 | + ) |
| 1945 | + |
| 1946 | + def test_author_fixup_lookalike_is_judged(self): |
| 1947 | + rule = ValidationRule(check="subject_capitalized") |
| 1948 | + validator = SubjectCapitalizationValidator(rule) |
| 1949 | + validator._suppress_output = True |
| 1950 | + assert validator.validate(ValidationContext(stdin_text="fixup!! add x")) == ( |
| 1951 | + ValidationResult.FAIL |
| 1952 | + ) |
| 1953 | + |
1898 | 1954 |
|
1899 | 1955 | class TestBodyValidator: |
1900 | 1956 | @pytest.mark.parametrize( |
@@ -4292,6 +4348,8 @@ def test_merge_and_fixup_subjects_still_bypass_the_rule(self): |
4292 | 4348 | not judged, and SKIP keeps that distinct from having passed.""" |
4293 | 4349 | assert self._verdict("Merge branch 'main' into topic") == ValidationResult.SKIP |
4294 | 4350 | assert self._verdict("fixup! fixed the parser") == ValidationResult.SKIP |
| 4351 | + assert self._verdict("squash! fixed the parser") == ValidationResult.SKIP |
| 4352 | + assert self._verdict("amend! fixed the parser") == ValidationResult.SKIP |
4295 | 4353 |
|
4296 | 4354 | @pytest.mark.benchmark |
4297 | 4355 | def test_author_subject_starting_with_merge_is_judged(self): |
@@ -4344,6 +4402,22 @@ def test_tool_written_subject(self, subject): |
4344 | 4402 | def test_author_prose(self, subject): |
4345 | 4403 | assert not is_merge_subject(subject) |
4346 | 4404 |
|
| 4405 | + @pytest.mark.parametrize( |
| 4406 | + "subject, expected", |
| 4407 | + [ |
| 4408 | + ("fixup! feat: x", True), |
| 4409 | + ("squash! feat: x", True), |
| 4410 | + ("amend! feat: x", True), |
| 4411 | + ("fixup! fixup! feat: x", True), |
| 4412 | + ("fixup!feat: x", False), |
| 4413 | + ("fixup!! feat: x", False), |
| 4414 | + ("Fixup! feat: x", False), |
| 4415 | + ("feat: fixup! x", False), |
| 4416 | + ], |
| 4417 | + ) |
| 4418 | + def test_autosquash_subject(self, subject, expected): |
| 4419 | + assert is_autosquash_subject(subject) is expected |
| 4420 | + |
4347 | 4421 | @pytest.mark.parametrize( |
4348 | 4422 | "subject, expected", |
4349 | 4423 | [ |
|
0 commit comments