From 7ea9ac3db778e05fe2655018ca2fc5736c837489 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 11 Nov 2014 19:14:13 +0100 Subject: Fix -H return codes and test them. --- pygments/cmdline.py | 5 +++-- tests/test_cmdline.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pygments/cmdline.py b/pygments/cmdline.py index 40c1a599..608bd859 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -146,8 +146,10 @@ def _print_help(what, name): cls = find_filter_class(name) print("Help on the %s filter:" % name) print(dedent(cls.__doc__)) + return 0 except (AttributeError, ValueError): print("%s not found!" % what, file=sys.stderr) + return 1 def _print_list(what): @@ -250,8 +252,7 @@ def main_inner(popts, args, usage): print(usage, file=sys.stderr) return 2 - _print_help(what, name) - return 0 + return _print_help(what, name) # parse -O options parsed_opts = _parse_options(O_opts) diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index e7014418..f4c866a6 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -156,6 +156,8 @@ class CmdLineTest(unittest.TestCase): self.assertTrue('Python' in o) o = self.check_success("-H", "filter", "raiseonerror") self.assertTrue('raiseonerror', o) + e = self.check_failure("-H", "lexer", "foobar") + self.assertTrue('not found' in e) def test_S_opt(self): o = self.check_success("-S", "default", "-f", "html", "-O", "linenos=1") @@ -178,7 +180,7 @@ class CmdLineTest(unittest.TestCase): def test_invalid_opts(self): for opts in [("-L", "-lpy"), ("-L", "-fhtml"), ("-L", "-Ox"), - ("-a",), ("-Sst", "-lpy"), ("-H",), + ("-a", "arg"), ("-Sst", "-lpy"), ("-H",), ("-H", "formatter"), ("-H", "foo", "bar"), ("-s",)]: self.check_failure(*opts, code=2) -- cgit v1.2.1