-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: fix check-imports.py to match on word boundaries
`check-imports.py` was missing some unused `using` statements as it was not matching on word boundaries (e.g. `MaybeLocal` was considered a use of `Local`). Fix that and add some unit tests (which required the script to be renamed to drop the `-` so it could be imported into the test script). PR-URL: #33268 Refs: #29226 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
- Loading branch information
1 parent
4a20cc9
commit 05db682
Showing
8 changed files
with
114 additions
and
4 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
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,7 @@ | ||
using v8::MaybeLocal; | ||
using v8::Array; | ||
using v8::Local; | ||
|
||
MaybeLocal<Array> CreateObject() const { | ||
return MaybeLocal<Array>(); | ||
} |
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,7 @@ | ||
using v8::Array; | ||
using v8::Local; | ||
using v8::MaybeLocal; | ||
|
||
MaybeLocal<Array> CreateObject() const { | ||
return MaybeLocal<Array>(); | ||
} |
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,6 @@ | ||
using v8::MaybeLocal; | ||
using v8::Array; | ||
|
||
MaybeLocal<Array> CreateObject() const { | ||
return MaybeLocal<Array>(); | ||
} |
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,5 @@ | ||
using v8::Context; | ||
|
||
static void MyMethod(void) { | ||
return; | ||
} |
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,6 @@ | ||
using v8::Array; | ||
using v8::MaybeLocal; | ||
|
||
MaybeLocal<Array> CreateObject() const { | ||
return MaybeLocal<Array>(); | ||
} |
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,77 @@ | ||
import unittest | ||
import sys | ||
from contextlib import contextmanager | ||
from os import path | ||
sys.path.append(path.abspath(path.join(path.dirname(__file__), | ||
'..', '..', 'tools'))) | ||
try: | ||
from StringIO import StringIO | ||
except ImportError: | ||
from io import StringIO | ||
|
||
from checkimports import is_valid | ||
|
||
@contextmanager | ||
def captured_output(): | ||
tmp_out, tmp_err = StringIO(), StringIO() | ||
old_out, old_err = sys.stdout, sys.stderr | ||
try: | ||
sys.stdout, sys.stderr = tmp_out, tmp_err | ||
yield sys.stdout, sys.stderr | ||
finally: | ||
sys.stdout, sys.stderr = old_out, old_err | ||
tmp_out.close() | ||
tmp_err.close() | ||
|
||
class CheckImportsTest(unittest.TestCase): | ||
fixturesDir = path.join(path.dirname(__file__), '..', '..', | ||
'test', 'fixtures', 'tools', 'checkimports') | ||
|
||
def test_unused_and_unsorted(self): | ||
with captured_output() as (out, err): | ||
self.assertEqual(is_valid(path.join(self.fixturesDir, 'invalid.cc')), | ||
False) | ||
output = out.getvalue() | ||
self.assertIn('does not use "Local"', output); | ||
self.assertIn('using statements aren\'t sorted in', output); | ||
self.assertIn('Line 1: Actual: v8::MaybeLocal, Expected: v8::Array', | ||
output); | ||
self.assertIn('Line 2: Actual: v8::Array, Expected: v8::Local', | ||
output); | ||
self.assertIn('Line 3: Actual: v8::Local, Expected: v8::MaybeLocal', | ||
output); | ||
|
||
def test_unused_complex(self): | ||
with captured_output() as (out, err): | ||
self.assertEqual(is_valid(path.join(self.fixturesDir, 'maybe.cc')), | ||
False) | ||
output = out.getvalue() | ||
self.assertIn('does not use "Local"', output); | ||
|
||
def test_unused_simple(self): | ||
with captured_output() as (out, err): | ||
self.assertEqual(is_valid(path.join(self.fixturesDir, 'unused.cc')), | ||
False) | ||
output = out.getvalue() | ||
self.assertIn('does not use "Context"', output); | ||
|
||
def test_unsorted(self): | ||
with captured_output() as (out, err): | ||
self.assertEqual(is_valid(path.join(self.fixturesDir, 'unsorted.cc')), | ||
False) | ||
output = out.getvalue() | ||
self.assertIn('using statements aren\'t sorted in', output); | ||
self.assertIn('Line 1: Actual: v8::MaybeLocal, Expected: v8::Array', | ||
output); | ||
self.assertIn('Line 2: Actual: v8::Array, Expected: v8::MaybeLocal', | ||
output); | ||
|
||
def test_valid(self): | ||
with captured_output() as (out, err): | ||
self.assertEqual(is_valid(path.join(self.fixturesDir, 'valid.cc')), | ||
True) | ||
output = out.getvalue() | ||
self.assertEqual(output, ''); | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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