Skip to content

Support for syntax test output highlighting #3022

@deathaxe

Description

@deathaxe

Problem description

Reading the syntax test output can sometimes be a bit tedious. A syntax highlighting of the output could propaply help improving the readability of the test output.

Preferred solution

To do so, the run_syntax_tests.py needs to be patched to add support for the syntax key in sublime-build files.

The proposal also contains a syntax definition. But I don't have a final idea about how to scope the different parts of the build output in detail. Maybe the scope names need to be tweaked a little bit.

1. Add support for the `syntax` parameter of `sublime-build` files to the `run_syntax_tests` command.

--- C:\Apps\Sublime Text 3\Data\Packages\Default\run_syntax_tests.py    Thu Oct 17 18:22:14 2019
+++ C:\Apps\Sublime Text 3\Data\Packages\Default\run_syntax_tests.py    Thu Oct 17 18:22:34 2019
@@ -10,7 +10,11 @@
 
 
 class RunSyntaxTestsCommand(sublime_plugin.WindowCommand):
-    def run(self, find_all=False, **kwargs):
+
+    def run(self,
+            find_all=False,
+            syntax="Syntax Test.sublime-syntax",
+            **kwargs):
 
         if not hasattr(self, 'output_view'):
             # Try not to call get_output_panel until the regexes are assigned
@@ -23,6 +27,7 @@
         settings.set('line_numbers', False)
         settings.set('gutter', False)
         settings.set('scroll_past_end', False)
+        settings.set('syntax', syntax)
 
         # Call create_output_panel a second time after assigning the above
         # settings, so that it'll be picked up as a result buffer

2. Add a Syntax Test.sublime-syntax file

%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Sublime Syntax Tests
hidden: true
scope: text.syntax-tests
variables:
  scope_segment: '\w+(?:[\w-]*\+*)' # \+* is for the non standard scope.c++ scopes

contexts:
  main:
    - match: ^(\[)Finished(\])
      scope: markup.info.syntax-tests
      captures:
        1: punctuation.definition.markup.begin.syntax-tests
        2: punctuation.definition.markup.end.syntax-tests
    - match: ^(FAILED)(:) (\d+) of (\d+) assertions in (\d+) files failed
      captures:
        1: markup.error.failed.syntax-tests
        2: punctuation.separator.syntax-tests
        3: markup.error.num-failed.syntax-tests
        4: markup.info.num-asserts.syntax-tests
        5: markup.info.num-files.syntax-tests
    - match: ^
      push:
        - match: '[/.]'
          scope: punctuation.separator.path.syntax-tests
        - match: (:)(\d+)(:)(\d+)(:)
          captures:
            1: punctuation.separator.sequence.syntax-tests
            2: constant.numeric.integer.decimal.syntax-tests
            3: punctuation.separator.sequence.syntax-tests
            4: constant.numeric.integer.decimal.syntax-tests
            5: punctuation.separator.sequence.syntax-tests
          set:
            - match: \n
              pop: true
            - match: \[
              scope: punctuation.definition.selector.begin.syntax-tests
              push:
                - match: \]
                  scope: punctuation.definition.selector.end.syntax-tests
                  pop: true
                - match: '\)'
                  scope: invalid.illegal.stray-bracket.scope-selector
                - include: scope-selector

###[ PackageDev's Scope Selector ]#############################################

  scope-selector:
    - match: (?:^\s*)?({{scope_segment}})
      captures:
        1: string.unquoted.scope-segment.scope-selector
      push:
        - match: (\.)(\.+)?
          captures:
            1: punctuation.separator.scope-segments.scope-selector
            2: invalid.illegal.empty-scope-segment.scope-selector
          pop: true
        - match: \s+\(
          scope: invalid.illegal.operator-required-between-scope-and-group.scope-selector
        - match: \s+(?=\w)
          scope: keyword.operator.right.scope-selector
          pop: true
        - match: ''
          pop: true
    - match: '-'
      scope: keyword.operator.without.scope-selector
    - match: '&'
      scope: keyword.operator.with.scope-selector
    - match: '[,|]'
      scope: keyword.operator.or.scope-selector
    - match: \(
      scope: punctuation.section.group.begin.scope-selector
      push:
        - match: \)
          scope: punctuation.section.group.end.scope-selector
          set:
            - match: (\s*{{scope_segment}}|\.)+
              scope: invalid.illegal.operator-required-after-group.scope-selector
            - match: \s*
              pop: true
        - include: scope-selector

Alternatives

If the syntax definition seems too much, please, at least implement step 1 with Plain Text.tmLanguage as default syntax to enable custom sublime-build files with a custom syntax definition.

Maybe a 3rd party package like PackageDev could implement the highlighting then, without the need of patching the run_syntax_tests.py implementation or hack around to make it work.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions