summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-11-11 19:14:13 +0100
committerGeorg Brandl <georg@python.org>2014-11-11 19:14:13 +0100
commit7ea9ac3db778e05fe2655018ca2fc5736c837489 (patch)
tree82aea6b4ecd074502a98a2e2321a0d25f16b5713
parent6ef0dc9af1f4343f9574a589058cb6d0fa01b8d8 (diff)
downloadpygments-7ea9ac3db778e05fe2655018ca2fc5736c837489.tar.gz
Fix -H return codes and test them.
-rw-r--r--pygments/cmdline.py5
-rw-r--r--tests/test_cmdline.py4
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)