Skip to content

Commit

Permalink
Fix support for new color scheme format and other improvements
Browse files Browse the repository at this point in the history
* If new color scheme format is found the colors default to use the new
`region.colorish` scopes, otherwise the default colors are Monokai.
* If custom overrides are found in the user color scheme then the
default colors are not used.
* Add support for Warnings color output.
* Other syntax and color fixes.
  • Loading branch information
gerardroche committed Nov 17, 2017
1 parent 8809a33 commit a3ed9b1
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 127 deletions.
63 changes: 40 additions & 23 deletions plugin.py
Expand Up @@ -538,32 +538,49 @@ def get_phpunit_executable(self, working_dir):

def get_auto_generated_color_scheme(self):
color_scheme = self.view.settings().get('color_scheme')
debug_message('color scheme \'{}\''.format(color_scheme))

cs_head, cs_tail = os.path.split(color_scheme)
cs_package = os.path.split(cs_head)[1]
cs_name = os.path.splitext(cs_tail)[0]
if color_scheme.endswith('.sublime-color-scheme'):
return color_scheme

file_name = cs_package + '__' + cs_name + '.hidden-tmTheme'
abs_file = os.path.join(cache_path(), 'phpunitkit', 'color-schemes', file_name)
rel_file = 'Cache/phpunitkit/color-schemes/' + file_name

debug_message('auto generated color scheme = %s', rel_file)

if not os.path.exists(os.path.dirname(abs_file)):
os.makedirs(os.path.dirname(abs_file))

with open(abs_file, 'w', encoding='utf8') as f:
f.write(re.sub(
'</array>\\s*'
'(<key>.*</key>\\s*<string>[^<]*</string>\\s*)*'
'</dict>\\s*</plist>\\s*'
'$',
load_resource(
'Packages/phpunitkit/res/text-ui-result-theme-partial.txt') + '\\n</array></dict></plist>',
load_resource(color_scheme)
))
try:
# Try to patch color scheme with default test result colors

color_scheme_resource = load_resource(color_scheme)
if 'phpunitkit' in color_scheme_resource or 'region.greenish' in color_scheme_resource:
debug_message('color looks like it has color support')
return color_scheme

cs_head, cs_tail = os.path.split(color_scheme)
cs_package = os.path.split(cs_head)[1]
cs_name = os.path.splitext(cs_tail)[0]

file_name = cs_package + '__' + cs_name + '.hidden-tmTheme'
abs_file = os.path.join(cache_path(), 'phpunitkit', 'color-schemes', file_name)
rel_file = 'Cache/phpunitkit/color-schemes/' + file_name

debug_message('auto generated color scheme = %s', rel_file)

if not os.path.exists(os.path.dirname(abs_file)):
os.makedirs(os.path.dirname(abs_file))

with open(abs_file, 'w', encoding='utf8') as f:
f.write(re.sub(
'</array>\\s*'
'(<key>.*</key>\\s*<string>[^<]*</string>\\s*)*'
'</dict>\\s*</plist>\\s*'
'$',
load_resource(
'Packages/phpunitkit/res/text-ui-result-theme-partial.txt') + '\\n</array></dict></plist>',
color_scheme_resource
))

return rel_file
except Exception as e:
print('PHPUnit: an error occurred trying to patch color'
' scheme with PHPUnit test results colors: {}'.format(str(e)))

return rel_file
return color_scheme


class PhpunitTestSuiteCommand(WindowCommand):
Expand Down
102 changes: 16 additions & 86 deletions res/text-ui-result-theme-partial.txt
Expand Up @@ -3,131 +3,61 @@

<dict>
<key>scope</key>
<string>test.footer.none-executed, test.footer.ok-but-incomplete-skipped-or-risky</string>
<string>test.footer.ok</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#FFFF00</string>
<string>#a6e22e</string>
<key>foreground</key>
<string>#000000</string>
<string>#272822</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>test.footer.ok</string>
<string>test.footer.warn, test.footer.none-executed, test.footer.ok-but-incomplete-skipped-or-risky</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#00FF00</string>
<string>#fd971f</string>
<key>foreground</key>
<string>#1C1F26</string>
<string>#272822</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>test.footer.fail</string>
<string>test.footer.error, test.footer.fail</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#FF0000</string>
<string>#f92672</string>
<key>foreground</key>
<string>#FFFFFF</string>
<string>#f8f8f2</string>
</dict>
</dict>

<!-- progress -->

<dict>
<key>scope</key>
<string>test.progress.failure</string>
<string>test.progress.error, test.progress.failure</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#FF0000</string>
<key>foreground</key>
<string>#FFFFFF</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>test.progress.error</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF0000</string>
<key>fontStyle</key>
<string>bold</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>test.progress.incomplete, test.progress.risky</string>
<key>settings</key>
<dict>
<string>#f92672</string>
<key>foreground</key>
<string>#FFFF00</string>
<key>fontStyle</key>
<string>bold</string>
<string>#f8f8f2</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>test.progress.skipped</string>
<string>test.progress.warning, test.progress.skipped, test.progress.incomplete, test.progress.risky</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#fd971f</string>
<key>foreground</key>
<string>#00FFFF</string>
<string>#272822</string>
<key>fontStyle</key>
<string>bold</string>
</dict>
</dict>

<!-- source.diff -->

<dict>
<key>scope</key>
<string>meta.diff, meta.diff.header</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#75715e</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>markup.deleted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF0000</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>markup.inserted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00FF00</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>markup.changed</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#e6db74</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>meta.diff, meta.diff.range</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00FFFF</string>
</dict>
</dict>

<!-- /PHPUnitKit -->
49 changes: 36 additions & 13 deletions res/text-ui-result.sublime-syntax
Expand Up @@ -8,31 +8,54 @@ hidden: true
contexts:
main:
- include: scope:source.diff
- match: ^(?=(\.|E|F|I|R|S)+\s+)
- match: ^(?=(\.|E|F|I|R|S|W)+\s+)
push:
- match: \s+(\d+\s+\/\s+\d+\s+\(\s*\d+\%\))?$
pop: true
- match: \.
scope: test.progress.success.phpunit-result
- match: E
scope: test.progress.error.phpunit-result
scope: region.redish phpunitkit test.progress.error.phpunit-result
- match: F
scope: test.progress.failure.phpunit-result
scope: region.redish phpunitkit test.progress.failure.phpunit-result
- match: I
scope: test.progress.incomplete.phpunit-result
scope: region.orangish phpunitkit test.progress.incomplete.phpunit-result
- match: R
scope: test.progress.risky.phpunit-result
scope: region.orangish phpunitkit test.progress.risky.phpunit-result
- match: S
scope: test.progress.skipped.phpunit-result
scope: region.orangish phpunitkit test.progress.skipped.phpunit-result
- match: W
scope: region.orangish phpunitkit test.progress.warning.phpunit-result

- match: '^(?:\e\[[0-9;]+m)?No tests executed\!(?:\e\[[0-9;]+m)?$'
scope: test.footer.none-executed.phpunit-result
scope: region.orangish test.footer.none-executed.phpunit-result

- match: '^(?:\e\[[0-9;]+m)?OK \(\d+ test(?:s)?, \d+ assertion(?:s)?\)(?:\e\[[0-9;]+m)?$'
scope: test.footer.ok.phpunit-result
scope: region.greenish phpunitkit test.footer.ok.phpunit-result

- match: '^(?:\e\[[0-9;]+m)?OK, but incomplete, skipped, or risky tests\!(?:\e\[[0-9;]+m)?$'
scope: test.footer.ok-but-incomplete-skipped-or-risky.phpunit-result
scope: region.orangish phpunitkit test.footer.ok-but-incomplete-skipped-or-risky.phpunit-result

- match: '^(?:\e\[[0-9;]+m)?Tests\: \d+, Assertions\: \d+(?:, (?:Incomplete|Skipped|Risky)\: \d+)+\.(?:\e\[[0-9;]+m)?$'
scope: test.footer.ok-but-incomplete-skipped-or-risky.phpunit-result
scope: region.orangish phpunitkit test.footer.ok-but-incomplete-skipped-or-risky.phpunit-result

- match: '^(?:\e\[[0-9;]+m)?WARNINGS\!(?:\e\[[0-9;]+m\s*)?$'
scope: region.orangish phpunitkit test.footer.warn.phpunit-result
push:
- match: '^(?:\e\[[0-9;]+m)?Tests\: \d+, Assertions\: \d+(?:, (?:Errors|Failures|Warnings|Skipped|Incomplete|Risky)\: \d+)+\.(?:\e\[[0-9;]+m)?$'
scope: region.orangish phpunitkit test.footer.warn.phpunit-result
pop: true

- match: '^(?:\e\[[0-9;]+m)?FAILURES\!(?:\e\[[0-9;]+m\s*)?$'
scope: test.footer.fail.phpunit-result
- match: '^(?:\e\[[0-9;]+m)?Tests\: \d+, Assertions\: \d+(?:, (?:Errors|Failures|Skipped|Incomplete|Risky)\: \d+)+\.(?:\e\[[0-9;]+m)?$'
scope: test.footer.fail.phpunit-result
scope: region.redish phpunitkit test.footer.fail.phpunit-result
push:
- match: '^(?:\e\[[0-9;]+m)?Tests\: \d+, Assertions\: \d+(?:, (?:Errors|Failures|Warnings|Skipped|Incomplete|Risky)\: \d+)+\.(?:\e\[[0-9;]+m)?$'
scope: region.redish phpunitkit test.footer.fail.phpunit-result
pop: true

- match: '^(?:\e\[[0-9;]+m)?ERRORS\!(?:\e\[[0-9;]+m\s*)?$'
scope: region.redish phpunitkit test.footer.error.phpunit-result
push:
- match: '^(?:\e\[[0-9;]+m)?Tests\: \d+, Assertions\: \d+(?:, (?:Errors|Failures|Warnings|Skipped|Incomplete|Risky)\: \d+)+\.(?:\e\[[0-9;]+m)?$'
scope: region.orangish phpunitkit test.footer.error.phpunit-result
pop: true
40 changes: 35 additions & 5 deletions tests/syntax_test-text-ui-result
Expand Up @@ -20,25 +20,33 @@ I
R
#<- test.progress.risky.phpunit-result

I
#<- test.progress.incomplete.phpunit-result
S
#<- test.progress.skipped.phpunit-result

W
#<- test.progress.warning.phpunit-result

.EFIRS
.EFIRSW
#<- test.progress.success.phpunit-result
#^ test.progress.error.phpunit-result
# ^ test.progress.failure.phpunit-result
# ^ test.progress.incomplete.phpunit-result
# ^ test.progress.risky.phpunit-result
# ^ test.progress.skipped.phpunit-result
# ^ test.progress.warning.phpunit-result
...
#<- test.progress.success.phpunit-result
#^^ test.progress.success.phpunit-result

F..S...
F..S...W..E.
#<- test.progress.failure.phpunit-result
#^^ test.progress.success.phpunit-result
# ^ test.progress.skipped.phpunit-result
# ^^^ test.progress.success.phpunit-result
# ^ test.progress.warning.phpunit-result
# ^^ test.progress.success.phpunit-result
# ^ test.progress.error.phpunit-result
# ^ test.progress.success.phpunit-result

Time: 385 ms, Memory: 5.50MB

Expand All @@ -53,12 +61,34 @@ OK (45 tests, 81 assertions)
OK, but incomplete, skipped, or risky tests!
#<- test.footer.ok-but-incomplete-skipped-or-risky.phpunit-result
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ test.footer.ok-but-incomplete-skipped-or-risky.phpunit-result
Tests: 1, Assertions: 0, Skipped: 1.
#<- test.footer.ok-but-incomplete-skipped-or-risky.phpunit-result
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ test.footer.ok-but-incomplete-skipped-or-risky.phpunit-result

FAILURES!
#<- test.footer.fail.phpunit-result
#^^^^^^^^ test.footer.fail.phpunit-result

Tests: 46, Assertions: 82, Failures: 2.
#<- test.footer.fail.phpunit-result
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ test.footer.fail.phpunit-result

ERRORS!
#<- test.footer.error.phpunit-result
#^^^^^^ test.footer.error.phpunit-result
Tests: 6, Assertions: 5, Errors: 1.
#<- test.footer.error.phpunit-result
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ test.footer.error.phpunit-result

ERRORS!
#<- test.footer.error.phpunit-result
#^^^^^^ test.footer.error.phpunit-result
Tests: 18, Assertions: 16, Errors: 1, Skipped: 1, Risky: 1.
#<- test.footer.error.phpunit-result
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ test.footer.error.phpunit-result

WARNINGS!
#<- test.footer.warn.phpunit-result
#^^^^^^ test.footer.warn.phpunit-result
Tests: 1, Assertions: 0, Warnings: 1.
#<- test.footer.warn.phpunit-result
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ test.footer.warn.phpunit-result

0 comments on commit a3ed9b1

Please sign in to comment.