diff options
author | Georg Brandl <georg@python.org> | 2014-11-11 08:57:19 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-11-11 08:57:19 +0100 |
commit | 421490248a3208a786a31a3c8a541bd0e28f7924 (patch) | |
tree | 8b6a76697c309fb7a9e125661831614db2c3a111 | |
parent | 51d35f516f952edfea4ea6c7b3661d2a47e164d3 (diff) | |
parent | e460ebf07d887385aed294fee486f67b9718a7d1 (diff) | |
download | pygments-421490248a3208a786a31a3c8a541bd0e28f7924.tar.gz |
merge with stable
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | pygments/cmdline.py | 21 | ||||
-rw-r--r-- | tests/test_cmdline.py | 15 |
3 files changed, 33 insertions, 7 deletions
@@ -2,9 +2,9 @@ Pygments changelog ================== Issue numbers refer to the tracker at -<http://bitbucket.org/birkenfeld/pygments-main/issues>, +<https://bitbucket.org/birkenfeld/pygments-main/issues>, pull request numbers to the requests at -<http://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged>. +<https://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged>. Version 2.0.1 diff --git a/pygments/cmdline.py b/pygments/cmdline.py index 20e87c36..53e858b5 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -30,7 +30,7 @@ from pygments.styles import get_all_styles, get_style_by_name USAGE = """\ Usage: %s [-l <lexer> | -g] [-F <filter>[:<options>]] [-f <formatter>] - [-O <options>] [-P <option=value>] [-s] [-o <outfile>] [<infile>] + [-O <options>] [-P <option=value>] [-s] [-v] [-o <outfile>] [<infile>] %s -S <style> -f <formatter> [-a <arg>] [-O <options>] [-P <option=value>] %s -L [<which> ...] @@ -90,6 +90,9 @@ waiting to process the entire file. This only works for stdin, and is intended for streaming input such as you get from 'tail -f'. Example usage: "tail -f sql.log | pygmentize -s -l sql" +The -v option prints a detailed traceback on unhandled exceptions, +which is useful for debugging and bug reports. + The -h option prints this help. The -V option prints the package version. """ @@ -496,7 +499,7 @@ def main(args=sys.argv): usage = USAGE % ((args[0],) * 6) try: - popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHgs") + popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:vhVHgs") except getopt.GetoptError: print(usage, file=sys.stderr) return 2 @@ -504,6 +507,18 @@ def main(args=sys.argv): try: return main_inner(popts, args, usage) except Exception: + if '-v' in dict(popts): + print(file=sys.stderr) + print('*' * 65, file=sys.stderr) + print('An unhandled exception occurred while highlighting.', + file=sys.stderr) + print('Please report the whole traceback to the issue tracker at', + file=sys.stderr) + print('<https://bitbucket.org/birkenfeld/pygments-main/issues>.', + file=sys.stderr) + print('*' * 65, file=sys.stderr) + print(file=sys.stderr) + raise import traceback info = traceback.format_exception(*sys.exc_info()) msg = info[-1].strip() @@ -513,4 +528,6 @@ def main(args=sys.argv): print(file=sys.stderr) print('*** Error while highlighting:', file=sys.stderr) print(msg, file=sys.stderr) + print('*** If this is a bug you want to report, please rerun with -v.', + file=sys.stderr) return 1 diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 64c4245e..8929ce0a 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -156,10 +156,19 @@ class CmdLineTest(unittest.TestCase): self.assertTrue('Error: filter \'foo\' not found' in e) def test_exception(self): - # unexpected exception while highlighting - cmdline.highlight = None # override callable + cmdline.highlight = None # override callable to provoke TypeError try: + # unexpected exception while highlighting e = self.check_failure('-lpython', TESTFILE) + self.assertTrue('*** Error while highlighting:' in e) + self.assertTrue('TypeError' in e) + + # same with -v: should reraise the exception + try: + self.check_failure('-lpython', '-v', TESTFILE) + except Exception: + pass + else: + self.fail('exception not reraised') finally: cmdline.highlight = highlight - self.assertTrue('*** Error while highlighting:' in e) |