|
| 1 | +"""Tests for .github/scripts/bump-kind.sh (release.yml and pages.yml share it). |
| 2 | +
|
| 3 | +Run: python tests/test_bump_kind.py -v (needs bash). |
| 4 | +""" |
| 5 | +from __future__ import annotations |
| 6 | + |
| 7 | +import shutil |
| 8 | +import subprocess |
| 9 | +import unittest |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +SCRIPT = Path(__file__).resolve().parent.parent / ".github" / "scripts" / "bump-kind.sh" |
| 13 | +# Resolve now: on Windows CreateProcess would find System32\bash.exe (WSL) first. |
| 14 | +BASH = shutil.which("bash") |
| 15 | + |
| 16 | + |
| 17 | +def kind(*messages: str) -> str: |
| 18 | + # git log --format='%B%x00' separates entries with "\n" after each NUL. |
| 19 | + stdin = "\n".join(m + "\0" for m in messages) |
| 20 | + # Bytes, not text mode: on Windows text mode rewrites LF as CRLF. |
| 21 | + out = subprocess.run( |
| 22 | + [BASH, SCRIPT.as_posix()], input=stdin.encode(), capture_output=True, check=True |
| 23 | + ) |
| 24 | + return out.stdout.decode().strip() |
| 25 | + |
| 26 | + |
| 27 | +@unittest.skipIf(BASH is None, "bash not available") |
| 28 | +class BumpKind(unittest.TestCase): |
| 29 | + def test_docs_and_chore_do_not_release(self): |
| 30 | + self.assertEqual(kind("docs: tidy README\n", "chore: bump version to 1.2.3 [skip ci]\n"), "none") |
| 31 | + |
| 32 | + def test_fix_is_patch(self): |
| 33 | + self.assertEqual(kind("fix(snippets): x\n"), "patch") |
| 34 | + |
| 35 | + def test_feat_is_minor_and_beats_fix(self): |
| 36 | + self.assertEqual(kind("fix: a\n", "feat(showcase): b\n"), "minor") |
| 37 | + |
| 38 | + def test_bang_subject_is_major(self): |
| 39 | + self.assertEqual(kind("feat(api)!: drop 4.5\n"), "major") |
| 40 | + |
| 41 | + def test_breaking_footer_is_major(self): |
| 42 | + self.assertEqual(kind("refactor: x\n\nBREAKING CHANGE: removes y\n"), "major") |
| 43 | + |
| 44 | + def test_breaking_prose_in_subject_is_not_major(self): |
| 45 | + # Was major: the old grep matched "BREAKING[ -]CHANGE" anywhere, -i. |
| 46 | + self.assertEqual(kind("docs: explain breaking-change policy\n"), "none") |
| 47 | + self.assertEqual(kind("fix: note the breaking change in docs\n"), "patch") |
| 48 | + |
| 49 | + def test_lowercase_footer_is_not_major(self): |
| 50 | + self.assertEqual(kind("fix: x\n\nbreaking change: no\n"), "patch") |
| 51 | + |
| 52 | + def test_empty_input_is_none(self): |
| 53 | + self.assertEqual(kind(), "none") |
| 54 | + |
| 55 | + |
| 56 | +if __name__ == "__main__": |
| 57 | + unittest.main() |
0 commit comments