-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Includes some regex fixes for latest PHP versions and some improved error message filtering.
- Loading branch information
1 parent
804a20f
commit b1b02d1
Showing
4 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# flake8: noqa | ||
import unittest | ||
import re | ||
import importlib | ||
|
||
# Damn you dash separated module names!!! | ||
LinterModule = importlib.import_module('SublimeLinter-php.linter') | ||
Linter = LinterModule.PHP | ||
_filter_message = LinterModule._filter_message | ||
regex = Linter.regex | ||
|
||
|
||
class TestRegex(unittest.TestCase): | ||
|
||
def assertMatch(self, string, expected): | ||
match = re.match(regex, string) | ||
self.assertIsNotNone(match) | ||
|
||
# Hack to test message filtering. | ||
actual = match.groupdict() | ||
if 'message' in actual: | ||
actual['message'] = _filter_message(actual['message']) | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
def assertNoMatch(self, string): | ||
self.assertIsNone(re.match(regex, string)) | ||
|
||
def test_no_errors(self): | ||
self.assertNoMatch('No syntax errors detected in - ') | ||
self.assertNoMatch('No syntax errors detected in - file.php') | ||
self.assertNoMatch('No syntax errors detected in - /path/to/file.php') | ||
self.assertNoMatch('No syntax errors detected in Standard input code') | ||
|
||
def test_errors(self): | ||
self.assertMatch( | ||
'Parse error: syntax error, unexpected \'$this\' (T_VARIABLE) in - on line 14', { | ||
'error': 'Parse', | ||
'line': '14', | ||
'message': 'syntax error, unexpected \'$this\' (T_VARIABLE)', | ||
'near': '$this' | ||
}) | ||
|
||
self.assertMatch( | ||
'Parse error: syntax error, unexpected end of file in - on line 23', { | ||
'error': 'Parse', | ||
'line': '23', | ||
'message': 'syntax error, unexpected end of file', | ||
'near': None | ||
}) | ||
|
||
def test_issue_29(self): | ||
self.assertMatch( | ||
'Parse error: syntax error, unexpected \'endwhile\' (T_ENDWHILE), expecting end of file in Standard input code on line 16', { | ||
'error': 'Parse', | ||
'line': '16', | ||
'message': 'syntax error, unexpected \'endwhile\' (T_ENDWHILE), expecting end of file', | ||
'near': 'endwhile' | ||
}) | ||
|
||
self.assertMatch( | ||
'Parse error: parse error in - on line 16', { | ||
'error': 'Parse', | ||
'line': '16', | ||
'message': 'parse error', | ||
'near': None | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"tests_dir" : "tests", | ||
"pattern" : "test*.py", | ||
"async": false, | ||
"deferred": true, | ||
"verbosity": 2, | ||
"capture_console": true, | ||
"output": null | ||
} |