Skip to content

Commit 21cbcc5

Browse files
vapierLUCI
authored and
LUCI
committed
update-manpages: include in unittests
People often forget to regen when making interface changes. We skip the test if help2man isn't installed since it's not common, and it's not available on our CI bots currently. Change-Id: Ib4911a0e3fa1294ad90e4ac8afc047a0b7c2b66d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/469741 Tested-by: Mike Frysinger <[email protected]> Reviewed-by: Gavin Mak <[email protected]> Commit-Queue: Mike Frysinger <[email protected]>
1 parent 0f200bb commit 21cbcc5

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

release/update_manpages.py

+31-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
import subprocess
2828
import sys
2929
import tempfile
30+
from typing import List
3031

3132

32-
TOPDIR = Path(__file__).resolve().parent.parent
33+
THIS_FILE = Path(__file__).resolve()
34+
TOPDIR = THIS_FILE.parent.parent
3335
MANDIR = TOPDIR.joinpath("man")
3436

3537
# Load repo local modules.
@@ -42,9 +44,23 @@ def worker(cmd, **kwargs):
4244
subprocess.run(cmd, **kwargs)
4345

4446

45-
def main(argv):
47+
def get_parser() -> argparse.ArgumentParser:
48+
"""Get argument parser."""
4649
parser = argparse.ArgumentParser(description=__doc__)
47-
parser.parse_args(argv)
50+
parser.add_argument(
51+
"-n",
52+
"--check",
53+
"--dry-run",
54+
action="store_const",
55+
const=True,
56+
help="Check if changes are necessary; don't actually change files",
57+
)
58+
return parser
59+
60+
61+
def main(argv: List[str]) -> int:
62+
parser = get_parser()
63+
opts = parser.parse_args(argv)
4864

4965
if not shutil.which("help2man"):
5066
sys.exit("Please install help2man to continue.")
@@ -117,6 +133,7 @@ def main(argv):
117133
functools.partial(worker, cwd=tempdir, check=True), cmdlist
118134
)
119135

136+
ret = 0
120137
for tmp_path in MANDIR.glob("*.1.tmp"):
121138
path = tmp_path.parent / tmp_path.stem
122139
old_data = path.read_text() if path.exists() else ""
@@ -133,7 +150,17 @@ def main(argv):
133150
)
134151
new_data = re.sub(r'^(\.TH REPO "1" ")([^"]+)', r"\1", data, flags=re.M)
135152
if old_data != new_data:
136-
path.write_text(data)
153+
if opts.check:
154+
ret = 1
155+
print(
156+
f"{THIS_FILE.name}: {path.name}: "
157+
"man page needs regenerating",
158+
file=sys.stderr,
159+
)
160+
else:
161+
path.write_text(data)
162+
163+
return ret
137164

138165

139166
def replace_regex(data):

run_tests

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import functools
1919
import os
20+
import shutil
2021
import subprocess
2122
import sys
2223
from typing import List
@@ -101,6 +102,19 @@ def run_isort():
101102
).returncode
102103

103104

105+
def run_update_manpages() -> int:
106+
"""Returns the exit code from release/update-manpages."""
107+
if not shutil.which("help2mafn"):
108+
print("update-manpages: help2man not found; skipping test")
109+
return 0
110+
111+
return subprocess.run(
112+
[sys.executable, "release/update-manpages", "--check"],
113+
check=False,
114+
cwd=ROOT_DIR,
115+
).returncode
116+
117+
104118
def main(argv):
105119
"""The main entry."""
106120
checks = (
@@ -109,6 +123,7 @@ def main(argv):
109123
run_black,
110124
run_flake8,
111125
run_isort,
126+
run_update_manpages,
112127
)
113128
# Run all the tests all the time to get full feedback. Don't exit on the
114129
# first error as that makes it more difficult to iterate in the CQ.

0 commit comments

Comments
 (0)