Patchwork [v3] run-tests: also color the summary messages (skipped, failed...)

login
register
mail settings
Submitter Matthieu Laneuville
Date July 17, 2017, 10:33 p.m.
Message ID <14c07f0460918fe57b1c.1500330830@carbon>
Download mbox | patch
Permalink /patch/22459/
State Accepted
Headers show

Comments

Matthieu Laneuville - July 17, 2017, 10:33 p.m.
# HG changeset patch
# User Matthieu Laneuville <matthieu.laneuville@octobus.net>
# Date 1500330427 -32400
#      Tue Jul 18 07:27:07 2017 +0900
# Node ID 14c07f0460918fe57b1c2709fe3ea3f071a95659
# Parent  7f5f97697162331b5acf78aef091ae3fd341e308
run-tests: also color the summary messages (skipped, failed...)
Yuya Nishihara - July 18, 2017, 1:19 p.m.
On Tue, 18 Jul 2017 07:33:50 +0900, mlaneuville@gmail.com wrote:
> # HG changeset patch
> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
> # Date 1500330427 -32400
> #      Tue Jul 18 07:27:07 2017 +0900
> # Node ID 14c07f0460918fe57b1c2709fe3ea3f071a95659
> # Parent  7f5f97697162331b5acf78aef091ae3fd341e308
> run-tests: also color the summary messages (skipped, failed...)

Queued, thanks.

> @@ -1587,7 +1621,14 @@
>                      self.stream.write('t')
>                  else:
>                      if not self._options.nodiff:
> -                        self.stream.write('\nERROR: %s output changed\n' % test)
> +                        formatted = '\nERROR: %s output changed\n' % test
> +                        if with_color and pygmentspresent:

Perhaps "pygmentspresent" wouldn't be necessary because you made it tested
beforehand.
Yuya Nishihara - July 18, 2017, 3:36 p.m.
On Tue, 18 Jul 2017 07:33:50 +0900, mlaneuville@gmail.com wrote:
> # HG changeset patch
> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
> # Date 1500330427 -32400
> #      Tue Jul 18 07:27:07 2017 +0900
> # Node ID 14c07f0460918fe57b1c2709fe3ea3f071a95659
> # Parent  7f5f97697162331b5acf78aef091ae3fd341e308
> run-tests: also color the summary messages (skipped, failed...)
> 
> diff -r 7f5f97697162 -r 14c07f046091 tests/run-tests.py
> --- a/tests/run-tests.py	Tue Jul 18 07:19:26 2017 +0900
> +++ b/tests/run-tests.py	Tue Jul 18 07:27:07 2017 +0900
> @@ -95,12 +95,46 @@
>      try: # is pygments installed
>          import pygments
>          import pygments.lexers as lexers
> +        import pygments.lexer as lexer
>          import pygments.formatters as formatters
> +        import pygments.token as token
> +        import pygments.style as style
>          with_color = True
>          pygmentspresent = True
>      except ImportError:
>          pass
>  
> +if pygmentspresent:
> +    class TestRunnerStyle(style.Style):
> +        default_style = ""
> +        skipped = token.string_to_tokentype("Token.Generic.Skipped")
> +        failed = token.string_to_tokentype("Token.Generic.Failed")
> +        error = token.string_to_tokentype("Token.Generic.Error")
> +        skippedname = token.string_to_tokentype("Token.Generic.SName")
> +        failedname = token.string_to_tokentype("Token.Generic.FName")
> +        styles = {
> +            skipped:         '#ansilightgray',
> +            skippedname:     '#ansidarkgray',
> +            failed:          '#ansidarkred',
> +            failedname:      '#ansired',
> +        }

Ugh, the buildbot failing.

https://buildbot.mercurial-scm.org/builders/hg%20tests/builds/1100/steps/run-tests.py%20%28python%202.7.10%29/logs/stdio

Does this require newer Pygments?
via Mercurial-devel - July 18, 2017, 4:08 p.m.
On Tue, Jul 18, 2017 at 8:36 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Tue, 18 Jul 2017 07:33:50 +0900, mlaneuville@gmail.com wrote:
>> # HG changeset patch
>> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
>> # Date 1500330427 -32400
>> #      Tue Jul 18 07:27:07 2017 +0900
>> # Node ID 14c07f0460918fe57b1c2709fe3ea3f071a95659
>> # Parent  7f5f97697162331b5acf78aef091ae3fd341e308
>> run-tests: also color the summary messages (skipped, failed...)
>>
>> diff -r 7f5f97697162 -r 14c07f046091 tests/run-tests.py
>> --- a/tests/run-tests.py      Tue Jul 18 07:19:26 2017 +0900
>> +++ b/tests/run-tests.py      Tue Jul 18 07:27:07 2017 +0900
>> @@ -95,12 +95,46 @@
>>      try: # is pygments installed
>>          import pygments
>>          import pygments.lexers as lexers
>> +        import pygments.lexer as lexer
>>          import pygments.formatters as formatters
>> +        import pygments.token as token
>> +        import pygments.style as style
>>          with_color = True
>>          pygmentspresent = True
>>      except ImportError:
>>          pass
>>
>> +if pygmentspresent:
>> +    class TestRunnerStyle(style.Style):
>> +        default_style = ""
>> +        skipped = token.string_to_tokentype("Token.Generic.Skipped")
>> +        failed = token.string_to_tokentype("Token.Generic.Failed")
>> +        error = token.string_to_tokentype("Token.Generic.Error")
>> +        skippedname = token.string_to_tokentype("Token.Generic.SName")
>> +        failedname = token.string_to_tokentype("Token.Generic.FName")
>> +        styles = {
>> +            skipped:         '#ansilightgray',
>> +            skippedname:     '#ansidarkgray',
>> +            failed:          '#ansidarkred',
>> +            failedname:      '#ansired',
>> +        }
>
> Ugh, the buildbot failing.
>
> https://buildbot.mercurial-scm.org/builders/hg%20tests/builds/1100/steps/run-tests.py%20%28python%202.7.10%29/logs/stdio
>
> Does this require newer Pygments?

It's failing the same way for me. I'll drop the patch.

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Matthieu Laneuville - July 19, 2017, 5:01 a.m.
That was indeed a Pygments-2.2.0 addition, I'm sending an updated patch
with color defined.

Le mer. 19 juil. 2017 à 01:08, Martin von Zweigbergk <martinvonz@google.com>
a écrit :

> On Tue, Jul 18, 2017 at 8:36 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> > On Tue, 18 Jul 2017 07:33:50 +0900, mlaneuville@gmail.com wrote:
> >> # HG changeset patch
> >> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
> >> # Date 1500330427 -32400
> >> #      Tue Jul 18 07:27:07 2017 +0900
> >> # Node ID 14c07f0460918fe57b1c2709fe3ea3f071a95659
> >> # Parent  7f5f97697162331b5acf78aef091ae3fd341e308
> >> run-tests: also color the summary messages (skipped, failed...)
> >>
> >> diff -r 7f5f97697162 -r 14c07f046091 tests/run-tests.py
> >> --- a/tests/run-tests.py      Tue Jul 18 07:19:26 2017 +0900
> >> +++ b/tests/run-tests.py      Tue Jul 18 07:27:07 2017 +0900
> >> @@ -95,12 +95,46 @@
> >>      try: # is pygments installed
> >>          import pygments
> >>          import pygments.lexers as lexers
> >> +        import pygments.lexer as lexer
> >>          import pygments.formatters as formatters
> >> +        import pygments.token as token
> >> +        import pygments.style as style
> >>          with_color = True
> >>          pygmentspresent = True
> >>      except ImportError:
> >>          pass
> >>
> >> +if pygmentspresent:
> >> +    class TestRunnerStyle(style.Style):
> >> +        default_style = ""
> >> +        skipped = token.string_to_tokentype("Token.Generic.Skipped")
> >> +        failed = token.string_to_tokentype("Token.Generic.Failed")
> >> +        error = token.string_to_tokentype("Token.Generic.Error")
> >> +        skippedname = token.string_to_tokentype("Token.Generic.SName")
> >> +        failedname = token.string_to_tokentype("Token.Generic.FName")
> >> +        styles = {
> >> +            skipped:         '#ansilightgray',
> >> +            skippedname:     '#ansidarkgray',
> >> +            failed:          '#ansidarkred',
> >> +            failedname:      '#ansired',
> >> +        }
> >
> > Ugh, the buildbot failing.
> >
> >
> https://buildbot.mercurial-scm.org/builders/hg%20tests/builds/1100/steps/run-tests.py%20%28python%202.7.10%29/logs/stdio
> >
> > Does this require newer Pygments?
>
> It's failing the same way for me. I'll drop the patch.
>
> > _______________________________________________
> > Mercurial-devel mailing list
> > Mercurial-devel@mercurial-scm.org
> > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Yuya Nishihara - July 19, 2017, 12:54 p.m.
On Wed, 19 Jul 2017 05:01:34 +0000, Matthieu Laneuville wrote:
> That was indeed a Pygments-2.2.0 addition, I'm sending an updated patch
> with color defined.
> 
> Le mer. 19 juil. 2017 à 01:08, Martin von Zweigbergk <martinvonz@google.com>
> a écrit :
> 
> > On Tue, Jul 18, 2017 at 8:36 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> > > On Tue, 18 Jul 2017 07:33:50 +0900, mlaneuville@gmail.com wrote:
> > >> # HG changeset patch
> > >> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
> > >> # Date 1500330427 -32400
> > >> #      Tue Jul 18 07:27:07 2017 +0900
> > >> # Node ID 14c07f0460918fe57b1c2709fe3ea3f071a95659
> > >> # Parent  7f5f97697162331b5acf78aef091ae3fd341e308
> > >> run-tests: also color the summary messages (skipped, failed...)

[...]

> > > Ugh, the buildbot failing.
> > >
> > >
> > https://buildbot.mercurial-scm.org/builders/hg%20tests/builds/1100/steps/run-tests.py%20%28python%202.7.10%29/logs/stdio
> > >
> > > Does this require newer Pygments?
> >
> > It's failing the same way for me. I'll drop the patch.

Thanks. I'm getting a feeling that using Pygments makes things rather
complicated.

Patch

diff -r 7f5f97697162 -r 14c07f046091 tests/run-tests.py
--- a/tests/run-tests.py	Tue Jul 18 07:19:26 2017 +0900
+++ b/tests/run-tests.py	Tue Jul 18 07:27:07 2017 +0900
@@ -95,12 +95,46 @@ 
     try: # is pygments installed
         import pygments
         import pygments.lexers as lexers
+        import pygments.lexer as lexer
         import pygments.formatters as formatters
+        import pygments.token as token
+        import pygments.style as style
         with_color = True
         pygmentspresent = True
     except ImportError:
         pass
 
+if pygmentspresent:
+    class TestRunnerStyle(style.Style):
+        default_style = ""
+        skipped = token.string_to_tokentype("Token.Generic.Skipped")
+        failed = token.string_to_tokentype("Token.Generic.Failed")
+        error = token.string_to_tokentype("Token.Generic.Error")
+        skippedname = token.string_to_tokentype("Token.Generic.SName")
+        failedname = token.string_to_tokentype("Token.Generic.FName")
+        styles = {
+            skipped:         '#ansilightgray',
+            skippedname:     '#ansidarkgray',
+            failed:          '#ansidarkred',
+            failedname:      '#ansired',
+        }
+
+    class TestRunnerLexer(lexer.RegexLexer):
+        tokens = {
+            'root': [
+                (r'^Skipped', token.Generic.Skipped, 'skipped'),
+                (r'^Failed ', token.Generic.Failed, 'failed'),
+                (r'^ERROR: ', token.Generic.Failed, 'failed'),
+            ],
+            'skipped': [
+                (r'[\w-]+\.t', token.Generic.SName),
+                (r':.*', token.Generic.Skipped),
+            ],
+            'failed': [
+                (r'[\w-]+\.t', token.Generic.FName),
+                (r'(:| ).*', token.Generic.Failed),
+            ]
+        }
 
 if sys.version_info > (3, 5, 0):
     PYTHON3 = True
@@ -1587,7 +1621,14 @@ 
                     self.stream.write('t')
                 else:
                     if not self._options.nodiff:
-                        self.stream.write('\nERROR: %s output changed\n' % test)
+                        formatted = '\nERROR: %s output changed\n' % test
+                        if with_color and pygmentspresent:
+                            formatted = pygments.highlight(
+                                formatted,
+                                TestRunnerLexer(),
+                                formatters.Terminal256Formatter(
+                                            style=TestRunnerStyle)).strip("\n")
+                        self.stream.write(formatted)
                     self.stream.write('!')
 
                 self.stream.flush()
@@ -1990,9 +2031,23 @@ 
 
             if not self._runner.options.noskips:
                 for test, msg in result.skipped:
-                    self.stream.writeln('Skipped %s: %s' % (test.name, msg))
+                    formatted = 'Skipped %s: %s' % (test.name, msg)
+                    if with_color and pygmentspresent:
+                        formatted = pygments.highlight(
+                            formatted,
+                            TestRunnerLexer(),
+                            formatters.Terminal256Formatter(
+                                            style=TestRunnerStyle)).strip("\n")
+                    self.stream.writeln(formatted)
             for test, msg in result.failures:
-                self.stream.writeln('Failed %s: %s' % (test.name, msg))
+                formatted = 'Failed %s: %s' % (test.name, msg)
+                if with_color and pygmentspresent:
+                    formatted = pygments.highlight(
+                        formatted,
+                        TestRunnerLexer(),
+                        formatters.Terminal256Formatter(
+                                        style=TestRunnerStyle)).strip("\n")
+                self.stream.writeln(formatted)
             for test, msg in result.errors:
                 self.stream.writeln('Errored %s: %s' % (test.name, msg))
 
diff -r 7f5f97697162 -r 14c07f046091 tests/test-run-tests.t
--- a/tests/test-run-tests.t	Tue Jul 18 07:19:26 2017 +0900
+++ b/tests/test-run-tests.t	Tue Jul 18 07:27:07 2017 +0900
@@ -131,10 +131,8 @@ 
   \x1b[38;5;34m+  bar*baz (glob)\x1b[39m (esc)
      bar*bad (glob)
   \x1b[38;5;124m-  bar*baz (glob)\x1b[39m (esc)
-  
-  ERROR: test-failure.t output changed
-  !
-  Failed test-failure.t: output changed
+  \x1b[31mERROR: \x1b[39m\x1b[31;01mtest-failure.t\x1b[39;00m\x1b[31m output changed\x1b[39m! (esc)
+  \x1b[31mFailed \x1b[39m\x1b[31;01mtest-failure.t\x1b[39;00m\x1b[31m: output changed\x1b[39m (esc)
   # Ran 1 tests, 0 skipped, 1 failed.
   python hash seed: * (glob)
   [1]