From e7e20f4686e1be6a3914df0a5ec60c7d32ba8775 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 18 Apr 2023 00:05:53 -0400 Subject: [PATCH] tests: do not allow underscores in cli options We use dashes in --long-options, not underscores, so add a test to make sure people don't accidentally add them. Change-Id: Iffbce474d22cf1f6c2042f7882f215875c8df3cf Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/369734 Reviewed-by: Gavin Mak Tested-by: Mike Frysinger Commit-Queue: Mike Frysinger --- tests/test_subcmds.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_subcmds.py b/tests/test_subcmds.py index 73b66e3f..5ce0776f 100644 --- a/tests/test_subcmds.py +++ b/tests/test_subcmds.py @@ -75,3 +75,17 @@ class AllCommands(unittest.TestCase): msg=f"subcmds/{name}.py: {option.get_opt_string()}: " f'help text should not end in a period: "{option.help}"', ) + + def test_cli_option_style(self): + """Force some consistency in option flags.""" + for name, cls in subcmds.all_commands.items(): + cmd = cls() + parser = cmd.OptionParser + for option in parser.option_list: + for opt in option._long_opts: + self.assertNotIn( + "_", + opt, + msg=f"subcmds/{name}.py: {opt}: only use dashes in " + "options, not underscores", + )